Skip to content

Commit

Permalink
fix: better logic for determining if the run was triggered by a relea…
Browse files Browse the repository at this point in the history
…se pr
  • Loading branch information
stdavis committed Jul 10, 2024
1 parent 9736328 commit 8193c5c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"cSpell.words": [
"agrc",
"automerge",
"autorelease",
"Pelka",
"Radovan",
"tibdex",
Expand Down
47 changes: 30 additions & 17 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,33 @@ runs:

- name: 🤔 Is this a release PR merge
id: is-release-pr
shell: bash
run: |
latest_commit_message=$(git log -1 --pretty=format:%s)
if [[ "${{ inputs.prerelease }}" == "true" ]]; then
pattern="chore: release v[0-9]\+\.[0-9]\+\.[0-9]\+-[0-9]\+$"
else
pattern="chore: release v[0-9]\+\.[0-9]\+\.[0-9]\+$"
fi
if echo $latest_commit_message | grep -q "$pattern"; then
echo "this workflow was triggered by a release PR"
echo "result=yes" >> $GITHUB_OUTPUT
else
echo "this workflow was not triggered by a release PR"
fi
uses: actions/github-script@v6
with:
result-encoding: string
retries: 3
script: |
const response = (
await github.rest.repos.listPullRequestsAssociatedWithCommit({
commit_sha: context.sha,
owner: context.repo.owner,
repo: context.repo.repo,
})
);
for (const pullRequest of response.data) {
if (
pullRequest.base.ref === context.ref.replace('refs/heads/', '') &&
pullRequest.state === 'closed' &&
pullRequest.labels.some(label => label.name === 'autorelease: pending')
) {
console.log('this workflow was triggered by a release PR');
return 'yes';
}
}
console.log('this workflow was *not* triggered by a release PR');
return 'no';
- name: ⏩ Get next version
if: ${{ !env.ACT }}
Expand Down Expand Up @@ -113,7 +126,7 @@ runs:
- name: 🚀 Create release PR
id: create-release-pr
if: ${{ !steps.is-release-pr.outputs.result }}
if: ${{ steps.is-release-pr.outputs.result == 'no' }}
shell: bash
run: |
node release-please/build/src/bin/release-please.js release-pr \
Expand All @@ -129,7 +142,7 @@ runs:
- name: 🚀 Create GitHub release
id: create-github-release
if: ${{ steps.is-release-pr.outputs.result }}
if: ${{ steps.is-release-pr.outputs.result == 'yes' }}
shell: bash
run: |
node release-please/build/src/bin/release-please.js github-release \
Expand All @@ -149,7 +162,7 @@ runs:
- name: 🏷️ Tag major and minor versions
shell: bash
if: ${{ inputs.create-major-minor-tags == 'true' && steps.is-release-pr.outputs.result && inputs.prerelease != 'true' }}
if: ${{ inputs.create-major-minor-tags == 'true' && steps.is-release-pr.outputs.result == 'yes' && inputs.prerelease != 'true' }}
run: |
major="${{ steps.get-next-version.outputs.major || steps.mock-get-next-version.outputs.major }}"
minor="${{ steps.get-next-version.outputs.minor || steps.mock-get-next-version.outputs.minor }}"
Expand Down

0 comments on commit 8193c5c

Please sign in to comment.