diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4a06fd5..12c1198 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,9 +6,7 @@ on: jobs: quality_checks: - uses: ./.github/workflows/quality_checks.yml - with: - BRANCH_NAME: main + uses: NHSDigital/eps-workflow-quality-checks/.github/workflows/quality-checks.yml@main secrets: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} @@ -27,7 +25,7 @@ jobs: uses: asdf-vm/actions/setup@05e0d2ed97b598bfce82fd30daf324ae0c4570e6 with: asdf_branch: v0.11.3 - + - name: Cache asdf uses: actions/cache@v4 with: @@ -42,8 +40,8 @@ jobs: with: asdf_branch: v0.11.3 env: - PYTHON_CONFIGURE_OPTS: --enable-shared - + PYTHON_CONFIGURE_OPTS: --enable-shared + - name: Install node packages run: | make install-node diff --git a/.github/workflows/pr_link.yml b/.github/workflows/pr_link.yml index f25eac7..1bd4340 100644 --- a/.github/workflows/pr_link.yml +++ b/.github/workflows/pr_link.yml @@ -1,34 +1,46 @@ -name: PR Title Check - +name: PR Link ticket on: - workflow_call: - + pull_request: + types: [opened] jobs: - pr_title_format_check: + link-ticket: runs-on: ubuntu-latest + env: + REF: ${{ github.event.pull_request.head.ref }} steps: - - name: Check PR Title is Prefixed with Change Type - env: - PR_TITLE: ${{ github.event.pull_request.title }} + - name: Check ticket name conforms to requirements + run: echo "$REF" | grep -i -E -q "(aea-[0-9]+)|(apm-[0-9]+)|(apmspii-[0-9]+)|(adz-[0-9]+)|(amb-[0-9]+)|(dependabot\/)" + continue-on-error: true + + - name: Grab ticket name + if: contains(github.event.pull_request.head.ref, 'aea-') || contains(github.event.pull_request.head.ref, 'AEA-') || contains(github.event.pull_request.head.ref, 'apm-') || contains(github.event.pull_request.head.ref, 'APM-') || contains(github.event.pull_request.head.ref, 'apmspii-') || contains(github.event.pull_request.head.ref, 'APMSPII-') || contains(github.event.pull_request.head.ref, 'adz-') || contains(github.event.pull_request.head.ref, 'ADZ-') || contains(github.event.pull_request.head.ref, 'amb-') || contains(github.event.pull_request.head.ref, 'AMB-') + continue-on-error: true run: | - if [[ "$PR_TITLE" =~ ^(Fix|Update|New|Breaking|Docs|Build|Upgrade|Chore):.*$ ]]; then - echo "PR title is prefixed with change type." - else - echo "PR title is not prefixed with change type." - echo "Please prefix your PR title with a change type (Fix, Update, New, Breaking, Docs, Build, Upgrade, Chore)." - echo "See the contributing guide for more details:" - echo "https://github.com/NHSDigital/nhs-eps-spine-client/blob/main/CONTRIBUTING.md" - exit 1 - fi + # Match ticket name patterns + REGEX=' + (aea-[0-9]+)| + (apm-[0-9]+)| + (apmspii-[0-9]+)| + (adz-[0-9]+)| + (amb-[0-9]+) + ' - - name: Check PR Title contains Ticket/Dependabot Reference + # Remove whitespace and newlines from the regex + REGEX=$(echo "$REGEX" | tr -d '[:space:]') + + # Extract the ticket name and convert to uppercase + TICKET_NAME=$(echo "$REF" | grep -i -E -o "$REGEX" | tr '[:lower:]' '[:upper:]') + + # Set the environment variable + echo "TICKET_NAME=$TICKET_NAME" >> "$GITHUB_ENV" + + - name: Comment on PR with link to JIRA ticket + if: contains(github.event.pull_request.head.ref, 'aea-') || contains(github.event.pull_request.head.ref, 'AEA-') || contains(github.event.pull_request.head.ref, 'apm-') || contains(github.event.pull_request.head.ref, 'APM-') || contains(github.event.pull_request.head.ref, 'apmspii-') || contains(github.event.pull_request.head.ref, 'APMSPII-') || contains(github.event.pull_request.head.ref, 'adz-') || contains(github.event.pull_request.head.ref, 'ADZ-') || contains(github.event.pull_request.head.ref, 'amb-') || contains(github.event.pull_request.head.ref, 'AMB-') + continue-on-error: true + uses: unsplash/comment-on-pr@master env: - PR_TITLE: ${{ github.event.pull_request.title }} - run: | - if [[ "$PR_TITLE" =~ ^.*:.*\[([A-Z]+-[0-9]+|dependabot)\].*-.*$ ]]; then - echo "PR title contains ticket or dependabot reference." - else - echo "PR title does not contain ticket or dependabot reference." - echo "Please ensure PR title contains a ticket (eg. 'Fix: [AEA-####] - ...', or 'Chore: [dependabot] - ...')." - exit 1 - fi + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + msg: | + This branch is work on a ticket in an NHS Digital JIRA Project. Here's a handy link to the ticket: + # [${{ env.TICKET_NAME }}](https://nhsd-jira.digital.nhs.uk/browse/${{ env.TICKET_NAME }}) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 7a8861f..c63120a 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -6,9 +6,7 @@ on: jobs: quality_checks: - uses: ./.github/workflows/quality_checks.yml - with: - BRANCH_NAME: ${{ github.event.pull_request.head.ref }} + uses: NHSDigital/eps-workflow-quality-checks/.github/workflows/quality-checks.yml@main secrets: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.github/workflows/quality_checks.yml b/.github/workflows/quality_checks.yml deleted file mode 100644 index b170054..0000000 --- a/.github/workflows/quality_checks.yml +++ /dev/null @@ -1,65 +0,0 @@ -name: Quality Checks - -on: - workflow_call: - inputs: - BRANCH_NAME: - type: string - required: true - secrets: - SONAR_TOKEN: - required: true - -jobs: - quality_checks: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - ref: ${{ inputs.BRANCH_NAME }} - fetch-depth: 0 - - # using git commit sha for version of action to ensure we have stable version - - name: Install asdf - uses: asdf-vm/actions/setup@05e0d2ed97b598bfce82fd30daf324ae0c4570e6 - with: - asdf_branch: v0.11.3 - - - name: Cache asdf - uses: actions/cache@v4 - with: - path: | - ~/.asdf - key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }} - restore-keys: | - ${{ runner.os }}-asdf- - - - name: Install asdf dependencies in .tool-versions - uses: asdf-vm/actions/install@05e0d2ed97b598bfce82fd30daf324ae0c4570e6 - with: - asdf_branch: v0.11.3 - env: - PYTHON_CONFIGURE_OPTS: --enable-shared - - - name: make install - run: | - make install - - - name: run check-licenses - run: make check-licenses - - - name: run lint - run: make lint - - - name: run build - run: make build - - - name: run unit tests - run: make test - - - name: SonarCloud Scan - uses: SonarSource/sonarcloud-github-action@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index af3c468..2b28cb7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,9 +7,7 @@ on: jobs: quality_checks: - uses: ./.github/workflows/quality_checks.yml - with: - BRANCH_NAME: main + uses: NHSDigital/eps-workflow-quality-checks/.github/workflows/quality-checks.yml@main secrets: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/README.md b/README.md index bbdd3c1..135bf8a 100644 --- a/README.md +++ b/README.md @@ -130,9 +130,8 @@ Workflows are in the .github/workflows folder - `dependabot_auto_approve_and_merge.yml` Workflow to auto merge dependabot updates - `pr-link.yaml` This workflow template links Pull Requests to Jira tickets and runs when a pull request is opened - `pr_title_check.yml` Workflow to check the format of a pull request is compliant with the project standards. See [guidelines for contribution](./CONTRIBUTING.md) for details -- `pull_request.yml` Called when pull request is opened or updated. Runs quality_checks.yml -- `quality_checks.yml` Workflow verifies and enhances code quality through setup, dependencies, checks, and SonarCloud scanning -- `release.yml` Run when code is merged to main branch or a tag starting v is pushed. Calls quality_checks.yml +- `pull_request.yml` Called when pull request is opened or updated. Runs [quality_checks](https://github.com/NHSDigital/eps-workflow-quality-checks) +- `release.yml` Run when code is merged to main branch or a tag starting v is pushed. Calls [quality_checks](https://github.com/NHSDigital/eps-workflow-quality-checks) - `rename_dependabot_prs.yml` Renames dependabot pull requests to comply with project standards ### Running a Release