integration tests moved to end-to-end

This commit is contained in:
Earl Warren 2023-10-29 00:37:25 +02:00
parent a521fd2935
commit 34d0f8d26e
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
33 changed files with 3 additions and 739 deletions

View file

@ -11,17 +11,13 @@ jobs:
strategy:
matrix:
info:
- version: "1.21.0-3-rc0"
- version: "1.21.0-5-rc2"
image: codeberg.org/forgejo-experimental/forgejo
# keep "cron" last otherwise it will linger and pollute the following runs
tests: "${{ vars.V1_21_TESTS || 'echo push-cancel artifacts service checkout pull-request container expression local-action docker-action if if-fail cron' }}"
- version: "1.20"
image: codeberg.org/forgejo/forgejo
tests: "${{ vars.V1_20_TESTS || 'echo checkout service container expression local-action docker-action if if-fail' }}"
steps:
- uses: actions/checkout@v3
- if: matrix.info.tests != 'none'
shell: bash
- uses: actions/checkout@v4
- shell: bash
run: |
LXC_IP_PREFIX=10.0.10 ./forgejo-dependencies.sh
export PATH=$(pwd):$PATH
@ -33,38 +29,3 @@ jobs:
echo "============================ demo ==================="
forgejo-test-helper.sh run_workflow testdata/demo $url root demo setup-forgejo $token
function run() {
local example=$1
export example
export EXAMPLE_DIR=$(pwd)/testdata/example-$example
if test -f $EXAMPLE_DIR/setup.sh ; then
echo "============================ SETUP example-$example ==================="
bash -ex $EXAMPLE_DIR/setup.sh || return 1
fi
if test -f $EXAMPLE_DIR/run.sh ; then
echo "============================ RUN example-$example ==================="
bash -ex $EXAMPLE_DIR/run.sh || return 1
else
forgejo-test-helper.sh run_workflow testdata/example-$example $url root example-$example setup-forgejo $token || return 1
fi
if test -f $EXAMPLE_DIR/teardown.sh ; then
echo "============================ TEARDOWN example-$example ==================="
bash -ex $EXAMPLE_DIR/teardown.sh || return 1
fi
}
for example in ${{ matrix.info.tests }} ; do
echo "============================ BEGIN example-$example ==================="
if ! time run $example >& /tmp/run.out ; then
cat /tmp/run.out
echo "============================ FAIL example-$example ==================="
sleep 5 # hack for Forgejo v1.21 to workaround a but by which the last lines of the output are moved to the next step
false
fi
echo "============================ END example-$example ==================="
done

6
testdata/README.txt vendored
View file

@ -1,6 +0,0 @@
Run the tests from source for debugging purposes with:
#
# runner-config.yaml will be ignored if it does not exist and the default configuration will be used
#
forgejo-runner exec --config testdata/example-$service/runner-config.yaml --workflows testdata/example-$service/.forgejo/workflows

View file

@ -1,47 +0,0 @@
on: [push]
jobs:
upload-many:
runs-on: docker
steps:
- run: mkdir -p artifacts
- run: touch artifacts/ONE artifacts/TWO
- uses: actions/upload-artifact@v3
with:
name: many-artifacts
path: artifacts/
download-many:
needs: [upload-many]
runs-on: docker
steps:
- uses: actions/download-artifact@v3
- run: |
test -f many-artifacts/ONE
test -f many-artifacts/TWO
upload-one:
runs-on: docker
steps:
- run: mkdir -p path/to/artifact
- run: echo hello > path/to/artifact/world.txt
- uses: actions/upload-artifact@v3
with:
name: my-artifact
path: path/to/artifact/world.txt
download-one:
needs: [upload-one]
runs-on: docker
steps:
- run: "! test -f world.txt"
- uses: actions/download-artifact@v3
with:
name: my-artifact
- run: "test -f world.txt"

View file

@ -1,10 +0,0 @@
on: [push]
jobs:
v3:
runs-on: docker
steps:
- uses: actions/checkout@v3
v4:
runs-on: docker
steps:
- uses: actions/checkout@v4

View file

@ -1,8 +0,0 @@
on: [push]
jobs:
test:
runs-on: docker
container:
image: alpine:3.18
steps:
- run: grep Alpine /etc/os-release

View file

@ -1,14 +0,0 @@
on:
schedule:
- cron: '* * * * *'
jobs:
test:
runs-on: docker
container:
image: code.forgejo.org/oci/debian:bookworm
options: "--volume /srv/example-cron-volume:/srv/example-cron-volume"
steps:
- run: |
touch /srv/example-cron-volume/DONE

View file

@ -1,7 +0,0 @@
forgejo-test-helper.sh push_workflow testdata/example-$example http://root:admin1234@$(cat forgejo-ip):3000 root example-$example setup-forgejo $(cat forgejo-token)
# 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
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,2 +0,0 @@
mkdir /srv/example-cron-volume
FORGEJO_RUNNER_CONFIG=$EXAMPLE_DIR/runner-config.yaml forgejo-runner.sh reload

View file

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

View file

@ -1,19 +0,0 @@
on: [push]
jobs:
ls:
runs-on: docker
steps:
#
# This Docker action creates the file SOMEFILE ...
#
- uses: https://code.forgejo.org/forgejo/test-setup-forgejo-docker@main
with:
args: ${{ github.workspace }}/SOMEFILE
#
# ... which then also exists in the job workspace
# because both docker containers are automatically
# sharing the volume that contains it.
#
- run: |
test -f ${{ github.workspace }}/SOMEFILE

View file

@ -1,6 +0,0 @@
on: [push]
jobs:
test:
runs-on: docker
steps:
- run: echo All Good

View file

@ -1 +0,0 @@
ONE

View file

@ -1,106 +0,0 @@
on: [push]
env:
KEY1: value1
KEY2: value2
jobs:
test:
runs-on: docker
steps:
- name: environment
run: |
set -x
test "KEY1=${{ env.KEY1 }}" = "KEY1=value1"
test "KEY2=$KEY2" = "KEY2=value2"
- name: if skip one
run: false
if: env.KEY1 == 'nogood'
- name: if skip two
run: false
if: ${{ env.KEY1 == 'nogood' }}
- name: if does not skip
id: conditional
run: echo 'check=good' >> $GITHUB_OUTPUT
if: env.KEY1 == 'value1'
- name: verify if did not skip
run: test ${{ steps.conditional.outputs.check }} = good
- name: logical
run: |
set -x
test "${{ fromJSON('["one","two"]')[0] }}" = "one"
test "${{ !false }}" = "true"
test "${{ !( 1 > 2 ) }}" = "true"
test "${{ 1 >= 1 }}" = "true"
test "${{ 1 <= 1 }}" = "true"
test "${{ 1 < 2 }}" = "true"
test "${{ 1 == 1 }}" = "true"
test "${{ 1 != 2 }}" = "true"
test "${{ true && true }}" = "true"
test "${{ true || false }}" = "true"
- name: literals
run: |
set -x
test "${{ 0.9 }}" = "0.9"
test "${{ env.NULL == null }}" = "true"
test "${{ true == true }}" = "true"
test "${{ true == false }}" = "false"
test "${{ 'something' }}" = "something"
test "${{ 'inside''quote' }}" = "inside'quote"
test "${{ 'something' == 'SOMETHING' }}" = "true"
- name: contains
run: |
set -x
test "${{ contains('number 0.9', 0.9) }}" = "true"
test "${{ contains('zeroonetwo', 'one') }}" = "true"
test "${{ contains('zeroonetwo', 'notfound') }}" = "false"
test "${{ contains(fromJSON('["one","two"]'), 'one') }}" = "true"
test "${{ contains(fromJSON('["one","two"]'), 'notfound') }}" = "false"
- name: startsWith
run: |
set -x
test "${{ startsWith('0.9 number', 0.9) }}" = "true"
test "${{ startsWith('some number', 'SOME') }}" = "true"
test "${{ startsWith('number', '0.9') }}" = "false"
- name: endsWith
run: |
set -x
test "${{ endsWith('number 0.9', 0.9) }}" = "true"
test "${{ endsWith('number some', 'SOME') }}" = "true"
test "${{ endsWith('number', '0.9') }}" = "false"
- name: format
run: |
set -x
test "${{ format('{0} and {1}', 'A', 'B') }}" = "A and B"
test "${{ format('{{ and }}', 'A', 'B') }}" = "{ and }"
- name: join
run: |
set -x
test "${{ join(fromJSON('["one","two"]')) }}" = "one,two"
test "${{ join(fromJSON('["one","two"]'), '+') }}" = "one+two"
- name: toJSON
run: |
set -x
test "${{ toJSON(0.9) }}" = "0.9"
- name: fromJSON
run: |
set -x
test "${{ fromJSON('["one","two"]')[0] }}" = 'one'
- name: hashFiles
run: |
set -x
hash="bd52020371c038c4ad38a8d2df05dfa1a220d40fbe1ae83b63d6010cb527e531"
test "${{ hashFiles('testdata/example-expression/.forgejo/fileone.txt') }}" = $hash
test "${{ hashFiles('testdata/example-expression/.forgejo/fileone.*') }}" = $hash

View file

@ -1,17 +0,0 @@
#
# As of Forgejo v1.20 running this example would require using the web
# endpoints because there is no API to do the same.
#
# It was manually tested to **not work** with Forgejo v1.21 & runner 3.0.1
#
on: [push]
jobs:
test:
runs-on: docker
steps:
- run: sleep infinity
- if: cancelled()
run: echo IF TEST CANCELLED

View file

@ -1,30 +0,0 @@
on: [push]
jobs:
test:
runs-on: docker
steps:
- run: false
- if: failure()
run: echo IF TEST FAILURE
- if: always()
run: echo IF TEST ALWAYS
#
# This is documented in GitHub Actions and does not work in Forgejo Actions
# as of 3.0.1.
#
# If you have a chain of dependent jobs, failure() returns true if any ancestor job fails.
#
# first:
# runs-on: docker
# steps:
# - run: false
# second:
# runs-on: docker
# needs: [first]
# steps:
# - if: failure()
# run: echo IF TEST FAIL DEPENDS

View file

@ -1,4 +0,0 @@
! forgejo-test-helper.sh run_workflow testdata/example-$example http://root:admin1234@$(cat forgejo-ip):3000 root example-$example setup-forgejo $(cat forgejo-token)
grep --quiet 'IF TEST FAILURE' $FORGEJO_RUNNER_LOGS
grep --quiet 'IF TEST ALWAYS' $FORGEJO_RUNNER_LOGS

View file

@ -1,17 +0,0 @@
on: [push]
jobs:
basic:
runs-on: docker
steps:
- name: if true
if: true
id: if_true
run: echo 'check=good' >> $GITHUB_OUTPUT
- name: verify if true was run
run: test ${{ steps.if_true.outputs.check }} = good
- name: if false
if: false
run: false

View file

@ -1,16 +0,0 @@
inputs:
input-one:
default: 'one'
description: 'description one'
input-two-required:
description: 'description two'
required: true
outputs:
key:
description: 'output value'
value: "${{ steps.one.outputs.key }}"
runs:
using: "composite"
steps:
- run: echo key=${{ inputs.input-two-required }} >> $GITHUB_OUTPUT

View file

@ -1,11 +0,0 @@
on: [push]
jobs:
ls:
runs-on: docker
steps:
- uses: actions/checkout@v3
- id: local-action
uses: ./.forgejo/local-action
with:
input-two-required: "two"
- run: test "${{ steps.local-action.outputs.key }}" = "two"

View file

@ -1,123 +0,0 @@
on:
pull_request:
pull_request_target:
types:
- opened
- synchronize
jobs:
test:
runs-on: docker
container:
image: code.forgejo.org/oci/debian:bookworm
options: "--volume /srv/example-pull-request:/srv/example-pull-request"
steps:
- name: setup
shell: bash
run: |
set -x
test $GITHUB_TOKEN = ${{ env.GITHUB_TOKEN }}
test $GITHUB_TOKEN = ${{ github.token }}
export DEBIAN_FRONTEND=noninteractive ; apt-get -qq update ; apt-get install -y -qq curl git >& /dev/null
curl -sS -o /usr/local/bin/forgejo-curl.sh https://code.forgejo.org/forgejo/forgejo-curl/raw/branch/main/forgejo-curl.sh && chmod +x /usr/local/bin/forgejo-curl.sh
forgejo-curl.sh --token "$GITHUB_TOKEN" login $GITHUB_SERVER_URL
forgejo-curl.sh api_json $GITHUB_SERVER_URL/api/v1/user
- name: secrets
shell: bash
run: |
set -x
if test ${{ github.event.pull_request.base.repo.full_name }} = ${{ github.event.pull_request.head.repo.full_name }} ; then
forked=false
else
forked=true
fi
case $GITHUB_EVENT_NAME in
pull_request_target)
#
# all PRs: secrets
#
test "${{ secrets.SECRET }}"
;;
pull_request)
if $forked ; then
#
# PRs from forked repositories: no secrets
#
test -z "${{ secrets.SECRET }}"
else
#
# PRs from the same repository: secrets
#
test "${{ secrets.SECRET }}"
fi
;;
*)
echo unexpected event $GITHUB_EVENT_NAME
false
;;
esac
- name: PR TOKEN scopes
shell: bash
run: |
set -x
if test ${{ github.event.pull_request.base.repo.full_name }} = ${{ github.event.pull_request.head.repo.full_name }} ; then
forked=false
else
forked=true
fi
function assert_fail_if_forked() {
if "$@" ; then
! $forked
else
$forked
fi
}
#
# create an issue
#
base_repo=${{ github.event.pull_request.base.repo.full_name }}
forgejo-curl.sh api_json --data-raw '{"title":"ISSUE"}' $GITHUB_SERVER_URL/api/v1/repos/$base_repo/issues
url=$(echo $GITHUB_SERVER_URL | sed -e "s|://|://$GITHUB_TOKEN@|")
git clone $url/$base_repo base
branch=B$RANDOM
(
cd base
git checkout -b $branch
git config user.email root@example.com
git config user.name username
echo CHANGE >> README
git add .
git commit -m 'change'
case $GITHUB_EVENT_NAME in
pull_request_target|pull_request)
#
# repository write scope via http git passthrough
#
assert_fail_if_forked git push --force -u origin $branch
#
# repository write scope via the API
#
assert_fail_if_forked forgejo-curl.sh api_json --data-raw '{"title":"PR","base":"main","head":"'$branch'"}' $GITHUB_SERVER_URL/api/v1/repos/$base_repo/pulls
assert_fail_if_forked forgejo-curl.sh api_json --data-raw '{"color":"#ffffff","name":"labelname"}' $GITHUB_SERVER_URL/api/v1/repos/$base_repo/labels
#
# See https://codeberg.org/forgejo/forgejo/issues/1525
#
! forgejo-curl.sh api_json --data-raw '{"new_branch_name":"B'$RANDOM'"}' $GITHUB_SERVER_URL/api/v1/repos/$base_repo/branches
;;
*)
echo unexpected event $GITHUB_EVENT_NAME
false
;;
esac
)
- name: save event
run: |
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) }}
EOF

View file

@ -1,8 +0,0 @@
#!/bin/bash
set -ex
test -d $d/fork-org/pull_request/opened
test -d $d/fork-org/pull_request_target/opened
test -d $d/root/pull_request/opened
test -d $d/root/pull_request_target/opened

View file

@ -1,58 +0,0 @@
url=http://root:admin1234@$(cat forgejo-ip):3000
api=$url/api/v1
export d=/srv/example-pull-request
PROOF='some proof'
function setup() {
forgejo-test-helper.sh push_workflow testdata/example-$example http://root:admin1234@$(cat forgejo-ip):3000 root example-$example setup-forgejo $(cat forgejo-token)
forgejo-curl.sh api_json --data-raw '{"username":"fork-org"}' $api/orgs
forgejo-curl.sh api_json --data-raw '{"organization":"fork-org"}' $api/repos/root/example-pull-request/forks
forgejo-curl.sh api_json -X PUT --data-raw '{"data":"AAAA"}' $api/repos/root/example-pull-request/actions/secrets/SECRET
(
cd $d
git clone $url/fork-org/example-pull-request fork
cd fork
git config user.email root@example.com
git config user.name username
echo fork $PROOF >> README
git add .
git commit -m 'fork change'
git push
)
forgejo.sh retry forgejo-curl.sh api_json --data-raw '{"title":"PR from fork","base":"main","head":"fork-org:main"}' $api/repos/root/example-pull-request/pulls
(
cd $d
git clone $url/root/example-pull-request
cd example-pull-request
git checkout -b other
git config user.email root@example.com
git config user.name username
echo other $PROOF >> README
git add .
git commit -m 'other change'
git push --force -u origin other
)
forgejo.sh retry forgejo-curl.sh api_json --data-raw '{"title":"PR same repo","base":"main","head":"other"}' $api/repos/root/example-pull-request/pulls
export RETRY_DELAYS="60 60 60 60 60 60 60"
for assert in $EXAMPLE_DIR/assert-*.sh ; do
if ! forgejo.sh retry $assert ; then
find $d
cat $FORGEJO_RUNNER_LOGS
false
fi
done
}
function main() {
setup
}
main

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: "bridge"
privileged: false
options:
workdir_parent:
valid_volumes: ["/srv/example-pull-request"]
docker_host: ""
host:
workdir_parent:

View file

@ -1,2 +0,0 @@
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

@ -1,6 +0,0 @@
on: [push]
jobs:
test:
runs-on: docker
steps:
- run: sleep infinity

View file

@ -1,20 +0,0 @@
url=http://root:admin1234@$(cat forgejo-ip):3000
token=$(cat forgejo-token)
repo=root/example-$example
#
# push the repository
#
forgejo-test-helper.sh push_workflow testdata/example-$example $url root example-$example setup-forgejo $token
sha=$(forgejo-test-helper.sh branch_tip $url $repo main)
#
# wait for the workflow (sleep infinity) to start running
#
forgejo-test-helper.sh wait_running $url $repo $sha
#
# push to the same branch
#
forgejo-test-helper.sh push_workflow testdata/example-$example $url root example-$example setup-forgejo $token
#
# wait for the workflow to be canceld as a result of the previous push
#
forgejo-test-helper.sh wait_failure $url $repo $sha 'Has been cancelled'

View file

@ -1,4 +0,0 @@
#
# this will effectively discard any linger workflow so they do not interfere with other tests
#
forgejo-runner.sh reload

View file

@ -1,59 +0,0 @@
on: [push]
jobs:
#
# No volume involved
#
simple:
runs-on: docker
container:
image: code.forgejo.org/oci/debian:bookworm
services:
pgsql:
image: code.forgejo.org/oci/postgres:15
env:
POSTGRES_DB: test
POSTGRES_PASSWORD: postgres
steps:
- run: |
apt-get update -qq
apt-get install -y -qq postgresql-client
PGPASSWORD=postgres psql -h pgsql -U postgres -c '\dt' test
#
# A --volume option will expose the volume from the docker host to the job
#
volume-on-step:
needs: [simple]
runs-on: docker
container:
image: code.forgejo.org/oci/debian:bookworm
options: "--volume /srv/example-service-volume-valid:/srv/example-service-volume-valid --volume /srv/example-service-volume-invalid:/srv/example-service-volume-invalid"
steps:
- run: |
test -f /srv/example-service-volume-valid
! test -f /srv/example-service-volume-invalid
#
# A --volume option will expose the volume from the docker host to the service
#
volume-on-service:
needs: [volume-on-step]
runs-on: docker
container:
image: code.forgejo.org/oci/debian:bookworm
options: "--volume /srv/example-service-volume-valid:/srv/example-service-volume-valid"
services:
myservice:
image: code.forgejo.org/oci/debian:bookworm
options: "--volume /srv/example-service-volume-valid:/srv/example-service-volume-valid"
cmd: ["bash", "-c", "echo -n SUCCESS > /srv/example-service-volume-valid ; sleep infinity"]
steps:
- run: |
set -x
f=/srv/example-service-volume-valid
test -f $f
test $(cat $f) = SUCCESS

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-service-volume-valid"]
docker_host: ""
host:
workdir_parent:

View file

@ -1,3 +0,0 @@
> /srv/example-service-volume-valid
> /srv/example-service-volume-invalid
FORGEJO_RUNNER_CONFIG=$EXAMPLE_DIR/runner-config.yaml forgejo-runner.sh reload

View file

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