🔄 synced file(s) with PaddleHQ/go-library-template #222
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # DO NOT EDIT: This file should only be modified in the `go-library-template` repo. | |
| name: Ensure SemVer Label is added | |
| on: | |
| pull_request: | |
| types: | |
| - opened | |
| - synchronize | |
| - reopened | |
| - labeled | |
| - unlabeled | |
| permissions: | |
| contents: read | |
| issues: read | |
| pull-requests: read | |
| actions: write # required for `workflow-dispatch` to trigger the automerge workflow | |
| env: | |
| VALID_SEMVER_LABELS: norelease,release:major,release:minor,release:patch | |
| jobs: | |
| check_semver: | |
| name: Ensure SemVer Label is added | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.13.2 | |
| with: | |
| egress-policy: audit | |
| - name: Checkout code | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| persist-credentials: false | |
| - name: Read build config | |
| id: build_config | |
| uses: pietrobolcato/action-read-yaml@9f13718d61111b69f30ab4ac683e67a56d254e1d # 1.1.0 | |
| with: | |
| config: ${{ github.workspace }}/build-config.yaml | |
| - uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | |
| if: steps.build_config.outputs['semanticReleases'] != 'false' | |
| with: | |
| script: | | |
| const validLabels = process.env.VALID_SEMVER_LABELS.split(","); | |
| const { data: labelResultList } = await github.rest.issues.listLabelsOnIssue({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number | |
| }); | |
| const prLabels = labelResultList.map(label => label.name); | |
| const semverLabels = prLabels.filter(value => validLabels.includes(value)); | |
| core.info(`Valid labels: ${validLabels.join(" | ")}`); | |
| core.info(`PR labels: ${prLabels.join(" | ")}`); | |
| core.info(`Semver Labels: ${semverLabels.join(" | ")}`); | |
| if (semverLabels.length == 0) { | |
| core.setFailed("You must add a SemVer label of one of ${validLabels.join(" | ")} to this PR"); | |
| } | |
| if (semverLabels.length > 1) { | |
| core.setFailed("You must only add one SemVer label to this PR"); | |
| } | |
| - name: Automerge | |
| uses: ./.github/actions/trigger-automerge | |
| with: | |
| event: ${{ toJSON(github.event) }} | |
| hasAutoApproverPrivateKey: ${{ secrets.AUTO_APPROVER_PRIVATE_KEY != '' }} |