From 5c74015b7d93a8044cc9549a85e37dec3b96d0b4 Mon Sep 17 00:00:00 2001 From: Smaug123 <3138005+Smaug123@users.noreply.github.com> Date: Mon, 27 Jan 2025 08:49:54 +0000 Subject: [PATCH] Switch to GR's tagging workflow --- .github/workflows/dotnet.yaml | 70 +++++++++++++++++++++++------------ .github/workflows/tag.sh | 31 ---------------- 2 files changed, 46 insertions(+), 55 deletions(-) delete mode 100644 .github/workflows/tag.sh diff --git a/.github/workflows/dotnet.yaml b/.github/workflows/dotnet.yaml index 75fef14..9a267f4 100644 --- a/.github/workflows/dotnet.yaml +++ b/.github/workflows/dotnet.yaml @@ -111,19 +111,6 @@ jobs: # Verify that there is exactly one ApiSurface.*.nupkg in the artifact that would be NuGet published run: if [[ $(find . -maxdepth 1 -name 'ApiSurface.*.nupkg' -printf c | wc -c) -ne "1" ]]; then exit 1; fi - github-tag-and-release-dry-run: - runs-on: ubuntu-latest - needs: [expected-pack] - steps: - - uses: actions/checkout@v4 - - name: Download NuGet artifact - uses: actions/download-artifact@v4 - - name: Tag and release packages - env: - GITHUB_TOKEN: "mock-token" - DRY_RUN: "1" - run: bash .github/workflows/tag.sh - all-required-checks-complete: needs: [check-format, build, expected-pack, analyze-code, github-tag-and-release-dry-run] if: ${{ always() }} @@ -162,24 +149,59 @@ jobs: nuget-key: ${{ secrets.NUGET_API_KEY }} nupkg-dir: downloaded + github-tag-and-release-dry-run: + runs-on: ubuntu-latest + needs: [expected-pack] + steps: + - uses: actions/checkout@v4 + - name: Download NuGet artifact + uses: actions/download-artifact@v4 + with: + name: nuget-package + - name: Compute package path + id: compute-path + run: | + find . -maxdepth 1 -type f -name 'ApiSurface.*.nupkg' -exec sh -c 'echo "output=$(basename "$1")" >> $GITHUB_OUTPUT' shell {} \; + - name: Compute tag name + id: compute-tag + env: + 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 + github-tag-and-release: runs-on: ubuntu-latest if: ${{ !github.event.repository.fork && github.ref == 'refs/heads/main' }} needs: [all-required-checks-complete] environment: release + permissions: + contents: write steps: - - name: Generate app token - id: app-token - uses: actions/create-github-app-token@v1 - with: - app-id: ${{ secrets.APP_ID }} - private-key: ${{ secrets.APP_PRIVATE_KEY }} - uses: actions/checkout@v4 - with: - token: ${{ steps.app-token.outputs.token }} - name: Download NuGet artifact uses: actions/download-artifact@v4 - - name: Tag and release packages + with: + name: nuget-package + - name: Compute package path + id: compute-path + run: | + find . -maxdepth 1 -type f -name 'ApiSurface.*.nupkg' -exec sh -c 'echo "output=$(basename "$1")" >> $GITHUB_OUTPUT' shell {} \; + - name: Compute tag name + id: compute-tag env: - GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} - run: bash .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 c0401da..0000000 --- a/.github/workflows/tag.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -run_or_echo() { - if [[ "$DRY_RUN" = "1" ]]; then - echo "$@" - else - "$@" - fi -} - -export -f run_or_echo - -find . -maxdepth 2 -type f -name '*.nupkg' -exec bash -c 'tag=$(basename "$1" .nupkg); git tag "$tag"; run_or_echo git push origin "$tag"' shell {} \; - -export TAG -TAG=$(find . -maxdepth 2 -type f -name 'ApiSurface.*.nupkg' -exec sh -c 'basename "$1" .nupkg' shell {} \;) - -case "$TAG" in - *" -"*) - echo "Error: TAG contains a newline; multiple packages found." - exit 1 - ;; - "") - echo "Error: no TAG found; aborting." - exit 2 - ;; -esac - -# the empty target_commitish indicates the repo default branch -run_or_echo curl -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/G-Research/ApiSurface/releases -d '{"tag_name":"'"$TAG"'","target_commitish":"","name":"'"$TAG"'","draft":false,"prerelease":false,"generate_release_notes":false}'