Skip to content

Commit 969bb6b

Browse files
authored
feat: add release trigger for merged PRs with create-release label (#1244)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. --> ## Overview This PR updates the release CI to trigger when a PR with the `create-release` label is merged. See tested action: https://github.com/MSevey/workflows/actions/runs/6489995567 <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. --> ## Checklist <!-- Please complete the checklist to ensure that the PR is ready to be reviewed. IMPORTANT: PRs should be left in Draft until the below checklist is completed. --> - [ ] New and updated code has appropriate documentation - [ ] New and updated code has new and/or updated testing - [ ] Required CI checks are passing - [ ] Visual proof for any user facing features like CLI or documentation updates - [ ] Linked issues closed with keywords
1 parent e3218bb commit 969bb6b

1 file changed

Lines changed: 42 additions & 3 deletions

File tree

.github/workflows/ci_release.yml

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,50 @@ jobs:
3737
proto:
3838
uses: ./.github/workflows/proto.yml
3939

40-
# Make a release if this is a manually trigger job, i.e. workflow_dispatch
40+
# get_merged_pr_labels uses the listPullRequestsAssociatedWithCommit API
41+
# endpoint to get the PR information for the commit during a push event. Once
42+
# the PR information is received, we check to see if the create-release label
43+
# was added to the pr.
44+
get_merged_pr_labels:
45+
runs-on: ubuntu-latest
46+
outputs:
47+
has_release_label: ${{ steps.set-outputs.outputs.has_release_label }}
48+
steps:
49+
# We only want to run this step on a push event, otherwise this will error
50+
# out as the result is null. We have the if condition here as to not block
51+
# steps that rely on this step and others if this step is skipped.
52+
- name: Query listPullRequestsAssociatedWithCommit for the PR information
53+
if: ${{ github.event_name == 'push' }}
54+
uses: actions/github-script@v6
55+
id: get_pr_data
56+
with:
57+
script: |
58+
const prData = await github.rest.repos.listPullRequestsAssociatedWithCommit({
59+
commit_sha: context.sha,
60+
owner: context.repo.owner,
61+
repo: context.repo.repo,
62+
});
63+
const pr = prData.data[0];
64+
const prLabels = pr ? pr.labels.map(label => label.name) : [];
65+
const hasReleaseLabel = prLabels.includes('create-release');
66+
return { hasReleaseLabel };
67+
# Only run if the result is not null. We add this check so that the CI
68+
# does not show a failure when the previous step is skipped.
69+
- name: Set the outputs
70+
if: steps.get_pr_data.outputs.result != null
71+
id: set-outputs
72+
run: echo "has_release_label=${{ fromJSON(steps.get_pr_data.outputs.result).hasReleaseLabel }}" >> "$GITHUB_OUTPUT"
73+
74+
# Make a release if this is a manually trigger job, i.e. workflow_dispatch, or
75+
# there was a merged pr with the create-release label
4176
release:
42-
needs: [lint, test, proto]
77+
needs: [lint, test, proto, get_merged_pr_labels]
4378
runs-on: ubuntu-latest
44-
if: ${{ github.event_name == 'workflow_dispatch' }}
79+
if: |
80+
github.event_name == 'workflow_dispatch' ||
81+
(github.event_name == 'push' &&
82+
contains(github.ref, 'refs/heads/main') &&
83+
needs.get_merged_pr_labels.outputs.has_release_label)
4584
permissions: "write-all"
4685
steps:
4786
- uses: actions/checkout@v4

0 commit comments

Comments
 (0)