Support downloading the latest release of a repo (#16)

This PR adds the functionality to download the latest release from a repo. The API provides an endpoint to do so, so an option has been added to the action.

This closes #12

Co-authored-by: benniekiss <bgmt@mail.bbalm.me>
Reviewed-on: https://code.forgejo.org/actions/forgejo-release/pulls/16
Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org>
Co-authored-by: benniekiss <benniekiss@noreply.code.forgejo.org>
Co-committed-by: benniekiss <benniekiss@noreply.code.forgejo.org>
This commit is contained in:
benniekiss 2024-07-08 18:49:13 +00:00 committed by earl-warren
parent de47e391d3
commit a5aa633273
9 changed files with 101 additions and 24 deletions

View file

@ -8,6 +8,7 @@ if ${VERBOSE:-false}; then set -x; fi
: ${FORGEJO:=https://codeberg.org}
: ${REPO:=forgejo-integration/forgejo}
: ${RELEASE_DIR:=dist/release}
: ${DOWNLOAD_LATEST:=false}
: ${TMP_DIR:=$(mktemp -d)}
: ${GNUPGHOME:=$TMP_DIR}
: ${BIN_DIR:=$TMP_DIR}
@ -143,18 +144,23 @@ wait_release() {
download() {
setup_api
wait_release
(
mkdir -p $RELEASE_DIR
cd $RELEASE_DIR
api GET repos/$REPO/releases/tags/$TAG > $TMP_DIR/assets.json
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
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
)
}
missing() {
echo need upload or download argument got nothing
exit 1