mirror of
https://code.forgejo.org/actions/setup-forgejo.git
synced 2024-11-24 01:20:56 -05:00
Merge pull request 'add 'if' examples' (#45) from earl-warren/setup-forgejo:wip-if into main
Reviewed-on: https://code.forgejo.org/actions/setup-forgejo/pulls/45 Reviewed-by: dachary <dachary@noreply.code.forgejo.org>
This commit is contained in:
commit
db910eb6ef
5 changed files with 88 additions and 5 deletions
|
@ -3,11 +3,18 @@ on: [ push, pull_request ]
|
||||||
env:
|
env:
|
||||||
#
|
#
|
||||||
# List of tests to run as found in testdata/example-$test. The
|
# List of tests to run as found in testdata/example-$test. The
|
||||||
# directory will be used to create a git repository, uploaded to a
|
# directory will be used to create a git repository uploaded to a
|
||||||
# Forgejo instance. The test will be a success once the status of
|
# Forgejo instance.
|
||||||
|
#
|
||||||
|
# The test will be a success once the status of
|
||||||
# the commit is success, as set by the Forgejo Action run.
|
# the commit is success, as set by the Forgejo Action run.
|
||||||
#
|
#
|
||||||
TESTS: 'echo service container expression local-action docker-action'
|
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:
|
||||||
|
@ -28,7 +35,8 @@ jobs:
|
||||||
#
|
#
|
||||||
./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 ; do
|
|
||||||
|
for example in $TESTS $TESTS_FAILING ; do
|
||||||
|
|
||||||
if test $example = service ; then
|
if test $example = service ; then
|
||||||
> /srv/example-service-volume-valid
|
> /srv/example-service-volume-valid
|
||||||
|
@ -41,7 +49,13 @@ jobs:
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "============================ BEGIN example-$example ==================="
|
echo "============================ BEGIN example-$example ==================="
|
||||||
./forgejo-test-helper.sh run_workflow testdata/example-$example http://root:admin1234@$(cat forgejo-ip):3000 root example-$example setup-forgejo $(cat forgejo-token)
|
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
|
||||||
|
else
|
||||||
|
cat /tmp/run.out
|
||||||
|
test -f testdata/example-$example/expected-to-fail.sh
|
||||||
|
fi
|
||||||
echo "============================ END example-$example ==================="
|
echo "============================ END example-$example ==================="
|
||||||
|
|
||||||
if test -f $config ; then
|
if test -f $config ; then
|
||||||
|
|
17
testdata/example-if-cancel/.forgejo/workflows/test.yml
vendored
Normal file
17
testdata/example-if-cancel/.forgejo/workflows/test.yml
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#
|
||||||
|
# As of Forgejo v1.20 running this example would require using the web
|
||||||
|
# endpoints because there is no API to do the same.
|
||||||
|
#
|
||||||
|
# It was manually tested to **not work** with Forgejo v1.20 & runner 2.5.0
|
||||||
|
#
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: docker
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- run: sleep infinity
|
||||||
|
|
||||||
|
- if: cancelled()
|
||||||
|
run: echo IF TEST CANCELLED
|
30
testdata/example-if-fail/.forgejo/workflows/test.yml
vendored
Normal file
30
testdata/example-if-fail/.forgejo/workflows/test.yml
vendored
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: docker
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- run: false
|
||||||
|
- if: failure()
|
||||||
|
run: echo IF TEST FAILURE
|
||||||
|
- if: always()
|
||||||
|
run: echo IF TEST ALWAYS
|
||||||
|
|
||||||
|
#
|
||||||
|
# This is documented in GitHub Actions and does not work in Forgejo Actions
|
||||||
|
# as of 3.0.0.
|
||||||
|
#
|
||||||
|
# If you have a chain of dependent jobs, failure() returns true if any ancestor job fails.
|
||||||
|
#
|
||||||
|
# first:
|
||||||
|
# runs-on: docker
|
||||||
|
# steps:
|
||||||
|
# - run: false
|
||||||
|
|
||||||
|
# second:
|
||||||
|
# runs-on: docker
|
||||||
|
# needs: [first]
|
||||||
|
# steps:
|
||||||
|
# - if: failure()
|
||||||
|
# run: echo IF TEST FAIL DEPENDS
|
5
testdata/example-if-fail/expected-to-fail.sh
vendored
Executable file
5
testdata/example-if-fail/expected-to-fail.sh
vendored
Executable file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
grep --quiet 'IF TEST FAILURE' $FORGEJO_RUNNER_LOGS
|
||||||
|
grep --quiet 'IF TEST ALWAYS' $FORGEJO_RUNNER_LOGS
|
17
testdata/example-if/.forgejo/workflows/test.yml
vendored
Normal file
17
testdata/example-if/.forgejo/workflows/test.yml
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
basic:
|
||||||
|
runs-on: docker
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: if true
|
||||||
|
if: true
|
||||||
|
id: if_true
|
||||||
|
run: echo 'check=good' >> $GITHUB_OUTPUT
|
||||||
|
- name: verify if true was run
|
||||||
|
run: test ${{ steps.if_true.outputs.check }} = good
|
||||||
|
|
||||||
|
- name: if false
|
||||||
|
if: false
|
||||||
|
run: false
|
Loading…
Reference in a new issue