From 3a61ffbb45ef0222e99740c9806775ccd47d9f37 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Tue, 16 Apr 2024 11:44:26 -0600 Subject: [PATCH 1/6] Get sha from comment or head --- .github/workflows/snapshot-release.yml | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/snapshot-release.yml b/.github/workflows/snapshot-release.yml index 0db436315f3..ae2865bb3ec 100644 --- a/.github/workflows/snapshot-release.yml +++ b/.github/workflows/snapshot-release.yml @@ -33,13 +33,29 @@ jobs: - uses: alessbell/pull-request-comment-branch@v1.1 id: comment-branch + - name: Get sha + id: parse-sha + run: | + if ( + ${{ github.event.sender.login }} == 'benjamn' || + ${{ github.event.sender.login }} == 'alessbell' || + ${{ github.event.sender.login }} == 'bignimbus' || + ${{ github.event.sender.login }} == 'hwillson' || + ${{ github.event.sender.login }} == 'jerelmiller' || + ${{ github.event.sender.login }} == 'phryneas' + ); then + echo "sha<<${{ steps.comment-brand.outputs.head_sha }}" >> "${GITHUB_OUTPUT}" + else + echo "sha<<"${${{ github.event.comment.body }} | tr -s ' ' | cut -d ' ' -f2}" >> "${GITHUB_OUTPUT}" + fi + - name: Checkout head ref uses: actions/checkout@v4 with: ## specify the owner + repository in order to checkout the fork ## for community PRs repository: ${{ steps.comment-branch.outputs.head_owner }}/${{ steps.comment-branch.outputs.head_repo }} - ref: ${{ steps.comment-branch.outputs.head_ref }} + ref: ${{ steps.parse-sha.outputs.sha}} fetch-depth: 0 - name: Detect new changesets @@ -47,7 +63,7 @@ jobs: run: | delimiter="$(openssl rand -hex 8)" echo "changesets<<${delimiter}" >> "${GITHUB_OUTPUT}" - echo "$(git diff --name-only --diff-filter=A ${{ steps.comment-branch.outputs.base_sha }} ${{ steps.comment-branch.outputs.head_sha }} .changeset/*.md)" >> "${GITHUB_OUTPUT}" + echo "$(git diff --name-only --diff-filter=A ${{ steps.comment-branch.outputs.base_sha }} ${{ steps.parse-sha.outputs.sha }} .changeset/*.md)" >> "${GITHUB_OUTPUT}" echo "${delimiter}" >> "${GITHUB_OUTPUT}" - name: Append NPM token to .npmrc From fca0c32882d517eea8763c86fa6dae61f3cc38a1 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Fri, 19 Apr 2024 16:17:36 -0600 Subject: [PATCH 2/6] Properly parse sha from comment --- .github/workflows/snapshot-release.yml | 33 ++++++++++++++++++-------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/.github/workflows/snapshot-release.yml b/.github/workflows/snapshot-release.yml index ae2865bb3ec..f536e063509 100644 --- a/.github/workflows/snapshot-release.yml +++ b/.github/workflows/snapshot-release.yml @@ -36,19 +36,32 @@ jobs: - name: Get sha id: parse-sha run: | - if ( - ${{ github.event.sender.login }} == 'benjamn' || - ${{ github.event.sender.login }} == 'alessbell' || - ${{ github.event.sender.login }} == 'bignimbus' || - ${{ github.event.sender.login }} == 'hwillson' || - ${{ github.event.sender.login }} == 'jerelmiller' || - ${{ github.event.sender.login }} == 'phryneas' - ); then - echo "sha<<${{ steps.comment-brand.outputs.head_sha }}" >> "${GITHUB_OUTPUT}" + if [ "${{ steps.comment-branch.outputs.head_owner }}" == "apollographql" ]; then + echo "sha=${{ steps.comment-branch.outputs.head_sha }}" >> "${GITHUB_OUTPUT}" else - echo "sha<<"${${{ github.event.comment.body }} | tr -s ' ' | cut -d ' ' -f2}" >> "${GITHUB_OUTPUT}" + sha_from_comment="$(echo '${{ github.event.comment.body }}' | tr -s ' ' | cut -d ' ' -f2)" + + if [ $sha_from_comment == "/release:pr" ]; then + exit 1 + else + echo "sha=$sha_from_comment" >> "${GITHUB_OUTPUT}" + fi fi + + - name: Comment sha reminder + if: steps.parse-sha.outcome == 'failure' + uses: peter-evans/create-or-update-comment@v2.1.0 + with: + issue-number: ${{ github.event.issue.number }} + body: | + Did you forget to add the sha? Please use `/release:pr ` + + - name: Fail job + if: steps.parse-sha.outcome == 'failure' + run: | + exit 1 + - name: Checkout head ref uses: actions/checkout@v4 with: From 14a5c2be1795c16a72c9dd5b0fd6ad429451ca9b Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Fri, 19 Apr 2024 16:22:37 -0600 Subject: [PATCH 3/6] Tweak name of step --- .github/workflows/snapshot-release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/snapshot-release.yml b/.github/workflows/snapshot-release.yml index f536e063509..be4b5365f9f 100644 --- a/.github/workflows/snapshot-release.yml +++ b/.github/workflows/snapshot-release.yml @@ -62,13 +62,13 @@ jobs: run: | exit 1 - - name: Checkout head ref + - name: Checkout ref uses: actions/checkout@v4 with: ## specify the owner + repository in order to checkout the fork ## for community PRs repository: ${{ steps.comment-branch.outputs.head_owner }}/${{ steps.comment-branch.outputs.head_repo }} - ref: ${{ steps.parse-sha.outputs.sha}} + ref: ${{ steps.parse-sha.outputs.sha }} fetch-depth: 0 - name: Detect new changesets From 30fe41448fb3eb7de36c3d0bc249e177c8bb22c4 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Fri, 19 Apr 2024 16:31:11 -0600 Subject: [PATCH 4/6] Switch to env variable to get comment body --- .github/workflows/snapshot-release.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/snapshot-release.yml b/.github/workflows/snapshot-release.yml index 8542877ab88..648b4d298c6 100644 --- a/.github/workflows/snapshot-release.yml +++ b/.github/workflows/snapshot-release.yml @@ -39,7 +39,7 @@ jobs: if [ "${{ steps.comment-branch.outputs.head_owner }}" == "apollographql" ]; then echo "sha=${{ steps.comment-branch.outputs.head_sha }}" >> "${GITHUB_OUTPUT}" else - sha_from_comment="$(echo '${{ github.event.comment.body }}' | tr -s ' ' | cut -d ' ' -f2)" + sha_from_comment="$(echo $COMMENT_BODY | tr -s ' ' | cut -d ' ' -f2)" if [ $sha_from_comment == "/release:pr" ]; then exit 1 @@ -47,6 +47,8 @@ jobs: echo "sha=$sha_from_comment" >> "${GITHUB_OUTPUT}" fi fi + env: + COMMENT_BODY: ${{ github.event.comment.body }} - name: Comment sha reminder From 67b413da5b63ba2a311f61166d52a9e8994d76f9 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Fri, 19 Apr 2024 16:31:52 -0600 Subject: [PATCH 5/6] Fix formatting --- .github/workflows/snapshot-release.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/snapshot-release.yml b/.github/workflows/snapshot-release.yml index 648b4d298c6..6cc1b9a5edb 100644 --- a/.github/workflows/snapshot-release.yml +++ b/.github/workflows/snapshot-release.yml @@ -50,7 +50,6 @@ jobs: env: COMMENT_BODY: ${{ github.event.comment.body }} - - name: Comment sha reminder if: steps.parse-sha.outcome == 'failure' uses: peter-evans/create-or-update-comment@v2.1.0 From 919808e7a8a38365037f535a3cdffadaa22962d4 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Mon, 22 Apr 2024 10:04:14 -0600 Subject: [PATCH 6/6] Add continue-on-error --- .github/workflows/snapshot-release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/snapshot-release.yml b/.github/workflows/snapshot-release.yml index 6cc1b9a5edb..6020dddee7d 100644 --- a/.github/workflows/snapshot-release.yml +++ b/.github/workflows/snapshot-release.yml @@ -35,6 +35,7 @@ jobs: - name: Get sha id: parse-sha + continue-on-error: true run: | if [ "${{ steps.comment-branch.outputs.head_owner }}" == "apollographql" ]; then echo "sha=${{ steps.comment-branch.outputs.head_sha }}" >> "${GITHUB_OUTPUT}"