From b2d99f4c4aeee43106bffe2210ea8a28e7a5c481 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Sat, 12 Jul 2025 08:08:25 +0000 Subject: [PATCH] actions: shell: assert shell behavior (#788) Refs https://code.forgejo.org/forgejo/runner/issues/150 Reviewed-on: https://code.forgejo.org/forgejo/end-to-end/pulls/788 Co-authored-by: Earl Warren Co-committed-by: Earl Warren --- actions/actions.sh | 2 +- .../example-shell/.forgejo/workflows/test.yml | 78 +++++++++++++++++++ actions/example-shell/runner-config.yaml | 32 ++++++++ actions/example-shell/setup.sh | 1 + actions/example-shell/teardown.sh | 1 + 5 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 actions/example-shell/.forgejo/workflows/test.yml create mode 100644 actions/example-shell/runner-config.yaml create mode 100755 actions/example-shell/setup.sh create mode 100755 actions/example-shell/teardown.sh diff --git a/actions/actions.sh b/actions/actions.sh index bb21e8a1..b1e6bd8a 100755 --- a/actions/actions.sh +++ b/actions/actions.sh @@ -143,7 +143,7 @@ function test_actions() { done fi - for example in echo lxc config-options cache checkout service container expression local-action docker-action if if-fail push tag push-cancel artifacts pull-request context; do + for example in shell echo lxc config-options cache checkout service container expression local-action docker-action if if-fail push tag push-cancel artifacts pull-request context; do run actions_verify_example $example done diff --git a/actions/example-shell/.forgejo/workflows/test.yml b/actions/example-shell/.forgejo/workflows/test.yml new file mode 100644 index 00000000..38a2a6cd --- /dev/null +++ b/actions/example-shell/.forgejo/workflows/test.yml @@ -0,0 +1,78 @@ +on: [push] + +env: + ASSERT_SHELL: 'set -x ; readlink /proc/$$/exe ; readlink /proc/$$/exe | grep ' + +jobs: + default: + # docker:docker://code.forgejo.org/oci/node:22-bookworm + runs-on: docker + steps: + - name: default is bash + run: | + ${{ env.ASSERT_SHELL }} /bash + + defaults-run: + needs: [default] + # alpine:docker://code.forgejo.org/oci/alpine:latest + runs-on: alpine + defaults: + run: + shell: sh + steps: + - name: default is sh which is an alias for busybox in alpine + run: | + ${{ env.ASSERT_SHELL }} /busybox + + alpine: + needs: [defaults-run] + runs-on: docker + container: + image: code.forgejo.org/oci/alpine:latest + steps: + - name: default is sh which is an alias for busybox in alpine + run: | + ${{ env.ASSERT_SHELL }} /busybox + + python: + needs: [alpine] + runs-on: docker + container: + image: code.forgejo.org/oci/python:slim + steps: + - name: python => python {0} + shell: python + run: | + print("something") + + other: + needs: [python] + runs-on: docker + container: + image: code.forgejo.org/oci/node:22-bookworm + steps: + - name: default is sh which is an alias for dash in bookworm + run: | + ${{ env.ASSERT_SHELL }} /dash + + - name: bash => bash --noprofile --norc -e -o pipefail {0} + shell: bash + run: | + ${{ env.ASSERT_SHELL }} /bash + shopt -o + shopt -o | grep --quiet 'pipefail.*on' + + - name: sh => sh -e {0} + shell: sh + run: | + ${{ env.ASSERT_SHELL }} /dash + + - name: node => node {0} + shell: node + run: | + console.log("something") + + - name: dash -e {0} + shell: dash -e {0} + run: | + ${{ env.ASSERT_SHELL }} /dash diff --git a/actions/example-shell/runner-config.yaml b/actions/example-shell/runner-config.yaml new file mode 100644 index 00000000..4e4974d2 --- /dev/null +++ b/actions/example-shell/runner-config.yaml @@ -0,0 +1,32 @@ + +log: + level: debug + +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:22-bookworm + - alpine:docker://code.forgejo.org/oci/alpine:latest + +cache: + enabled: false + dir: "" + host: "" + port: 0 + +container: + network: "" + privileged: false + options: + workdir_parent: + valid_volumes: [] + docker_host: "" + +host: + workdir_parent: diff --git a/actions/example-shell/setup.sh b/actions/example-shell/setup.sh new file mode 100755 index 00000000..9c1f5adf --- /dev/null +++ b/actions/example-shell/setup.sh @@ -0,0 +1 @@ +FORGEJO_RUNNER_CONFIG=$EXAMPLE_DIR/runner-config.yaml forgejo-runner.sh reload diff --git a/actions/example-shell/teardown.sh b/actions/example-shell/teardown.sh new file mode 100755 index 00000000..b410c513 --- /dev/null +++ b/actions/example-shell/teardown.sh @@ -0,0 +1 @@ +forgejo-runner.sh reload