actions: add example-7-0-schedule

verify runs-on variable expansion happens on scheduled workflows

* Adds the TEST_SCHEDULE_RUNSON=docker variable
* Use it in a scheduled job
* Run this test only with Forgejo versions greater or equal to 8.0
  otherwise it is not implemented yet
This commit is contained in:
Earl Warren 2024-04-06 11:07:10 +02:00
parent 99295ebc86
commit 6a9502dfe2
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
4 changed files with 62 additions and 1 deletions

View file

@ -6,6 +6,7 @@ ACTIONS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
function actions_verify_example() { function actions_verify_example() {
local example=$1 local example=$1
export HOST_PORT
export url=http://${FORGEJO_USER}:${FORGEJO_PASSWORD}@${HOST_PORT} export url=http://${FORGEJO_USER}:${FORGEJO_PASSWORD}@${HOST_PORT}
export token=$(cat $DOT_FORGEJO_CURL/token) export token=$(cat $DOT_FORGEJO_CURL/token)
@ -87,7 +88,7 @@ function actions_runner_version() {
} }
function test_actions() { function test_actions() {
local versions="${1:-1.20 1.21 $RELEASE_NUMBERS_AND_DEV}" local versions=8.0-dev
for version in $versions ; do for version in $versions ; do
@ -96,5 +97,11 @@ function test_actions() {
log_info "Testing actions with Forgejo $version & Forgejo runner $runner_version" log_info "Testing actions with Forgejo $version & Forgejo runner $runner_version"
if dpkg --compare-versions $version ge 7.0 ; then
for example in 7-0-schedule ; do
run actions_verify_example $example
done
fi
done done
} }

View file

@ -0,0 +1,23 @@
on:
schedule:
- cron: '* * * * *'
jobs:
test:
runs-on: ${{ vars.TEST_SCHEDULE_RUNSON }}
container:
image: code.forgejo.org/oci/debian:bookworm
options: "--volume /srv/example:/srv/example"
steps:
- run: |
echo "TEST_SCHEDULE_RUNSON=${{ vars.TEST_SCHEDULE_RUNSON }}"
touch /srv/example/7-0-schedule-volume/DONE
- name: save context
run: |
d=/srv/example/7-0-schedule/contexts/$GITHUB_EVENT_NAME
mkdir -p $d
cat > $d/github <<'EOF'
${{ toJSON(github) }}
EOF

View file

@ -0,0 +1,30 @@
forgejo-test-helper.sh push_workflow actions/example-$example $url root example-$example setup-forgejo $token
forgejo-curl.sh web -X POST http://${HOST_PORT}/admin/actions/variables/1/delete || true
forgejo-curl.sh web --form name=TEST_SCHEDULE_RUNSON --form data=docker http://${HOST_PORT}/admin/actions/variables/new
#
# Verify that creating a new branch with the same SHA as the default branch
# does not change the ref associated with the schedule
#
# See https://codeberg.org/forgejo/forgejo/pulls/1941 for more information
#
function verify_ref() {
local ref=$(sqlite3 $DIR/forgejo-work-path/forgejo.db 'select ref from action_schedule')
test "${ref##*/}" = "main"
}
verify_ref
api=$url/api/v1
forgejo-curl.sh api_json --data '{"new_branch_name":"zzzz"}' $api/repos/root/example-7-0-schedule/branches
verify_ref
# 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/7-0-schedule-volume/DONE ; then
cat $FORGEJO_RUNNER_LOGS
false
fi
c=/srv/example/7-0-schedule/contexts/schedule/github
cat $c
test "schedule" = "$(jq -r .event_name < $c)"
test "schedule" = "$(jq -r .event.action < $c)"

View file

@ -0,0 +1 @@
mkdir -p /srv/example/7-0-schedule-volume