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:
earl-warren 2023-09-29 22:38:18 +00:00
commit c2b00566d0
13 changed files with 82 additions and 17 deletions

View file

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

View file

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

View file

@ -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() {

View file

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

View 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

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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