mirror of
https://code.forgejo.org/actions/setup-forgejo.git
synced 2024-11-23 21:30:55 -05:00
Merge pull request 'add example of cron task' (#49) from earl-warren/setup-forgejo:wip-cron into main
Reviewed-on: https://code.forgejo.org/actions/setup-forgejo/pulls/49 Reviewed-by: dachary <dachary@noreply.code.forgejo.org>
This commit is contained in:
commit
a80989ce28
12 changed files with 102 additions and 41 deletions
|
@ -1,31 +1,24 @@
|
|||
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:
|
||||
integration:
|
||||
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:
|
||||
- uses: actions/checkout@v3
|
||||
- run: |
|
||||
set -x
|
||||
LXC_IP_PREFIX=10.0.10 ./forgejo-dependencies.sh
|
||||
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.
|
||||
# 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
|
||||
#export PATH=$(pwd)/forgejo-runner:$PATH
|
||||
#
|
||||
./forgejo-runner.sh setup
|
||||
forgejo-runner.sh setup
|
||||
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
|
||||
> /srv/example-service-volume-valid
|
||||
> /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
|
||||
if test -f $EXAMPLE_DIR/setup.sh ; then
|
||||
source $EXAMPLE_DIR/setup.sh
|
||||
fi
|
||||
|
||||
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
|
||||
cat /tmp/run.out
|
||||
! test -f testdata/example-$example/expected-to-fail.sh
|
||||
if test -f $EXAMPLE_DIR/run.sh ; then
|
||||
source $EXAMPLE_DIR/run.sh
|
||||
else
|
||||
cat /tmp/run.out
|
||||
test -f testdata/example-$example/expected-to-fail.sh
|
||||
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
|
||||
fi
|
||||
echo "============================ END example-$example ==================="
|
||||
|
||||
if test -f $config ; then
|
||||
./forgejo-runner.sh reload
|
||||
if test -f $EXAMPLE_DIR/teardown.sh ; then
|
||||
source $EXAMPLE_DIR/teardown.sh
|
||||
fi
|
||||
done
|
||||
echo "============================ demo ==================="
|
||||
|
|
|
@ -105,7 +105,7 @@ function push() {
|
|||
)
|
||||
}
|
||||
|
||||
function run_workflow() {
|
||||
function push_workflow() {
|
||||
local directory="$1"
|
||||
local url="$2"
|
||||
local owner="$3"
|
||||
|
@ -119,6 +119,17 @@ function run_workflow() {
|
|||
fi
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -6,11 +6,12 @@ set -e
|
|||
DIR=/tmp
|
||||
if ${VERBOSE:-false}; then set -x; fi
|
||||
: ${CONTAINER:=forgejo}
|
||||
: ${RETRY_DELAYS:=1 1 5 5 15 30}
|
||||
|
||||
function retry() {
|
||||
rm -f $DIR/retry.out
|
||||
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
|
||||
success=true
|
||||
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