Skip to content

Commit

Permalink
Merge pull request #57 from Flow-IPC/polish
Browse files Browse the repository at this point in the history
upload-release-asset action refuses to work ("Invalid name for request") no matter what experimental simplification I use, so instead using curl to explicitly make the upload POST. It worked experimentally, so now doing it for real. The code is actually shorter.
  • Loading branch information
ygoldfeld authored Jan 19, 2024
2 parents 9eaa458 + b464341 commit f225606
Showing 1 changed file with 34 additions and 33 deletions.
67 changes: 34 additions & 33 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ jobs:
git config user.email [email protected]
# We are forced to use a Personal Access Token attached to a special bot user such that in repo Settings
# we've configured that "guy" as allowed to bypass the requirement to merge via PR. As of this writing
# there's no way to configure the default token to being able to do this.
# there's no way to configure the default token to be able to do this.
# TODO: Keep an eye on that in case they provide for a better way:
# https://github.com/orgs/community/discussions/25305
git config --local http.https://github.com/.extraheader \
Expand All @@ -1103,21 +1103,40 @@ jobs:
# We want a source tarball and/or zip to be attached to the Release. Delightfully, GitHub does this
# automatically. Less delightfully, we have submodules -- where most of the code is in fact -- which GitHub
# will not include (they'll just be empty dirs instead). So we upload those manually.
- name: (On release creation only) Prepare full source package(s) to attach to Release page
id: prep_release_pkgs
#
# Regarding the actual upload request (x2): We do it via curl, following the documented GitHub API.
# Some resources recommend doing this (x2) instead:
# uses: actions/[email protected]
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ steps.prep_release_pkgs.outputs.upload-url }}
# asset_path: ${{ github.workspace }}/../${{ steps.prep_release_pkgs.outputs.tgz-name }}
# asset_name: ${{ steps.prep_release_pkgs.outputs.tgz-name }}
# asset_content_type: application/gzip
# For me (ygoldfel), despite a few hours of trying this and that and attempting to get debug output, it kept
# yielding `Invalid name for request` error with no added info. Reasons might be: some silly error on my part
# (but it is very vanilla, and I reduced it down to the bare essentials with no success, while also eliminating
# possibilities like it being unable to find the local file to upload and other stupidities); a change in API
# or some other behavior that was not handled by the upload-release-asset action package; possibly a break
# in a dependency of upload-release-asset (octokat?). upload-release-asset was last updated in 2020 and is
# officially now unmaintained. So I fought valiantly but eventually moved onto just using curl which worked
# almost immediately. Since the resulting code isn't even longer, and we are using a documented public API and
# standard tool (curl) which we also use elsewhere, it seemed a reasonable approach. TODO: Revisit perhaps.
- name: (On release creation only) Attach full source package(s) to Release
if: success() && (!cancelled()) && startsWith(github.ref, 'refs/tags/v')
run: |
# Prepare full source package(s) to attach to Release page.
# Attach full source package(s) to Release
cd ${{ github.workspace }}/..
REPO=ipc
VERSION=`echo ${{ github.ref }} | cut -c 12-` # E.g., refs/tags/v1.2.3-rc1 => 1.2.3-rc1.
TGZ_NAME=$REPO-${VERSION}_full.tar.gz
ZIP_NAME=$REPO-${VERSION}_full.zip
# When making archives: get rid of or exclude (I do not want to `rm` .git... feels dangerous
# against GitHub Actions):
# When making archives: get rid of or exclude (I do not want to `rm -rf` .git... feels dangerous-ish, as
# GitHub Actions cleans up checkouts later... just don't do it) the following:
# - .git directories and files. (.gitignore and .gitmodules, among others, must stay.)
# (tar --exclude-vcs sounds delightful, but it'll exclude .gitignore and .gitmodules at least.)
# - Any tarball created earlier upon doc generation.
# - Any doc tarball created earlier upon doc generation.
rm -f $REPO/doc/$REPO_doc.tgz
tar cvzf $TGZ_NAME --exclude=.git $REPO
zip -r $ZIP_NAME $REPO --exclude '*/.git/*' '*/.git'
Expand All @@ -1130,32 +1149,14 @@ jobs:
echo "For release [v$VERSION]: release-data API request yielded: [$RELEASE_DATA]."
UPLOAD_URL=`echo $RELEASE_DATA | jq -r .upload_url | sed 's/{.*}$//'`
echo "For release [v$VERSION]: upload-URL was computed to be: [$UPLOAD_URL]."
echo "upload-url=$UPLOAD_URL" >> $GITHUB_OUTPUT
echo "tgz-name=$TGZ_NAME" >> $GITHUB_OUTPUT
echo "zip-name=$ZIP_NAME" >> $GITHUB_OUTPUT
echo 'description=Source code (full)' >> $GITHUB_OUTPUT
- name: (On release creation only) Attach full source package (tarball) to Release page
if: (!cancelled()) && (steps.prep_release_pkgs.outcome == 'success')
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.prep_release_pkgs.outputs.upload-url }}
asset_path: ${{ github.workspace }}/../${{ steps.prep_release_pkgs.outputs.tgz-name }}
asset_name: ${{ steps.prep_release_pkgs.outputs.description }}
asset_content_type: application/gzip

- name: (On release creation only) Attach full source package (zip) to Release page
if: (!cancelled()) && (steps.prep_release_pkgs.outcome == 'success')
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.prep_release_pkgs.outputs.upload-url }}
asset_path: ${{ github.workspace }}/../${{ steps.prep_release_pkgs.outputs.zip-name }}
asset_name: ${{ steps.prep_release_pkgs.outputs.description }}
asset_content_type: application/zip
curl --fail-with-body -X POST \
-H 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' \
-H 'Content-Type: application/gzip' -H "Content-Length: $(wc -c < $TGZ_NAME)" \
--data-binary @$TGZ_NAME "$UPLOAD_URL?name=$TGZ_NAME"
curl --fail-with-body -X POST \
-H 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' \
-H 'Content-Type: application/zip' -H "Content-Length: $(wc -c < $ZIP_NAME)" \
--data-binary @$ZIP_NAME "$UPLOAD_URL?name=$ZIP_NAME"
- name: (On release creation only) Signal Pages about release (web site should update)
if: success() && (!cancelled()) && startsWith(github.ref, 'refs/tags/v')
Expand Down

0 comments on commit f225606

Please sign in to comment.