mirror of
https://code.forgejo.org/actions/forgejo-release
synced 2024-12-22 08:33:19 +00:00
Add support for files with spaces in their names (#24)
Some checks are pending
/ integration (push) Waiting to run
Some checks are pending
/ integration (push) Waiting to run
So far when uploading files containing spaces, such as `file 3.txt`, the `tea` command will be broken due to incorrectly formatted `tea` arguments. I have been receiving `Remote repository required: Specify ID via --repo or execute from a local git repo.` which was not helpful until I turned on `verbose` and saw the whole command. This fix should resolve this issue and thereby add active support for files with spaces. Co-authored-by: Felix Kröner <felix.kroener@dynamic-biosensors.com> Reviewed-on: https://code.forgejo.org/actions/forgejo-release/pulls/24 Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org> Co-authored-by: Crown0815 <crown0815@noreply.code.forgejo.org> Co-committed-by: Crown0815 <crown0815@noreply.code.forgejo.org>
This commit is contained in:
parent
c2742f30c0
commit
4d26949b75
3 changed files with 63 additions and 56 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
*~
|
*~
|
||||||
|
.idea
|
||||||
|
|
|
@ -22,43 +22,48 @@ if ${VERBOSE:-false}; then set -x; fi
|
||||||
export GNUPGHOME
|
export GNUPGHOME
|
||||||
|
|
||||||
setup_tea() {
|
setup_tea() {
|
||||||
if ! test -f $BIN_DIR/tea ; then
|
if ! test -f "$BIN_DIR"/tea ; then
|
||||||
ARCH=$(dpkg --print-architecture)
|
ARCH=$(dpkg --print-architecture)
|
||||||
curl -sL https://dl.gitea.io/tea/$TEA_VERSION/tea-$TEA_VERSION-linux-$ARCH > $BIN_DIR/tea
|
curl -sL https://dl.gitea.io/tea/$TEA_VERSION/tea-$TEA_VERSION-linux-"$ARCH" > "$BIN_DIR"/tea
|
||||||
chmod +x $BIN_DIR/tea
|
chmod +x "$BIN_DIR"/tea
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
ensure_tag() {
|
ensure_tag() {
|
||||||
if api GET repos/$REPO/tags/$TAG > $TMP_DIR/tag.json ; then
|
if api GET repos/$REPO/tags/"$TAG" > "$TMP_DIR"/tag.json ; then
|
||||||
local sha=$(jq --raw-output .commit.sha < $TMP_DIR/tag.json)
|
local sha=$(jq --raw-output .commit.sha < "$TMP_DIR"/tag.json)
|
||||||
if test "$sha" != "$SHA" ; then
|
if test "$sha" != "$SHA" ; then
|
||||||
cat $TMP_DIR/tag.json
|
cat "$TMP_DIR"/tag.json
|
||||||
echo "the tag SHA in the $REPO repository does not match the tag SHA that triggered the build: $SHA"
|
echo "the tag SHA in the $REPO repository does not match the tag SHA that triggered the build: $SHA"
|
||||||
false
|
false
|
||||||
fi
|
fi
|
||||||
else
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
upload_release() {
|
upload_release() {
|
||||||
local assets=$(ls $RELEASE_DIR/* | sed -e 's/^/-a /')
|
# assets is defined as a list of arguments, where values may contain whitespace and need to be quoted like this -a "my file.txt" -a "file.txt".
|
||||||
|
# It is expanded using "${assets[@]}" which preserves the separation of arguments and not split whitespace containing values.
|
||||||
|
# For reference, see https://github.com/koalaman/shellcheck/wiki/SC2086#exceptions
|
||||||
|
local assets=()
|
||||||
|
for file in "$RELEASE_DIR"/*; do
|
||||||
|
assets=("${assets[@]}" -a "$file")
|
||||||
|
done
|
||||||
if $PRERELEASE || echo "${TAG}" | grep -qi '\-rc' ; then
|
if $PRERELEASE || echo "${TAG}" | grep -qi '\-rc' ; then
|
||||||
releasetype="--prerelease"
|
releaseType="--prerelease"
|
||||||
echo "Uploading as Pre-Release"
|
echo "Uploading as Pre-Release"
|
||||||
else
|
else
|
||||||
echo "Uploading as Stable"
|
echo "Uploading as Stable"
|
||||||
fi
|
fi
|
||||||
ensure_tag
|
ensure_tag
|
||||||
anchor=$(echo $TAG | sed -e 's/^v//' -e 's/[^a-zA-Z0-9]/-/g')
|
if ! "$BIN_DIR"/tea release create "${assets[@]}" --repo $REPO --note "$RELEASENOTES" --tag "$TAG" --title "$TITLE" --draft ${releaseType} >& "$TMP_DIR"/tea.log ; then
|
||||||
if ! $BIN_DIR/tea release create $assets --repo $REPO --note "$RELEASENOTES" --tag $TAG --title "$TITLE" --draft ${releasetype} >& $TMP_DIR/tea.log ; then
|
if grep --quiet 'Unknown API Error: 500' "$TMP_DIR"/tea.log && grep --quiet services/release/release.go:194 "$TMP_DIR"/tea.log ; then
|
||||||
if grep --quiet 'Unknown API Error: 500' $TMP_DIR/tea.log && grep --quiet services/release/release.go:194 $TMP_DIR/tea.log ; then
|
|
||||||
echo "workaround v1.20 race condition https://codeberg.org/forgejo/forgejo/issues/1370"
|
echo "workaround v1.20 race condition https://codeberg.org/forgejo/forgejo/issues/1370"
|
||||||
sleep 10
|
sleep 10
|
||||||
$BIN_DIR/tea release create $assets --repo $REPO --note "$RELEASENOTES" --tag $TAG --title "$TITLE" --draft ${releasetype}
|
"$BIN_DIR"/tea release create "${assets[@]}" --repo $REPO --note "$RELEASENOTES" --tag "$TAG" --title "$TITLE" --draft ${releaseType}
|
||||||
else
|
else
|
||||||
cat $TMP_DIR/tea.log
|
cat "$TMP_DIR"/tea.log
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -69,16 +74,16 @@ upload_release() {
|
||||||
release_draft() {
|
release_draft() {
|
||||||
local state="$1"
|
local state="$1"
|
||||||
|
|
||||||
local id=$(api GET repos/$REPO/releases/tags/$TAG | jq --raw-output .id)
|
local id=$(api GET repos/$REPO/releases/tags/"$TAG" | jq --raw-output .id)
|
||||||
|
|
||||||
api PATCH repos/$REPO/releases/$id --data-raw '{"draft": '$state', "hide_archive_links": '$HIDE_ARCHIVE_LINK'}'
|
api PATCH repos/$REPO/releases/"$id" --data-raw '{"draft": '"$state"', "hide_archive_links": '$HIDE_ARCHIVE_LINK'}'
|
||||||
}
|
}
|
||||||
|
|
||||||
maybe_use_release_note_assistant() {
|
maybe_use_release_note_assistant() {
|
||||||
if "$RELEASE_NOTES_ASSISTANT"; then
|
if "$RELEASE_NOTES_ASSISTANT"; then
|
||||||
curl --fail -s -S -o rna https://code.forgejo.org/forgejo/release-notes-assistant/releases/download/v1.2.3/release-notes-assistant
|
curl --fail -s -S -o rna https://code.forgejo.org/forgejo/release-notes-assistant/releases/download/v1.2.3/release-notes-assistant
|
||||||
chmod +x ./rna
|
chmod +x ./rna
|
||||||
./rna --storage release --storage-location $TAG --forgejo-url $SCHEME://placeholder:$TOKEN@$HOST --repository $REPO --token $TOKEN release $TAG
|
./rna --storage release --storage-location "$TAG" --forgejo-url "$SCHEME"://placeholder:"$TOKEN"@"$HOST" --repository $REPO --token "$TOKEN" release "$TAG"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,11 +93,11 @@ sign_release() {
|
||||||
passphrase="--passphrase-file $GPG_PASSPHRASE"
|
passphrase="--passphrase-file $GPG_PASSPHRASE"
|
||||||
fi
|
fi
|
||||||
gpg --import --no-tty --pinentry-mode loopback $passphrase "$GPG_PRIVATE_KEY"
|
gpg --import --no-tty --pinentry-mode loopback $passphrase "$GPG_PRIVATE_KEY"
|
||||||
for asset in $RELEASE_DIR/* ; do
|
for asset in "$RELEASE_DIR"/* ; do
|
||||||
if [[ $asset =~ .sha256$ ]] ; then
|
if [[ $asset =~ .sha256$ ]] ; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
gpg --armor --detach-sign --no-tty --pinentry-mode loopback $passphrase < $asset > $asset.asc
|
gpg --armor --detach-sign --no-tty --pinentry-mode loopback $passphrase < "$asset" > "$asset".asc
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,15 +111,15 @@ maybe_override() {
|
||||||
if test "$OVERRIDE" = "false"; then
|
if test "$OVERRIDE" = "false"; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
api DELETE repos/$REPO/releases/tags/$TAG >& /dev/null || true
|
api DELETE repos/$REPO/releases/tags/"$TAG" >& /dev/null || true
|
||||||
api DELETE repos/$REPO/tags/$TAG >& /dev/null || true
|
api DELETE repos/$REPO/tags/"$TAG" >& /dev/null || true
|
||||||
}
|
}
|
||||||
|
|
||||||
upload() {
|
upload() {
|
||||||
setup_api
|
setup_api
|
||||||
setup_tea
|
setup_tea
|
||||||
rm -f ~/.config/tea/config.yml
|
rm -f ~/.config/tea/config.yml
|
||||||
GITEA_SERVER_TOKEN=$TOKEN $BIN_DIR/tea login add --url $FORGEJO
|
GITEA_SERVER_TOKEN=$TOKEN "$BIN_DIR"/tea login add --url $FORGEJO
|
||||||
maybe_sign_release
|
maybe_sign_release
|
||||||
maybe_override
|
maybe_override
|
||||||
upload_release
|
upload_release
|
||||||
|
@ -133,14 +138,14 @@ api() {
|
||||||
path=$1
|
path=$1
|
||||||
shift
|
shift
|
||||||
|
|
||||||
curl --fail -X $method -sS -H "Content-Type: application/json" -H "Authorization: token $TOKEN" "$@" $FORGEJO/api/v1/$path
|
curl --fail -X "$method" -sS -H "Content-Type: application/json" -H "Authorization: token $TOKEN" "$@" $FORGEJO/api/v1/"$path"
|
||||||
}
|
}
|
||||||
|
|
||||||
wait_release() {
|
wait_release() {
|
||||||
local ready=false
|
local ready=false
|
||||||
for i in $(seq $RETRY); do
|
for i in $(seq $RETRY); do
|
||||||
if api GET repos/$REPO/releases/tags/$TAG | jq --raw-output .draft > $TMP_DIR/draft; then
|
if api GET repos/$REPO/releases/tags/"$TAG" | jq --raw-output .draft > "$TMP_DIR"/draft; then
|
||||||
if test "$(cat $TMP_DIR/draft)" = "false"; then
|
if test "$(cat "$TMP_DIR"/draft)" = "false"; then
|
||||||
ready=true
|
ready=true
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
@ -164,14 +169,14 @@ download() {
|
||||||
cd $RELEASE_DIR
|
cd $RELEASE_DIR
|
||||||
if [[ ${DOWNLOAD_LATEST} == "true" ]] ; then
|
if [[ ${DOWNLOAD_LATEST} == "true" ]] ; then
|
||||||
echo "Downloading the latest release"
|
echo "Downloading the latest release"
|
||||||
api GET repos/$REPO/releases/latest > $TMP_DIR/assets.json
|
api GET repos/$REPO/releases/latest > "$TMP_DIR"/assets.json
|
||||||
elif [[ ${DOWNLOAD_LATEST} == "false" ]] ; then
|
elif [[ ${DOWNLOAD_LATEST} == "false" ]] ; then
|
||||||
wait_release
|
wait_release
|
||||||
echo "Downloading tagged release ${TAG}"
|
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
|
fi
|
||||||
jq --raw-output '.assets[] | "\(.name) \(.browser_download_url)"' < $TMP_DIR/assets.json | while read name url ; do
|
jq --raw-output '.assets[] | "\(.browser_download_url) \(.name)"' < "$TMP_DIR"/assets.json | while read url name ; do # `name` may contain whitespace, therefore, it must be last
|
||||||
curl --fail -H "Authorization: token $TOKEN" -o $name -L $url
|
curl --fail -H "Authorization: token $TOKEN" -o "$name" -L "$url"
|
||||||
done
|
done
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
1
testdata/upload-download/upload-dir/file 3.txt
vendored
Normal file
1
testdata/upload-download/upload-dir/file 3.txt
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
FILE3
|
Loading…
Reference in a new issue