Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require sha when creating snapshot releases on forks #11794

Merged
merged 8 commits into from
Apr 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions .github/workflows/snapshot-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,52 @@ jobs:
- uses: alessbell/[email protected]
id: comment-branch

- name: Checkout head ref
- 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}"
else
sha_from_comment="$(echo $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
env:
COMMENT_BODY: ${{ github.event.comment.body }}

- name: Comment sha reminder
if: steps.parse-sha.outcome == 'failure'
uses: peter-evans/[email protected]
with:
issue-number: ${{ github.event.issue.number }}
body: |
Did you forget to add the sha? Please use `/release:pr <sha>`

- name: Fail job
if: steps.parse-sha.outcome == 'failure'
run: |
exit 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between these two exit 1?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I forgot to copy a critical line from my testing. The Get sha step should have continue-on-error: true set, which would mean that instead of failing the entire job, it would allow it to continue. The idea was that if it failed, it would add the comment to the PR "Did you forget...", then fail early, hence this step.

The other option would be to update every step with if: steps.parse-sha-outcome != 'failure', but that felt like a lot and figured I'd just exit early instead. That plus the job itself would fail rather than succeed in that case so we'd get alerts that way too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


- 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.comment-branch.outputs.head_ref }}
ref: ${{ steps.parse-sha.outputs.sha }}
fetch-depth: 0

- name: Detect new changesets
id: added-files
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
Expand Down
Loading