Add support for files with spaces in their names #24
No reviewers
Labels
No milestone
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
actions/forgejo-release!24
Loading…
Reference in a new issue
No description provided.
Delete branch ":main"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
So far when uploading files containing spaces, such as
file 3.txt, theteacommand will be broken due to incorrectly formattedteaarguments.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 onverboseand saw the whole command.This fix should resolve this issue and thereby add active support for files with spaces.
It would be nice to fix this bug. Could you please resolve the conflict?
b10940c29f7a1ac7c579The relevant error is at https://code.forgejo.org/actions/forgejo-release/actions/runs/430/jobs/0#jobstep-4-1284
Look for
Failure - Mainto find it. The logs are enormous.@earl-warren I think I found the issue. I went ahead and resolved even more potential issues due to spaces in file or directory names by resolving all SC2086 warnings.
@earl-warren it appears that the
teacli has a problem with the-a "upload-dir/file 3.txt"option:I am not sure what the issue is. In the log there is this line which seems to indicate a
'being inserted into the command. But I do not see what in the code would cause a'to appear.The error is then reported here:
@ -55,2 +54,2 @@if ! $BIN_DIR/tea release create $assets --repo $REPO --note "$RELEASENOTES" --tag $TAG --title "$TITLE" --draft ${releasetype} >& $TMP_DIR/tea.log ; thenif grep --quiet 'Unknown API Error: 500' $TMP_DIR/tea.log && grep --quiet services/release/release.go:194 $TMP_DIR/tea.log ; thenanchor=$(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 ; thenI think you have an evaluation problem here. "$assset" will be a single argument.
You want "$assets" to not be a single argument but multiple arguments. I suggest creating a temporary script otherwise properly quoting and evaluating will be either difficult or obscure.
and then
bash uploader. This way the quoted file names $assets will be properly evaluated.I resolved the issue by creating an array for the assets. It is the recommended solution for SC2086, under the given circumstances
1f5768043f615f72e7fa@earl-warren the issue I have now is that the download still assumes a file name without space here:
The issue is likely the
"\(.name) \(.browser_download_url)"pattern, but I am not sure what this means.jqis json query?Try this instead:
name being the last argument will get everything after the URLs, space and all.
https://en.wikipedia.org/wiki/Jq_(programming_language)
That is a pretty good idea. Did the trick
@ -44,3 +44,3 @@upload_release() {local assets=$(ls $RELEASE_DIR/* | sed -e 's/^/-a /')local assets=()It is an unusual construct but clever. Someone reading the script will no doubt wonder why it is not just a string. Could you add a comment above to explain why it is justified?
What about adding something like this as well?
I'm sure I will have forgotten this trick in a month 😁
Do you prefer a more detailed description over the reference to the original source?
Just want to make sure you saw the change I already put in.
Yes, I would favor a detailed description that clarify how it is relevant in this context in addition to the link to the source. Otherwise my future self will have a more difficult time remembering the rationale 🙏
@ -55,2 +57,2 @@if ! $BIN_DIR/tea release create $assets --repo $REPO --note "$RELEASENOTES" --tag $TAG --title "$TITLE" --draft ${releasetype} >& $TMP_DIR/tea.log ; thenif grep --quiet 'Unknown API Error: 500' $TMP_DIR/tea.log && grep --quiet services/release/release.go:194 $TMP_DIR/tea.log ; thenanchor=$(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 ; thenClever bashism 👍
It is actually the proposed solution for SC2086, so all credit goes to the author of the SC2086 wiki page ;-)
@ -173,3 +175,1 @@jq --raw-output '.assets[] | "\(.name) \(.browser_download_url)"' < $TMP_DIR/assets.json | while read name url ; docurl --fail -H "Authorization: token $TOKEN" -o $name -L $urldonejq --raw-output '.assets[] | "\(.browser_download_url) \(.name)"' < "$TMP_DIR"/assets.json | while read url name ; doI would add a warning:
nameis read out last from assets.json 4308ed0075assetsis constructed as an array 36620ac8b8adaad4b7533942f4a9a9@earl-warren, all done