mirror of
https://code.forgejo.org/actions/setup-forgejo.git
synced 2024-11-24 00:40:58 -05:00
add example of cron task
This commit is contained in:
parent
b081450249
commit
7e8c8064af
12 changed files with 102 additions and 41 deletions
|
@ -1,31 +1,24 @@
|
||||||
on: [ push, pull_request ]
|
on: [ push, pull_request ]
|
||||||
|
|
||||||
env:
|
|
||||||
#
|
|
||||||
# List of tests to run as found in testdata/example-$test. The
|
|
||||||
# directory will be used to create a git repository uploaded to a
|
|
||||||
# Forgejo instance.
|
|
||||||
#
|
|
||||||
# The test will be a success once the status of
|
|
||||||
# the commit is success, as set by the Forgejo Action run.
|
|
||||||
#
|
|
||||||
TESTS: 'echo service container expression local-action docker-action if'
|
|
||||||
#
|
|
||||||
# The test is expected to fail the workflow and verify the expected
|
|
||||||
# side effect of the failure with testdata/example-$test/expected-to-fail.sh
|
|
||||||
#
|
|
||||||
TESTS_FAILING: 'if-fail'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
integration:
|
integration:
|
||||||
runs-on: self-hosted
|
runs-on: self-hosted
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
info:
|
||||||
|
- version: "1.21.0-0-rc0"
|
||||||
|
image: codeberg.org/forgejo-experimental/forgejo
|
||||||
|
tests: "echo cron service container expression local-action docker-action if if-fail"
|
||||||
|
- version: "1.20"
|
||||||
|
image: codeberg.org/forgejo/forgejo
|
||||||
|
tests: "echo service container expression local-action docker-action if if-fail"
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- run: |
|
- run: |
|
||||||
set -x
|
set -x
|
||||||
LXC_IP_PREFIX=10.0.10 ./forgejo-dependencies.sh
|
LXC_IP_PREFIX=10.0.10 ./forgejo-dependencies.sh
|
||||||
export PATH=$(pwd):$PATH
|
export PATH=$(pwd):$PATH
|
||||||
forgejo.sh setup root admin1234 codeberg.org/forgejo/forgejo 1.20
|
forgejo.sh setup root admin1234 ${{ matrix.info.image }} ${{ matrix.info.version }}
|
||||||
#
|
#
|
||||||
# Uncomment the following for a shortcut to debugging the Forgejo runner.
|
# Uncomment the following for a shortcut to debugging the Forgejo runner.
|
||||||
# It will build the runner from a designated repository and branch instead of
|
# It will build the runner from a designated repository and branch instead of
|
||||||
|
@ -34,33 +27,29 @@ jobs:
|
||||||
#./forgejo-test-helper.sh build_runner http://code.forgejo.org/earl-warren/runner wip-sync
|
#./forgejo-test-helper.sh build_runner http://code.forgejo.org/earl-warren/runner wip-sync
|
||||||
#export PATH=$(pwd)/forgejo-runner:$PATH
|
#export PATH=$(pwd)/forgejo-runner:$PATH
|
||||||
#
|
#
|
||||||
./forgejo-runner.sh setup
|
forgejo-runner.sh setup
|
||||||
export FORGEJO_RUNNER_LOGS=forgejo-runner.log
|
export FORGEJO_RUNNER_LOGS=forgejo-runner.log
|
||||||
|
|
||||||
for example in $TESTS $TESTS_FAILING ; do
|
for example in ${{ matrix.info.tests }} ; do
|
||||||
|
export EXAMPLE_DIR=$(pwd)/testdata/example-$example
|
||||||
|
|
||||||
if test $example = service ; then
|
if test -f $EXAMPLE_DIR/setup.sh ; then
|
||||||
> /srv/example-service-volume-valid
|
source $EXAMPLE_DIR/setup.sh
|
||||||
> /srv/example-service-volume-invalid
|
|
||||||
fi
|
|
||||||
|
|
||||||
config=$(pwd)/testdata/example-$example/runner-config.yaml
|
|
||||||
if test -f $config ; then
|
|
||||||
FORGEJO_RUNNER_CONFIG=$config ./forgejo-runner.sh reload
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "============================ BEGIN example-$example ==================="
|
echo "============================ BEGIN example-$example ==================="
|
||||||
if ./forgejo-test-helper.sh run_workflow testdata/example-$example http://root:admin1234@$(cat forgejo-ip):3000 root example-$example setup-forgejo $(cat forgejo-token) >& /tmp/run.out ; then
|
if test -f $EXAMPLE_DIR/run.sh ; then
|
||||||
cat /tmp/run.out
|
source $EXAMPLE_DIR/run.sh
|
||||||
! test -f testdata/example-$example/expected-to-fail.sh
|
|
||||||
else
|
else
|
||||||
|
if ! forgejo-test-helper.sh run_workflow testdata/example-$example http://root:admin1234@$(cat forgejo-ip):3000 root example-$example setup-forgejo $(cat forgejo-token) >& /tmp/run.out ; then
|
||||||
cat /tmp/run.out
|
cat /tmp/run.out
|
||||||
test -f testdata/example-$example/expected-to-fail.sh
|
false
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
echo "============================ END example-$example ==================="
|
echo "============================ END example-$example ==================="
|
||||||
|
|
||||||
if test -f $config ; then
|
if test -f $EXAMPLE_DIR/teardown.sh ; then
|
||||||
./forgejo-runner.sh reload
|
source $EXAMPLE_DIR/teardown.sh
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
echo "============================ demo ==================="
|
echo "============================ demo ==================="
|
||||||
|
|
|
@ -105,7 +105,7 @@ function push() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function run_workflow() {
|
function push_workflow() {
|
||||||
local directory="$1"
|
local directory="$1"
|
||||||
local url="$2"
|
local url="$2"
|
||||||
local owner="$3"
|
local owner="$3"
|
||||||
|
@ -119,6 +119,17 @@ function run_workflow() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
push "$directory" "$url" "$owner" "$project" "$self_action" "$token"
|
push "$directory" "$url" "$owner" "$project" "$self_action" "$token"
|
||||||
|
}
|
||||||
|
|
||||||
|
function run_workflow() {
|
||||||
|
local directory="$1"
|
||||||
|
local url="$2"
|
||||||
|
local owner="$3"
|
||||||
|
local project="$4"
|
||||||
|
local self_action="$5"
|
||||||
|
local token="$6"
|
||||||
|
|
||||||
|
push_workflow "$directory" "$url" "$owner" "$project" "$self_action" "$token"
|
||||||
wait_success "$url" "$owner/$project" $(cat $DIR/$project/SHA)
|
wait_success "$url" "$owner/$project" $(cat $DIR/$project/SHA)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,12 @@ set -e
|
||||||
DIR=/tmp
|
DIR=/tmp
|
||||||
if ${VERBOSE:-false}; then set -x; fi
|
if ${VERBOSE:-false}; then set -x; fi
|
||||||
: ${CONTAINER:=forgejo}
|
: ${CONTAINER:=forgejo}
|
||||||
|
: ${RETRY_DELAYS:=1 1 5 5 15 30}
|
||||||
|
|
||||||
function retry() {
|
function retry() {
|
||||||
rm -f $DIR/retry.out
|
rm -f $DIR/retry.out
|
||||||
success=false
|
success=false
|
||||||
for delay in 1 1 5 5 15 30 ; do
|
for delay in $RETRY_DELAYS ; do
|
||||||
if "$@" >> $DIR/retry.out 2>&1 ; then
|
if "$@" >> $DIR/retry.out 2>&1 ; then
|
||||||
success=true
|
success=true
|
||||||
break
|
break
|
||||||
|
|
14
testdata/example-cron/.forgejo/workflows/test.yml
vendored
Normal file
14
testdata/example-cron/.forgejo/workflows/test.yml
vendored
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '* * * * *'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: debian:bookworm
|
||||||
|
options: "--volume /srv/example-cron-volume:/srv/example-cron-volume"
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- run: |
|
||||||
|
touch /srv/example-cron-volume/DONE
|
7
testdata/example-cron/run.sh
vendored
Executable file
7
testdata/example-cron/run.sh
vendored
Executable file
|
@ -0,0 +1,7 @@
|
||||||
|
forgejo-test-helper.sh push_workflow testdata/example-$example http://root:admin1234@$(cat forgejo-ip):3000 root example-$example setup-forgejo $(cat forgejo-token)
|
||||||
|
# cron runs once per minute, give it three minutes max before declaring failure
|
||||||
|
if ! RETRY_DELAYS="30 30 30 30 30 30" forgejo.sh retry test -f /srv/example-cron-volume/DONE ; then
|
||||||
|
cat $FORGEJO_RUNNER_LOGS
|
||||||
|
false
|
||||||
|
fi
|
||||||
|
|
30
testdata/example-cron/runner-config.yaml
vendored
Normal file
30
testdata/example-cron/runner-config.yaml
vendored
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
|
||||||
|
log:
|
||||||
|
level: info
|
||||||
|
|
||||||
|
runner:
|
||||||
|
file: .runner
|
||||||
|
capacity: 1
|
||||||
|
env_file: .env
|
||||||
|
timeout: 3h
|
||||||
|
insecure: false
|
||||||
|
fetch_timeout: 5s
|
||||||
|
fetch_interval: 2s
|
||||||
|
labels: []
|
||||||
|
|
||||||
|
cache:
|
||||||
|
enabled: false
|
||||||
|
dir: ""
|
||||||
|
host: ""
|
||||||
|
port: 0
|
||||||
|
|
||||||
|
container:
|
||||||
|
network: ""
|
||||||
|
privileged: false
|
||||||
|
options:
|
||||||
|
workdir_parent:
|
||||||
|
valid_volumes: ["/srv/example-cron-volume"]
|
||||||
|
docker_host: ""
|
||||||
|
|
||||||
|
host:
|
||||||
|
workdir_parent:
|
2
testdata/example-cron/setup.sh
vendored
Executable file
2
testdata/example-cron/setup.sh
vendored
Executable file
|
@ -0,0 +1,2 @@
|
||||||
|
mkdir /srv/example-cron-volume
|
||||||
|
FORGEJO_RUNNER_CONFIG=$EXAMPLE_DIR/runner-config.yaml forgejo-runner.sh reload
|
1
testdata/example-cron/teardown.sh
vendored
Executable file
1
testdata/example-cron/teardown.sh
vendored
Executable file
|
@ -0,0 +1 @@
|
||||||
|
forgejo-runner.sh reload
|
5
testdata/example-if-fail/expected-to-fail.sh
vendored
5
testdata/example-if-fail/expected-to-fail.sh
vendored
|
@ -1,5 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -ex
|
|
||||||
grep --quiet 'IF TEST FAILURE' $FORGEJO_RUNNER_LOGS
|
|
||||||
grep --quiet 'IF TEST ALWAYS' $FORGEJO_RUNNER_LOGS
|
|
7
testdata/example-if-fail/run.sh
vendored
Executable file
7
testdata/example-if-fail/run.sh
vendored
Executable file
|
@ -0,0 +1,7 @@
|
||||||
|
if forgejo-test-helper.sh run_workflow testdata/example-$example http://root:admin1234@$(cat forgejo-ip):3000 root example-$example setup-forgejo $(cat forgejo-token) >& /tmp/run.out ; then
|
||||||
|
cat /tmp/run.out
|
||||||
|
false
|
||||||
|
fi
|
||||||
|
|
||||||
|
grep --quiet 'IF TEST FAILURE' $FORGEJO_RUNNER_LOGS
|
||||||
|
grep --quiet 'IF TEST ALWAYS' $FORGEJO_RUNNER_LOGS
|
3
testdata/example-service/setup.sh
vendored
Executable file
3
testdata/example-service/setup.sh
vendored
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
> /srv/example-service-volume-valid
|
||||||
|
> /srv/example-service-volume-invalid
|
||||||
|
FORGEJO_RUNNER_CONFIG=$EXAMPLE_DIR/runner-config.yaml forgejo-runner.sh reload
|
1
testdata/example-service/teardown.sh
vendored
Executable file
1
testdata/example-service/teardown.sh
vendored
Executable file
|
@ -0,0 +1 @@
|
||||||
|
forgejo-runner.sh reload
|
Loading…
Reference in a new issue