From d38af43567e95c66bd799db9e3a192bda3b4fc6b Mon Sep 17 00:00:00 2001 From: Liam MacPherson Date: Tue, 16 Apr 2024 12:56:26 +0100 Subject: [PATCH] ci: implement tagging of repository on change --- .../pull-request-semver-label-check.yaml | 39 ++++++++++++++ .../pull-request-semver-tag-merge.yaml | 52 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 .github/workflows/pull-request-semver-label-check.yaml create mode 100644 .github/workflows/pull-request-semver-tag-merge.yaml diff --git a/.github/workflows/pull-request-semver-label-check.yaml b/.github/workflows/pull-request-semver-label-check.yaml new file mode 100644 index 0000000..89fecce --- /dev/null +++ b/.github/workflows/pull-request-semver-label-check.yaml @@ -0,0 +1,39 @@ +name: 'Check PR for SemVer Label' +on: + pull_request: + types: + - labeled + - unlabeled + - opened + - reopened + - synchronize + branches: + - main + +permissions: + pull-requests: read + contents: read + +jobs: + semver-check: + name: 'Check PR for SemVer Label' + if: | + contains(github.event.pull_request.labels.*.name, 'skip-release') == false + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Parse the SemVer label + id: label + uses: UKHomeOffice/match-label-action@v1 + with: + labels: minor,major,patch + mode: singular + + - name: Calculate SemVer value + id: calculate + uses: UKHomeOffice/semver-calculate-action@v2 + with: + increment: ${{ steps.label.outputs.matchedLabels }} + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pull-request-semver-tag-merge.yaml b/.github/workflows/pull-request-semver-tag-merge.yaml new file mode 100644 index 0000000..0266df5 --- /dev/null +++ b/.github/workflows/pull-request-semver-tag-merge.yaml @@ -0,0 +1,52 @@ +name: 'SemVer Tag on Main Merge' +on: + pull_request: + types: + - closed + branches: + - main + +permissions: + pull-requests: read + contents: write + +concurrency: + group: ${{ github.workflow }} + cancel-in-progress: false + +jobs: + semver-tag: + name: 'Tag Repository with SemVer' + if: | + github.event.pull_request.merged == true && + contains(github.event.pull_request.labels.*.name, 'skip-release') == false + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Parse the SemVer label + id: label + uses: UKHomeOffice/match-label-action@v1 + with: + labels: minor,major,patch + mode: singular + + - name: Calculate SemVer value + id: calculate + uses: UKHomeOffice/semver-calculate-action@v2 + with: + increment: ${{ steps.label.outputs.matchedLabels }} + github_token: ${{ secrets.GITHUB_TOKEN }} + + - uses: actions/create-github-app-token@v1 + id: app-token + with: + app-id: ${{ secrets.GH_APP_ID }} + private-key: ${{ secrets.GH_APP_PEM_FILE }} + + - name: Tag Repository + uses: UKHomeOffice/semver-tag-action@v4 + with: + tag: ${{ steps.calculate.outputs.version }} + github_token: ${{ steps.app-token.outputs.token }}