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-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 52be20f..c9a4cdf 100644 --- a/actions/example-pull-request/.forgejo/workflows/test.yml +++ b/actions/example-pull-request/.forgejo/workflows/test.yml @@ -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: | diff --git a/actions/run.sh b/actions/run.sh index a776982..eee678a 100755 --- a/actions/run.sh +++ b/actions/run.sh @@ -19,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 @@ -34,7 +34,7 @@ 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() { @@ -101,7 +101,7 @@ 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