diff --git a/actions/example-container/.forgejo/workflows/test.yml b/actions/example-container/.forgejo/workflows/test.yml index 6385e42..583df87 100644 --- a/actions/example-container/.forgejo/workflows/test.yml +++ b/actions/example-container/.forgejo/workflows/test.yml @@ -3,6 +3,6 @@ jobs: test: runs-on: docker container: - image: alpine:3.18 + image: alpine:3.19 steps: - run: grep Alpine /etc/os-release diff --git a/actions/example-context/.forgejo/fileone.txt b/actions/example-context/.forgejo/fileone.txt deleted file mode 100644 index a2628c1..0000000 --- a/actions/example-context/.forgejo/fileone.txt +++ /dev/null @@ -1 +0,0 @@ -ONE diff --git a/actions/example-context/.forgejo/workflows/test.yml b/actions/example-context/.forgejo/workflows/test.yml new file mode 100644 index 0000000..4da32ec --- /dev/null +++ b/actions/example-context/.forgejo/workflows/test.yml @@ -0,0 +1,188 @@ +on: [push] + +jobs: + test: + runs-on: docker + container: + image: code.forgejo.org/oci/node:20-bookworm + options: "--volume /srv/example:/srv/example" + steps: + + - name: env.CI + run: | + set -x + test "$CI" = true + test "$CI" = "${{ env.CI }}" + + - name: env.GITHUB_ACTION + run: | + set -x + echo "$GITHUB_ACTION" | grep -E '^[0-9]+$' + test "$GITHUB_ACTION" = "${{ env.GITHUB_ACTION }}" + + # See also actions/example-local-action/.forgejo/local-action/action.yml + - name: env.GITHUB_ACTION_PATH + run: | + set -x + test -z "$GITHUB_ACTION_PATH" + test "$GITHUB_ACTION_PATH" = "${{ env.GITHUB_ACTION_PATH }}" + + - name: when running an action + if: ${{ env.GITHUB_ACTIONS }} + uses: SELF@main + with: + input-one: "otherone" + + - name: env.GITHUB_ACTION_REPOSITORY + run: test -f /srv/example/example-context/GITHUB_ACTION_REPOSITORY + + - name: env.GITHUB_ACTION_PATH + run: test -f /srv/example/example-context/GITHUB_ACTION_PATH + + - name: env.GITHUB_ACTIONS + run: | + set -x + test "$GITHUB_ACTIONS" = true + test "$GITHUB_ACTIONS" = "${{ env.GITHUB_ACTIONS }}" + + - name: env.GITHUB_ACTOR + run: | + set -x + test "$GITHUB_ACTOR" + test "$GITHUB_ACTOR" = "${{ env.GITHUB_ACTOR }}" + + - name: env.GITHUB_API_URL + shell: bash + run: | + set -x + [[ "$GITHUB_API_URL" =~ /api/v1$ ]] + test "$GITHUB_API_URL" = "${{ env.GITHUB_API_URL }}" + + # See also actions/example-pull-request/.forgejo/workflows/test.yml + - name: env.GITHUB_BASE_REF + run: | + set -x + test -z "$GITHUB_BASE_REF" + test "$GITHUB_BASE_REF" = "${{ env.GITHUB_BASE_REF }}" + + # See also actions/example-pull-request/.forgejo/workflows/test.yml + - name: env.GITHUB_HEAD_REF + run: | + set -x + test -z "$GITHUB_HEAD_REF" + test "$GITHUB_HEAD_REF" = "${{ env.GITHUB_HEAD_REF }}" + + - name: env.GITHUB_ENV + run: | + set -x + test -f "$GITHUB_ENV" + test "$GITHUB_ENV" = "${{ env.GITHUB_ENV }}" + + - name: env.GITHUB_EVENT_NAME + run: | + set -x + test "$GITHUB_EVENT_NAME" = push + test "$GITHUB_EVENT_NAME" = "${{ env.GITHUB_EVENT_NAME }}" + + - name: env.GITHUB_JOB + run: | + set -x + test "$GITHUB_JOB" = test + test "$GITHUB_JOB" = "${{ env.GITHUB_JOB }}" + + - name: env.GITHUB_OUTPUT + run: | + set -x + test -f "$GITHUB_OUTPUT" + test "$GITHUB_OUTPUT" = "${{ env.GITHUB_OUTPUT }}" + + - name: env.GITHUB_PATH + run: | + set -x + test -f "$GITHUB_PATH" + test "$GITHUB_PATH" = "${{ env.GITHUB_PATH }}" + + - name: env.GITHUB_REF + shell: bash + run: | + set -x + [[ "$GITHUB_REF" =~ ^refs/ ]] + test "$GITHUB_REF" = "${{ env.GITHUB_REF }}" + + - name: env.GITHUB_REF_NAME + shell: bash + run: | + set -x + ! [[ "$GITHUB_REF_NAME" =~ ^refs/ ]] + test "$GITHUB_REF_NAME" = "${{ env.GITHUB_REF_NAME }}" + + - name: env.GITHUB_REPOSITORY + run: | + set -x + test "$GITHUB_REPOSITORY" = root/example-context + test "$GITHUB_REPOSITORY" = "${{ env.GITHUB_REPOSITORY }}" + + - name: env.GITHUB_REPOSITORY_OWNER + run: | + set -x + test "$GITHUB_REPOSITORY_OWNER" = root + test "$GITHUB_REPOSITORY_OWNER" = "${{ env.GITHUB_REPOSITORY_OWNER }}" + + - name: env.GITHUB_RUN_NUMBER + run: | + set -x + echo "$GITHUB_RUN_NUMBER" | grep -E '^[0-9]+$' + test "$GITHUB_RUN_NUMBER" = "${{ env.GITHUB_RUN_NUMBER }}" + + - name: env.GITHUB_SERVER_URL + shell: bash + run: | + set -x + [[ "$GITHUB_SERVER_URL" =~ ^http ]] + test "$GITHUB_SERVER_URL" = "${{ env.GITHUB_SERVER_URL }}" + + - name: env.GITHUB_SHA + run: | + set -x + test "$GITHUB_SHA" + test "$GITHUB_SHA" = "${{ env.GITHUB_SHA }}" + + - name: env.GITHUB_STEP_SUMMARY + run: | + set -x + test -f "$GITHUB_STEP_SUMMARY" + test "$GITHUB_STEP_SUMMARY" = "${{ env.GITHUB_STEP_SUMMARY }}" + + # See also actions/example-pull-request/.forgejo/workflows/test.yml + - name: env.GITHUB_TOKEN + run: | + set -x + test "$GITHUB_TOKEN" + test "$GITHUB_TOKEN" = "${{ env.GITHUB_TOKEN }}" + + - name: env.GITHUB_WORKSPACE + run: | + set -x + test -d "$GITHUB_WORKSPACE" + test "$GITHUB_WORKSPACE" = "${{ env.GITHUB_WORKSPACE }}" + + - name: RUNNER_ARCH + run: | + set -x + test "$RUNNER_ARCH" = X64 + + - name: RUNNER_OS + run: | + set -x + test "$RUNNER_OS" = Linux + + # runner 3.3.0 $RUNNER_TOOL_CACHE is not an existing directory + # - name: RUNNER_TOOL_CACHE + # run: | + # set -x + # test -d "$RUNNER_TOOL_CACHE" + + - name: RUNNER_TEMP + run: | + set -x + test -d "$RUNNER_TEMP" diff --git a/actions/example-context/action-for-context/action.yml b/actions/example-context/action-for-context/action.yml new file mode 100644 index 0000000..5a79adc --- /dev/null +++ b/actions/example-context/action-for-context/action.yml @@ -0,0 +1,21 @@ +inputs: + input-one: + default: 'one' + description: 'description one' + +runs: + using: "composite" + steps: + - name: GITHUB_ACTION_REPOSITORY + run: | + set -x + test "$GITHUB_ACTION_REPOSITORY" = root/action-for-context + test "$GITHUB_ACTION_REPOSITORY" = "${{ env.GITHUB_ACTION_REPOSITORY }}" + touch /srv/example/example-context/GITHUB_ACTION_REPOSITORY + + - name: GITHUB_ACTION_PATH + shell: bash + run: | + set -x + [[ "$GITHUB_ACTION_PATH" =~ action-for-context@main$ ]] + touch /srv/example/example-context/GITHUB_ACTION_PATH diff --git a/actions/example-context/run.sh b/actions/example-context/run.sh new file mode 100644 index 0000000..d9d08b8 --- /dev/null +++ b/actions/example-context/run.sh @@ -0,0 +1 @@ +forgejo-test-helper.sh run_workflow actions/example-$example $url root example-$example action-for-context $token diff --git a/actions/example-context/setup.sh b/actions/example-context/setup.sh new file mode 100644 index 0000000..c7759f4 --- /dev/null +++ b/actions/example-context/setup.sh @@ -0,0 +1,3 @@ +mkdir -p /srv/example/example-context + +forgejo-test-helper.sh push actions/example-$example/action-for-context $url root action-for-context diff --git a/actions/example-cron/.forgejo/workflows/test.yml b/actions/example-cron/.forgejo/workflows/test.yml index c81b017..5f9a843 100644 --- a/actions/example-cron/.forgejo/workflows/test.yml +++ b/actions/example-cron/.forgejo/workflows/test.yml @@ -7,8 +7,8 @@ jobs: runs-on: docker container: image: code.forgejo.org/oci/debian:bookworm - options: "--volume /srv/example-cron-volume:/srv/example-cron-volume" + options: "--volume /srv/example:/srv/example" steps: - run: | - touch /srv/example-cron-volume/DONE + touch /srv/example/cron-volume/DONE diff --git a/actions/example-cron/run.sh b/actions/example-cron/run.sh index 3ced64c..c0dc193 100755 --- a/actions/example-cron/run.sh +++ b/actions/example-cron/run.sh @@ -16,7 +16,7 @@ forgejo-curl.sh api_json --data '{"new_branch_name":"zzzz"}' $api/repos/root/exa verify_ref # 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 +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 diff --git a/actions/example-cron/runner-config.yaml b/actions/example-cron/runner-config.yaml deleted file mode 100644 index 119cde4..0000000 --- a/actions/example-cron/runner-config.yaml +++ /dev/null @@ -1,30 +0,0 @@ - -log: - level: info - -runner: - file: .runner - capacity: 1 - env_file: .env - timeout: 3h - insecure: false - fetch_timeout: 5s - fetch_interval: 2s - labels: ["docker:docker://code.forgejo.org/oci/node:16-bullseye"] - -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: diff --git a/actions/example-cron/setup.sh b/actions/example-cron/setup.sh index ee70b92..ed70dec 100755 --- a/actions/example-cron/setup.sh +++ b/actions/example-cron/setup.sh @@ -1,3 +1 @@ -rm -fr /srv/example-cron-volume -mkdir -p /srv/example-cron-volume -FORGEJO_RUNNER_CONFIG=$EXAMPLE_DIR/runner-config.yaml forgejo-runner.sh reload +mkdir -p /srv/example/cron-volume diff --git a/actions/example-cron/teardown.sh b/actions/example-cron/teardown.sh deleted file mode 100755 index b410c51..0000000 --- a/actions/example-cron/teardown.sh +++ /dev/null @@ -1 +0,0 @@ -forgejo-runner.sh reload diff --git a/actions/example-local-action/.forgejo/local-action/action.yml b/actions/example-local-action/.forgejo/local-action/action.yml index d83d33c..7963757 100644 --- a/actions/example-local-action/.forgejo/local-action/action.yml +++ b/actions/example-local-action/.forgejo/local-action/action.yml @@ -13,4 +13,10 @@ outputs: runs: using: "composite" steps: + - name: GITHUB_ACTION_PATH + run: | + set -x + test "$(basename $GITHUB_ACTION_PATH)" = local-action + test "$GITHUB_ACTION_PATH" = "${{ env.GITHUB_ACTION_PATH }}" + - run: echo key=${{ inputs.input-two-required }} >> $GITHUB_OUTPUT diff --git a/actions/example-pull-request/.forgejo/workflows/test.yml b/actions/example-pull-request/.forgejo/workflows/test.yml index 90e9fb4..c9a4cdf 100644 --- a/actions/example-pull-request/.forgejo/workflows/test.yml +++ b/actions/example-pull-request/.forgejo/workflows/test.yml @@ -10,7 +10,7 @@ jobs: runs-on: docker container: image: code.forgejo.org/oci/node:20-bookworm - options: "--volume /srv/example-pull-request:/srv/example-pull-request" + options: "--volume /srv/example:/srv/example" steps: - name: setup @@ -33,6 +33,24 @@ jobs: echo value=true >> $GITHUB_OUTPUT fi + # See also actions/example-context/.forgejo/workflows/test.yml + - name: env.GITHUB_BASE_REF + run: | + set -x + test "$GITHUB_BASE_REF" = main + test "$GITHUB_BASE_REF" = "${{ env.GITHUB_BASE_REF }}" + + # See also actions/example-context/.forgejo/workflows/test.yml + - name: env.GITHUB_HEAD_REF + run: | + set -x + if ${{ steps.forked.outputs.value }} ; then + test "$GITHUB_HEAD_REF" = main + else + test "$GITHUB_HEAD_REF" = other + fi + test "$GITHUB_HEAD_REF" = "${{ env.GITHUB_HEAD_REF }}" + - name: secrets shell: bash run: | @@ -115,7 +133,7 @@ jobs: - name: save event run: | - d=/srv/example-pull-request/${{ github.event.pull_request.head.repo.owner.username }}/$GITHUB_EVENT_NAME/${{ github.event.action }} + d=/srv/example/pull-request/${{ github.event.pull_request.head.repo.owner.username }}/$GITHUB_EVENT_NAME/${{ github.event.action }} mkdir -p $d cat > $d/event <<'EOF' ${{ toJSON(github.event) }} diff --git a/actions/example-pull-request/run.sh b/actions/example-pull-request/run.sh index 2a88afd..b6897a2 100755 --- a/actions/example-pull-request/run.sh +++ b/actions/example-pull-request/run.sh @@ -1,9 +1,11 @@ api=$url/api/v1 -export d=/srv/example-pull-request +export d=/srv/example/pull-request PROOF='some proof' function setup() { + mkdir -p $d + forgejo-test-helper.sh push_workflow actions/example-$example $url root example-$example setup-forgejo $token forgejo-curl.sh api_json --data-raw '{"username":"fork-org"}' $api/orgs diff --git a/actions/example-pull-request/setup.sh b/actions/example-pull-request/setup.sh index e93087e..72c13c0 100755 --- a/actions/example-pull-request/setup.sh +++ b/actions/example-pull-request/setup.sh @@ -1,8 +1,2 @@ -if test $(id -u) != 0 ; then - SUDO=sudo -fi +mkdir -p /srv/example/pull-request -$SUDO rm -fr /srv/example-pull-request/{root,fork-org} -rm -fr /srv/example-pull-request -mkdir -p /srv/example-pull-request -FORGEJO_RUNNER_CONFIG=$EXAMPLE_DIR/runner-config.yaml forgejo-runner.sh reload diff --git a/actions/example-pull-request/teardown.sh b/actions/example-pull-request/teardown.sh deleted file mode 100755 index b410c51..0000000 --- a/actions/example-pull-request/teardown.sh +++ /dev/null @@ -1 +0,0 @@ -forgejo-runner.sh reload diff --git a/actions/example-service/runner-config.yaml b/actions/example-service/runner-config.yaml index 4606852..27981ab 100644 --- a/actions/example-service/runner-config.yaml +++ b/actions/example-service/runner-config.yaml @@ -10,7 +10,7 @@ runner: insecure: false fetch_timeout: 5s fetch_interval: 2s - labels: ["docker:docker://code.forgejo.org/oci/node:16-bullseye"] + labels: ["docker:docker://code.forgejo.org/oci/node:20-bookworm"] cache: enabled: false diff --git a/actions/run.sh b/actions/run.sh index 717682d..eee678a 100755 --- a/actions/run.sh +++ b/actions/run.sh @@ -2,11 +2,13 @@ set -e +SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + function run() { local example=$1 export example - export EXAMPLE_DIR=$(pwd)/actions/example-$example + export EXAMPLE_DIR=$SELF_DIR/example-$example if test -f $EXAMPLE_DIR/setup.sh ; then echo "============================ SETUP example-$example ===================" @@ -17,7 +19,7 @@ function run() { echo "============================ RUN example-$example ===================" bash -ex $EXAMPLE_DIR/run.sh || return 1 else - forgejo-test-helper.sh run_workflow actions/example-$example $url root example-$example setup-forgejo $token || return 1 + forgejo-test-helper.sh run_workflow actions/example-$example $url root example-$example $example $token || return 1 fi if test -f $EXAMPLE_DIR/teardown.sh ; then @@ -32,16 +34,31 @@ function examples_v1_20() { function examples_v1_21() { # keep "cron" last otherwise it will linger and pollute the following runs - echo 'echo push-cancel artifacts service checkout pull-request container expression local-action docker-action if if-fail cron' + echo 'echo push-cancel artifacts service checkout pull-request container expression local-action context docker-action if if-fail cron' } function examples_v1_22() { examples_v1_21 } +function cleanup_example_volume() { + if ! test -d /srv/example ; then + mkdir -p /srv/example + return + fi + + if test $(id -u) != 0 ; then + SUDO=sudo + fi + + $SUDO rm -fr /srv/example/* +} + function setup() { local binary=$1 forgejo-binary.sh setup root admin1234 $binary + cleanup_example_volume + export FORGEJO_RUNNER_CONFIG=$SELF_DIR/runner-config.yaml forgejo-runner.sh setup } @@ -84,12 +101,13 @@ function main() { for example in $examples ; do echo "======================== BEGIN example-$example ===================" if ! time run $example >& /tmp/run.out ; then - cat /tmp/run.out + sed -e 's/^/[RUN] /' < /tmp/run.out echo "======================== FAIL example-$example ===================" sleep 5 # hack for Forgejo v1.21 to workaround a bug by which the last lines of the output are moved to the next step false fi echo "======================== END example-$example ===================" + cleanup_example_volume done } diff --git a/actions/example-pull-request/runner-config.yaml b/actions/runner-config.yaml similarity index 89% rename from actions/example-pull-request/runner-config.yaml rename to actions/runner-config.yaml index 5c3a6b3..12019d7 100644 --- a/actions/example-pull-request/runner-config.yaml +++ b/actions/runner-config.yaml @@ -23,7 +23,7 @@ container: privileged: false options: workdir_parent: - valid_volumes: ["/srv/example-pull-request"] + valid_volumes: ["/srv/example"] docker_host: "" host: