From 96418bb554cb1ee8fcbbe9383a11c50fa718f45b Mon Sep 17 00:00:00 2001 From: Patrick Stevens <3138005+Smaug123@users.noreply.github.com> Date: Mon, 13 Jan 2025 09:50:09 +0000 Subject: [PATCH] Use GR's release action (#71) --- .github/workflows/dotnet.yaml | 48 ++++++++++---- .github/workflows/tag.sh | 120 ---------------------------------- 2 files changed, 36 insertions(+), 132 deletions(-) delete mode 100644 .github/workflows/tag.sh diff --git a/.github/workflows/dotnet.yaml b/.github/workflows/dotnet.yaml index 5479b58..4742c59 100644 --- a/.github/workflows/dotnet.yaml +++ b/.github/workflows/dotnet.yaml @@ -163,24 +163,36 @@ jobs: # Verify that there is exactly one nupkg in the artifact that would be NuGet published run: if [[ $(find . -maxdepth 1 -name 'WoofWare.PrattParser.*.nupkg' -printf c | wc -c) -ne "1" ]]; then exit 1; fi - github-release-plugin-dry-run: - needs: [nuget-pack] + github-release-dry-run: runs-on: ubuntu-latest + needs: [nuget-pack] steps: - uses: actions/checkout@v4 - - name: Download NuGet artifact (plugin) + - name: Download NuGet artifact uses: actions/download-artifact@v4 with: name: nuget-package - - name: Tag and release + - name: Compute package path + id: compute-path + run: | + find . -maxdepth 1 -type f -name 'WoofWare.PrattParser.*.nupkg' -exec sh -c 'echo "output=$(basename "$1")" >> $GITHUB_OUTPUT' shell {} \; + - name: Compute tag name + id: compute-tag env: - DRY_RUN: 1 - GITHUB_TOKEN: mock-token - run: sh .github/workflows/tag.sh + NUPKG_PATH: ${{ steps.compute-path.outputs.output }} + run: echo "output=$(basename "$NUPKG_PATH" .nupkg)" >> $GITHUB_OUTPUT + - name: Tag and release + uses: G-Research/common-actions/github-release@19d7281a0f9f83e13c78f99a610dbc80fc59ba3b + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + target-commitish: ${{ github.sha }} + tag: ${{ steps.compute-tag.outputs.output }} + binary-contents: ${{ steps.compute-path.outputs.output }} + dry-run: true all-required-checks-complete: if: ${{ always() }} - needs: [check-dotnet-format, check-nix-format, build, build-nix, linkcheck, flake-check, analyzers, nuget-pack, expected-pack, github-release-plugin-dry-run] + needs: [check-dotnet-format, check-nix-format, build, build-nix, linkcheck, flake-check, analyzers, nuget-pack, expected-pack, github-release-dry-run] runs-on: ubuntu-latest steps: - uses: G-Research/common-actions/check-required-lite@2b7dc49cb14f3344fbe6019c14a31165e258c059 @@ -241,17 +253,29 @@ jobs: github-release: runs-on: ubuntu-latest if: ${{ !github.event.repository.fork && github.ref == 'refs/heads/main' }} - needs: [all-required-checks-complete] environment: main-deploy permissions: contents: write + needs: [all-required-checks-complete] steps: - uses: actions/checkout@v4 - name: Download NuGet artifact uses: actions/download-artifact@v4 with: name: nuget-package - - name: Tag and release + - name: Compute package path + id: compute-path + run: | + find . -maxdepth 1 -type f -name 'WoofWare.PrattParser.*.nupkg' -exec sh -c 'echo "output=$(basename "$1")" >> $GITHUB_OUTPUT' shell {} \; + - name: Compute tag name + id: compute-tag env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: sh .github/workflows/tag.sh + NUPKG_PATH: ${{ steps.compute-path.outputs.output }} + run: echo "output=$(basename "$NUPKG_PATH" .nupkg)" >> $GITHUB_OUTPUT + - name: Tag and release + uses: G-Research/common-actions/github-release@19d7281a0f9f83e13c78f99a610dbc80fc59ba3b + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + target-commitish: ${{ github.sha }} + tag: ${{ steps.compute-tag.outputs.output }} + binary-contents: ${{ steps.compute-path.outputs.output }} diff --git a/.github/workflows/tag.sh b/.github/workflows/tag.sh deleted file mode 100644 index f70483e..0000000 --- a/.github/workflows/tag.sh +++ /dev/null @@ -1,120 +0,0 @@ -#!/bin/bash - -echo "Dry-run? $DRY_RUN!" - -find . -maxdepth 1 -type f ! -name "$(printf "*\n*")" -name '*.nupkg' | while IFS= read -r file -do - tag=$(basename "$file" .nupkg) - git tag "$tag" - ${DRY_RUN:+echo} git push origin "$tag" -done - -export TAG -TAG=$(find . -maxdepth 1 -type f -name 'WoofWare.PrattParser.*.nupkg' -exec sh -c 'basename "$1" .nupkg' shell {} \; | grep -v Attributes) - -case "$TAG" in - *" -"*) - echo "Error: TAG contains a newline; multiple plugins found." - exit 1 - ;; -esac - -# target_commitish empty indicates the repo default branch -curl_body='{"tag_name":"'"$TAG"'","target_commitish":"","name":"'"$TAG"'","draft":false,"prerelease":false,"generate_release_notes":false}' - -echo "cURL body: $curl_body" - -failed_output=$(cat <<'EOF' -{ - "message": "Validation Failed", - "errors": [ - { - "resource": "Release", - "code": "already_exists", - "field": "tag_name" - } - ], - "documentation_url": "https://docs.github.com/rest/releases/releases#create-a-release" -} -EOF -) - -success_output=$(cat <<'EOF' -{ - "url": "https://api.github.com/repos/Smaug123/fsharp-prattparser/releases/158152116", - "assets_url": "https://api.github.com/repos/Smaug123/fsharp-prattparser/releases/158152116/assets", - "upload_url": "https://uploads.github.com/repos/Smaug123/fsharp-prattparser/releases/158152116/assets{?name,label}", - "html_url": "https://github.com/Smaug123/fsharp-prattparser/releases/tag/WoofWare.PrattParser.2.1.30", - "id": 158152116, - "author": { - "login": "github-actions[bot]", - "id": 41898282, - "node_id": "MDM6Qm90NDE4OTgyODI=", - "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", - "gravatar_id": "", - "url": "https://api.github.com/users/github-actions%5Bbot%5D", - "html_url": "https://github.com/apps/github-actions", - "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", - "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", - "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", - "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", - "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", - "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", - "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", - "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", - "type": "Bot", - "site_admin": false - }, - "node_id": "RE_kwDOJfksgc4JbTW0", - "tag_name": "WoofWare.PrattParser.2.1.30", - "target_commitish": "main", - "name": "WoofWare.PrattParser.2.1.30", - "draft": false, - "prerelease": false, - "created_at": "2024-05-30T11:00:55Z", - "published_at": "2024-05-30T11:03:02Z", - "assets": [ - - ], - "tarball_url": "https://api.github.com/repos/Smaug123/fsharp-prattparser/tarball/WoofWare.PrattParser.2.1.30", - "zipball_url": "https://api.github.com/repos/Smaug123/fsharp-prattparser/zipball/WoofWare.PrattParser.2.1.30", - "body": null -} -EOF -) - -HANDLE_OUTPUT='' -handle_error() { - ERROR_OUTPUT="$1" - exit_message=$(echo "$ERROR_OUTPUT" | jq -r --exit-status 'if .errors | length == 1 then .errors[0].code else null end') - if [ "$exit_message" = "already_exists" ] ; then - HANDLE_OUTPUT="Did not create GitHub release because it already exists at this version." - else - echo "Unexpected error output from curl: $(cat curl_output.json)" - echo "JQ output: $(exit_message)" - exit 2 - fi -} - -run_tests() { - handle_error "$failed_output" - if [ "$HANDLE_OUTPUT" != "Did not create GitHub release because it already exists at this version." ]; then - echo "Bad output from handler: $HANDLE_OUTPUT" - exit 3 - fi - HANDLE_OUTPUT='' - echo "Tests passed." -} - -run_tests - -if [ "$DRY_RUN" != 1 ] ; then - if curl --fail-with-body -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GITHUB_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/Smaug123/fsharp-prattparser/releases -d "$curl_body" > curl_output.json; then - echo "Curl succeeded." - else - handle_error "$(cat curl_output.json)" - echo "$HANDLE_OUTPUT" - fi -fi