diff --git a/forgejo-release.sh b/forgejo-release.sh index fa101c6..acc27d1 100755 --- a/forgejo-release.sh +++ b/forgejo-release.sh @@ -23,22 +23,22 @@ export GNUPGHOME setup_tea() { if ! test -f "$BIN_DIR"/tea ; then - ARCH=$(dpkg --print-architecture) - curl -sL https://dl.gitea.io/tea/$TEA_VERSION/tea-$TEA_VERSION-linux-"$ARCH" > "$BIN_DIR"/tea - chmod +x "$BIN_DIR"/tea + ARCH=$(dpkg --print-architecture) + curl -sL https://dl.gitea.io/tea/$TEA_VERSION/tea-$TEA_VERSION-linux-"$ARCH" > "$BIN_DIR"/tea + chmod +x "$BIN_DIR"/tea fi } ensure_tag() { if api GET repos/$REPO/tags/"$TAG" > "$TMP_DIR"/tag.json ; then - local sha=$(jq --raw-output .commit.sha < "$TMP_DIR"/tag.json) - if test "$sha" != "$SHA" ; then - cat "$TMP_DIR"/tag.json - echo "the tag SHA in the $REPO repository does not match the tag SHA that triggered the build: $SHA" - false - fi + local sha=$(jq --raw-output .commit.sha < "$TMP_DIR"/tag.json) + if test "$sha" != "$SHA" ; then + cat "$TMP_DIR"/tag.json + echo "the tag SHA in the $REPO repository does not match the tag SHA that triggered the build: $SHA" + false + fi else - api POST repos/$REPO/tags --data-raw '{"tag_name": "'"$TAG"'", "target": "'"$SHA"'"}' + api POST repos/$REPO/tags --data-raw '{"tag_name": "'"$TAG"'", "target": "'"$SHA"'"}' fi } @@ -85,26 +85,26 @@ maybe_use_release_note_assistant() { sign_release() { local passphrase if test -s "$GPG_PASSPHRASE"; then - passphrase="--passphrase-file $GPG_PASSPHRASE" + passphrase="--passphrase-file $GPG_PASSPHRASE" fi gpg --import --no-tty --pinentry-mode loopback "$passphrase" "$GPG_PRIVATE_KEY" for asset in "$RELEASE_DIR"/* ; do - if [[ $asset =~ .sha256$ ]] ; then - continue - fi - gpg --armor --detach-sign --no-tty --pinentry-mode loopback "$passphrase" < "$asset" > "$asset".asc + if [[ $asset =~ .sha256$ ]] ; then + continue + fi + gpg --armor --detach-sign --no-tty --pinentry-mode loopback "$passphrase" < "$asset" > "$asset".asc done } maybe_sign_release() { if test -s "$GPG_PRIVATE_KEY"; then - sign_release + sign_release fi } maybe_override() { if test "$OVERRIDE" = "false"; then - return + return fi api DELETE repos/$REPO/releases/tags/"$TAG" >& /dev/null || true api DELETE repos/$REPO/tags/"$TAG" >& /dev/null || true @@ -122,8 +122,8 @@ upload() { setup_api() { if ! which jq curl ; then - apt-get -qq update - apt-get install -y -qq jq curl + apt-get -qq update + apt-get install -y -qq jq curl fi } @@ -139,40 +139,40 @@ api() { wait_release() { local ready=false for i in $(seq $RETRY); do - if api GET repos/$REPO/releases/tags/"$TAG" | jq --raw-output .draft > "$TMP_DIR"/draft; then - if test "$(cat "$TMP_DIR"/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 + if api GET repos/$REPO/releases/tags/"$TAG" | jq --raw-output .draft > "$TMP_DIR"/draft; then + if test "$(cat "$TMP_DIR"/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 + echo "no release for $TAG" + return 1 fi } download() { setup_api ( - mkdir -p $RELEASE_DIR - cd $RELEASE_DIR + mkdir -p $RELEASE_DIR + cd $RELEASE_DIR if [[ ${DOWNLOAD_LATEST} == "true" ]] ; then echo "Downloading the latest release" api GET repos/$REPO/releases/latest > "$TMP_DIR"/assets.json elif [[ ${DOWNLOAD_LATEST} == "false" ]] ; then wait_release echo "Downloading tagged release ${TAG}" - api GET repos/$REPO/releases/tags/"$TAG" > "$TMP_DIR"/assets.json + api GET repos/$REPO/releases/tags/"$TAG" > "$TMP_DIR"/assets.json fi - jq --raw-output '.assets[] | "\(.name) \(.browser_download_url)"' < "$TMP_DIR"/assets.json | while read name url ; do - curl --fail -H "Authorization: token $TOKEN" -o "$name" -L "$url" - done + jq --raw-output '.assets[] | "\(.name) \(.browser_download_url)"' < "$TMP_DIR"/assets.json | while read name url ; do + curl --fail -H "Authorization: token $TOKEN" -o "$name" -L "$url" + done ) }