Skip to content

Commit

Permalink
improved PR workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
josefaidt committed Oct 14, 2023
1 parent 5dfd86e commit 9af3619
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/actions/get-semver-label-from-pr/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# used to extract the version from a semver label
name: get-semver-label-from-pr
description: Gets semver label from PR event
outputs:
semver-label:
description: Semver label name
value: ${{ steps.get-label.outputs.result }}
semver-bump:
description: Semver bump type
value: ${{ steps.get-bump.outputs.result }}
runs:
using: 'composite'
steps:
- uses: actions/github-script@v6
id: get-label
with:
script: |
const labels = context.payload.pull_request.labels
const semverLabels = labels.filter(label => label.name.startsWith('semver:'))
if (semverLabels.length === 0) {
return core.setFailed('No semver label found')
}
if (semverLabels.length > 1) {
return core.setFailed('Cannot have multiple semver labels')
}
return semverLabels[0].name
- uses: actions/github-script@v6
id: get-bump
if: ${{ success() }}
env:
LABEL_NAME: ${{ steps.get-label.outputs.result }}
with:
script: |
return process.env.LABEL_NAME.replace('semver: ', '')
31 changes: 31 additions & 0 deletions .github/workflows/pr-has-semver-label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: pr-has-semver-label
on:
pull_request_target:
branches:
- main
types:
- opened
- labeled
- unlabeled
- ready_for_review
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
pr-has-semver-label:
if: github.event.pull_request.draft == false
name: pr-has-semver-label
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
sparse-checkout: |
.github
- name: Does the PR have a single semver label?
id: get-semver-label
uses: ./.github/actions/get-semver-label-from-pr
- name: update GitHub Action summary
id: set-semver-label-output
if: ${{ success() }}
run: echo "PR merge will cause a ${{ steps.get-semver-label.outputs.semver-bump }} version bump" >> $GITHUB_STEP_SUMMARY

0 comments on commit 9af3619

Please sign in to comment.