mirror of
https://code.forgejo.org/actions/setup-forgejo.git
synced 2024-12-26 06:42:17 -05:00
Merge pull request 'add example of artifact usage' (#51) from earl-warren/setup-forgejo:wip-artifacts into main
Reviewed-on: https://code.forgejo.org/actions/setup-forgejo/pulls/51 Reviewed-by: dachary <dachary@noreply.code.forgejo.org>
This commit is contained in:
commit
c2b00566d0
13 changed files with 82 additions and 17 deletions
|
@ -8,13 +8,23 @@ jobs:
|
|||
info:
|
||||
- version: "1.21.0-1-rc0"
|
||||
image: codeberg.org/forgejo-experimental/forgejo
|
||||
tests: "echo cron pull-request service container expression local-action docker-action if if-fail"
|
||||
tests: "service"
|
||||
- version: "1.21.0-1-rc0"
|
||||
image: codeberg.org/forgejo-experimental/forgejo
|
||||
tests: "artifacts"
|
||||
- version: "1.21.0-1-rc0"
|
||||
image: codeberg.org/forgejo-experimental/forgejo
|
||||
tests: "cron"
|
||||
- version: "1.21.0-1-rc0"
|
||||
image: codeberg.org/forgejo-experimental/forgejo
|
||||
tests: "${{ vars.V121_TESTS || 'echo pull-request container expression local-action docker-action if if-fail' }}"
|
||||
- version: "1.20"
|
||||
image: codeberg.org/forgejo/forgejo
|
||||
tests: "echo service container expression local-action docker-action if if-fail"
|
||||
tests: "${{ vars.V120_TESTS || 'echo service container expression local-action docker-action if if-fail' }}"
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- run: |
|
||||
- if: matrix.info.tests != 'none'
|
||||
run: |
|
||||
set -x
|
||||
LXC_IP_PREFIX=10.0.10 ./forgejo-dependencies.sh
|
||||
export PATH=$(pwd):$PATH
|
||||
|
|
|
@ -102,6 +102,7 @@ because the tests run as root, but they do not need to run as root.
|
|||
* `export example=pull-request`
|
||||
* `export EXAMPLE_DIR=$(pwd)/testdata/example-$example`
|
||||
* `$EXAMPLE_DIR/setup.sh` # if it exists
|
||||
* `$EXAMPLE_DIR/run.sh`
|
||||
* `$EXAMPLE_DIR/run.sh` or
|
||||
* `forgejo-test-helper.sh run_workflow testdata/example-$example http://root:admin1234@$(cat forgejo-ip):3000 root example-$example setup-forgejo $(cat forgejo-token)`
|
||||
* `forgejo-runner.sh teardown`
|
||||
* `forgejo.sh teardown`
|
||||
|
|
|
@ -24,7 +24,7 @@ function download() {
|
|||
function register() {
|
||||
local forgejo="$1"
|
||||
docker exec --user 1000 forgejo forgejo actions generate-runner-token > forgejo-runner-token
|
||||
timeout --signal=KILL 30 forgejo-runner register --no-interactive --instance "$forgejo" --name runner --token $(cat forgejo-runner-token) --labels docker:docker://node:16-bullseye,ubuntu-latest:docker://node:16-buster,self-hosted
|
||||
timeout --signal=KILL 30 forgejo-runner register --no-interactive --instance "$forgejo" --name runner --token $(cat forgejo-runner-token) --labels docker:docker://code.forgejo.org/oci/node:16-bullseye,ubuntu-latest:docker://code.forgejo.org/oci/node:16-buster,self-hosted
|
||||
}
|
||||
|
||||
function run() {
|
||||
|
|
|
@ -44,12 +44,20 @@ function build_runner() {
|
|||
forgejo-runner --version
|
||||
}
|
||||
|
||||
function get_status() {
|
||||
local url="$1"
|
||||
local repo="$2"
|
||||
local sha="$3"
|
||||
|
||||
forgejo-curl.sh api_json $url/api/v1/repos/$repo/commits/$sha/status
|
||||
}
|
||||
|
||||
function check_status() {
|
||||
local url="$1"
|
||||
local repo="$2"
|
||||
local sha="$3"
|
||||
|
||||
local state=$(forgejo-curl.sh api_json $url/api/v1/repos/$repo/commits/$sha/status | jq --raw-output .state)
|
||||
local state=$(get_status $url $repo $sha | jq --raw-output .state)
|
||||
echo $state
|
||||
test "$state" != "" -a "$state" != "pending" -a "$state" != "running" -a "$state" != "null"
|
||||
}
|
||||
|
@ -67,8 +75,8 @@ function wait_success() {
|
|||
sleep $LOOP_DELAY
|
||||
done
|
||||
if ! test "$(check_status "$url" "$repo" "$sha")" = "success" ; then
|
||||
get_status $url $repo $sha | jq .statuses
|
||||
test "$FORGEJO_RUNNER_LOGS" && cat $FORGEJO_RUNNER_LOGS
|
||||
forgejo-curl.sh api_json $url/api/v1/repos/$repo/commits/$sha/status | jq .
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
|
22
testdata/example-artifacts/.forgejo/workflows/many.yml
vendored
Normal file
22
testdata/example-artifacts/.forgejo/workflows/many.yml
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
on: [push]
|
||||
jobs:
|
||||
upload:
|
||||
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:
|
||||
runs-on: docker
|
||||
steps:
|
||||
- uses: actions/download-artifact@v3
|
||||
|
||||
- run: |
|
||||
test -f many-artifacts/ONE
|
||||
test -f many-artifacts/TWO
|
24
testdata/example-artifacts/.forgejo/workflows/one.yml
vendored
Normal file
24
testdata/example-artifacts/.forgejo/workflows/one.yml
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
on: [push]
|
||||
jobs:
|
||||
upload:
|
||||
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:
|
||||
runs-on: docker
|
||||
steps:
|
||||
- run: "! test -f world.txt"
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: my-artifact
|
||||
|
||||
- run: "test -f world.txt"
|
|
@ -6,7 +6,7 @@ jobs:
|
|||
test:
|
||||
runs-on: docker
|
||||
container:
|
||||
image: debian:bookworm
|
||||
image: code.forgejo.org/oci/debian:bookworm
|
||||
options: "--volume /srv/example-cron-volume:/srv/example-cron-volume"
|
||||
|
||||
steps:
|
||||
|
|
2
testdata/example-cron/runner-config.yaml
vendored
2
testdata/example-cron/runner-config.yaml
vendored
|
@ -10,7 +10,7 @@ runner:
|
|||
insecure: false
|
||||
fetch_timeout: 5s
|
||||
fetch_interval: 2s
|
||||
labels: []
|
||||
labels: ["docker:docker://code.forgejo.org/oci/node:16-bullseye"]
|
||||
|
||||
cache:
|
||||
enabled: false
|
||||
|
|
|
@ -9,7 +9,7 @@ jobs:
|
|||
test:
|
||||
runs-on: docker
|
||||
container:
|
||||
image: debian:bookworm
|
||||
image: code.forgejo.org/oci/debian:bookworm
|
||||
options: "--volume /srv/example-pull-request:/srv/example-pull-request"
|
||||
|
||||
steps:
|
||||
|
|
|
@ -10,7 +10,7 @@ runner:
|
|||
insecure: false
|
||||
fetch_timeout: 5s
|
||||
fetch_interval: 2s
|
||||
labels: []
|
||||
labels: ["docker:docker://code.forgejo.org/oci/node:16-bullseye"]
|
||||
|
||||
cache:
|
||||
enabled: false
|
||||
|
|
|
@ -4,11 +4,11 @@ jobs:
|
|||
test:
|
||||
runs-on: docker
|
||||
container:
|
||||
image: debian:bookworm
|
||||
image: code.forgejo.org/oci/debian:bookworm
|
||||
|
||||
services:
|
||||
pgsql:
|
||||
image: postgres:15
|
||||
image: code.forgejo.org/oci/postgres:15
|
||||
env:
|
||||
POSTGRES_DB: test
|
||||
POSTGRES_PASSWORD: postgres
|
||||
|
|
|
@ -7,7 +7,7 @@ jobs:
|
|||
volume-on-step:
|
||||
runs-on: docker
|
||||
container:
|
||||
image: debian:bookworm
|
||||
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:
|
||||
|
@ -21,12 +21,12 @@ jobs:
|
|||
volume-on-service:
|
||||
runs-on: docker
|
||||
container:
|
||||
image: debian:bookworm
|
||||
image: code.forgejo.org/oci/debian:bookworm
|
||||
options: "--volume /srv/example-service-volume-valid:/srv/example-service-volume-valid"
|
||||
|
||||
services:
|
||||
myservice:
|
||||
image: debian:bookworm
|
||||
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"]
|
||||
|
||||
|
|
2
testdata/example-service/runner-config.yaml
vendored
2
testdata/example-service/runner-config.yaml
vendored
|
@ -10,7 +10,7 @@ runner:
|
|||
insecure: false
|
||||
fetch_timeout: 5s
|
||||
fetch_interval: 2s
|
||||
labels: []
|
||||
labels: ["docker:docker://code.forgejo.org/oci/node:16-bullseye"]
|
||||
|
||||
cache:
|
||||
enabled: false
|
||||
|
|
Loading…
Reference in a new issue