From 358b55efd45c425fd55f4f3e15fb3f0a484df97e Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 24 May 2023 01:01:51 +0200 Subject: [PATCH] wait for a release to no longer be draft before downloading --- README.md | 3 +++ action.yml | 4 ++++ forgejo-release.sh | 24 ++++++++++++++++++++++++ testdata/forgejo-release-test.sh | 13 +++++++++++++ 4 files changed, 44 insertions(+) diff --git a/README.md b/README.md index 57472ee..6123b7b 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,9 @@ Upload or download the assets of a release to a Forgejo instance. | release-dir | Directory in whichs release assets are uploaded or downloaded | `true` | | | release-notes | Release notes | `false` | | | direction | Can either be download or upload | `true` | | +| gpg-private-key | GPG Private Key to sign the release artifacts | `false` | | +| gpg-passphrase | Passphrase of the GPG Private Key | `false` | | +| download-retry | Number of times to retry if the release is not ready (default 1) | `false` | | | verbose | Increase the verbosity level | `false` | false | diff --git a/action.yml b/action.yml index 00714f7..b3ba962 100644 --- a/action.yml +++ b/action.yml @@ -27,6 +27,8 @@ inputs: description: 'GPG Private Key to sign the release artifacts' gpg-passphrase: description: 'Passphrase of the GPG Private Key' + download-retry: + description: 'Number of times to retry if the release is not ready (default 1)' verbose: description: 'Increase the verbosity level' default: 'false' @@ -71,5 +73,7 @@ runs: export VERBOSE="${{ inputs.verbose }}" + export RETRY="${{ inputs.download-retry }}" + forgejo-release.sh ${{ inputs.direction }} shell: bash diff --git a/forgejo-release.sh b/forgejo-release.sh index ceb002e..75a0461 100755 --- a/forgejo-release.sh +++ b/forgejo-release.sh @@ -10,6 +10,8 @@ if ${VERBOSE:-false}; then set -x; fi : ${RELEASE_DIR:=dist/release} : ${BIN_DIR:=$(mktemp -d)} : ${TEA_VERSION:=0.9.0} +: ${RETRY:=1} +: ${DELAY:=10} setup_tea() { if ! test -f $BIN_DIR/tea ; then @@ -72,8 +74,30 @@ api() { curl --fail -X $method -sS -H "Content-Type: application/json" -H "Authorization: token $TOKEN" "$@" $FORGEJO/api/v1/$path } +wait_release() { + local ready=false + for i in $(seq $RETRY); do + if api GET repos/$REPO/releases/tags/$TAG | jq --raw-output .draft > /tmp/draft; then + if test "$(cat /tmp/draft)" = "false"; then + ready=true + break + fi + echo "release $TAG is still a draft" + else + echo "release $TAG does not exist yet" + fi + echo "waiting $DELAY seconds" + sleep $DELAY + done + if ! $ready ; then + echo "no release for $TAG" + return 1 + fi +} + download() { setup_api + wait_release ( mkdir -p $RELEASE_DIR cd $RELEASE_DIR diff --git a/testdata/forgejo-release-test.sh b/testdata/forgejo-release-test.sh index 946dfa0..9160da4 100755 --- a/testdata/forgejo-release-test.sh +++ b/testdata/forgejo-release-test.sh @@ -32,6 +32,16 @@ test_setup() { touch $RELEASE_DIR/file-two.txt } +test_wait_release_fail() { + ! wait_release +} + +test_wait_release() { + wait_release + release_draft true + ! wait_release +} + test_ensure_tag() { api DELETE repos/$REPO/tags/$TAG || true # @@ -62,12 +72,15 @@ test_run() { REPO=$user/$project test_setup $project test_ensure_tag + DELAY=0 + test_wait_release_fail echo "================================ TEST BEGIN" upload RELEASE_DIR=$pulled download diff -r $to_push $pulled echo "================================ TEST END" + test_wait_release } : ${TAG:=v17.8.20-1}