From b4643415b71d6ace1c397b4fdb4387bb49a8fc44 Mon Sep 17 00:00:00 2001 From: Yuri Goldfeld Date: Thu, 18 Jan 2024 17:22:04 -0800 Subject: [PATCH] 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. --- .github/workflows/main.yml | 122 +++++++++++-------------------------- 1 file changed, 35 insertions(+), 87 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f9d628c8f..666e62868 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -69,9 +69,8 @@ jobs: build: needs: [setup, set-vars] - # XXX if: | - needs.setup.outputs.proceed-else-not == 'true' && false + needs.setup.outputs.proceed-else-not == 'true' strategy: fail-fast: false @@ -1014,60 +1013,8 @@ jobs: with: submodules: true - - - - # XXX - - - - name: (On release creation only) Prepare full source package(s) to attach to Release - id: prep_release_pkgsXXX - if: success() - # XXX && (!cancelled()) && startsWith(github.ref, 'refs/tags/v') - run: | - # Prepare full source package(s) to attach to Release. - cd ${{ github.workspace }}/.. - REPO=ipc - # XXX VERSION=`echo ${{ github.ref }} | cut -c 12-` # E.g., refs/tags/v1.2.3-rc1 => 1.2.3-rc1. - VERSION=1.0.0-rc4 - 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): - # - .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. - #rm -f $REPO/doc/$REPO_doc.tgz - tar cvzf $TGZ_NAME --exclude=.git $REPO - # XXX zip -r $ZIP_NAME $REPO --exclude '*/.git/*' '*/.git' - # Soon we will need the upload URL, but unfortunately github.event.release.upload_url is only auto-populated - # on `release` trigger; whereas we want to be triggerable manually on `push` to tag v* (so a superset - # of `release` trigger). So we must figure it out via API call. - RELEASE_DATA=`curl -H 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' \ - -H 'Accept: application/vnd.github.v3+json' \ - https://api.github.com/repos/Flow-IPC/$REPO/releases/tags/v$VERSION` - 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%20code%20(full)' >> $GITHUB_OUTPUT - - - name: Manually upload asset using curl 1 - if: (!cancelled()) && (steps.prep_release_pkgsXXX.outcome == 'success') - run: | - cd ${{ github.workspace }}/.. - FILE=${{ steps.prep_release_pkgsXXX.outputs.tgz-name }} - curl -X POST \ - -H 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' \ - -H 'Content-Type: application/gzip' \ - -H "Content-Length: $(wc -c < $FILE)" \ - --data-binary @$FILE \ - '${{ steps.prep_release_pkgsXXX.outputs.upload-url }}?name=${{ steps.prep_release_pkgsXXX.outputs.description }}' - - name: Install Flow-IPC dependencies (like Graphviz) with apt-get - run: sudo apt-get install -y graphviz && false # XXX + run: sudo apt-get install -y graphviz - name: Install the latest version of Conan which is less than 2 run: pip install 'conan<2' @@ -1156,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 - 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/upload-release-asset@v1.0.2 + # 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. + # 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' @@ -1183,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 - 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 - 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')