Merge pull request 'actions: context examples supporting the documentation' (#56) from earl-warren/end-to-end:wip-context into main

Reviewed-on: https://code.forgejo.org/forgejo/end-to-end/pulls/56
Reviewed-by: dachary <dachary@noreply.code.forgejo.org>
This commit is contained in:
earl-warren 2024-01-05 22:32:02 +00:00
commit 69747630a9
19 changed files with 272 additions and 56 deletions

View file

@ -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

View file

@ -1 +0,0 @@
ONE

View file

@ -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"

View file

@ -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

View file

@ -0,0 +1 @@
forgejo-test-helper.sh run_workflow actions/example-$example $url root example-$example action-for-context $token

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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:

View file

@ -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

View file

@ -1 +0,0 @@
forgejo-runner.sh reload

View file

@ -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

View file

@ -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) }}

View file

@ -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

View file

@ -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

View file

@ -1 +0,0 @@
forgejo-runner.sh reload

View file

@ -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

View file

@ -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
}

View file

@ -23,7 +23,7 @@ container:
privileged: false
options:
workdir_parent:
valid_volumes: ["/srv/example-pull-request"]
valid_volumes: ["/srv/example"]
docker_host: ""
host: