|
| 1 | +name: PR Closed |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + types: [closed] |
| 7 | + branches: |
| 8 | + - main |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 12 | + cancel-in-progress: false |
| 13 | + |
| 14 | +jobs: |
| 15 | + check-merge-or-workflow-dispatch: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + deploy: ${{ steps.check.outputs.deploy }} |
| 19 | + steps: |
| 20 | + - name: Check if PR was merged or workflow is triggered by workflow_dispatch |
| 21 | + id: check |
| 22 | + run: | |
| 23 | + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then |
| 24 | + echo "deploy=true" >> $GITHUB_OUTPUT |
| 25 | + echo "Job triggered by workflow_dispatch - running 'deploy-main'" |
| 26 | + elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.merged }}" == "true" ]]; then |
| 27 | + echo "deploy=true" >> $GITHUB_OUTPUT |
| 28 | + echo "Job triggered by Merged PR - running 'deploy-main'" |
| 29 | + else |
| 30 | + echo "deploy=false" >> $GITHUB_OUTPUT |
| 31 | + echo "Job not triggered by workflow_dispatch or Merged PR - Skipping 'deploy-main'" |
| 32 | + fi |
| 33 | +
|
| 34 | + check-event-schemas-version-change: |
| 35 | + name: Check for event schemas package version change |
| 36 | + needs: check-merge-or-workflow-dispatch |
| 37 | + if: needs.check-merge-or-workflow-dispatch.outputs.deploy == 'true' |
| 38 | + outputs: |
| 39 | + version_changed: ${{ steps.check-version.outputs.version_changed }} |
| 40 | + runs-on: ubuntu-latest |
| 41 | + permissions: |
| 42 | + contents: read |
| 43 | + packages: read |
| 44 | + steps: |
| 45 | + - name: Checkout code |
| 46 | + |
| 47 | + |
| 48 | + - name: Setup NodeJS |
| 49 | + uses: actions/setup-node@v4 |
| 50 | + with: |
| 51 | + node-version: ${{ inputs.nodejs_version }} |
| 52 | + |
| 53 | + - name: check if local version differs from latest published version |
| 54 | + id: check-version |
| 55 | + run: | |
| 56 | + published_version=$(npm view @nhsdigital/nhs-notify-event-schemas-letter-rendering --json 2>/dev/null | jq -r '.["dist-tags"].latest // "null"') |
| 57 | + echo "Published version: $published_version" |
| 58 | +
|
| 59 | + local_version=$(jq -r '.version' packages/events/package.json) |
| 60 | + echo "Local version: $local_version" |
| 61 | +
|
| 62 | + if [[ $local_version = $published_version ]]; then |
| 63 | + echo "Local version is the same as the latest published version - skipping publish" |
| 64 | + echo "version_changed=false" >> $GITHUB_OUTPUT |
| 65 | + else |
| 66 | + echo "Local version is different to the latest published version - publishing new version" |
| 67 | + echo "version_changed=true" >> $GITHUB_OUTPUT |
| 68 | + fi |
| 69 | +
|
| 70 | + test-contract-provider: |
| 71 | + name: "Test contracts (provider)" |
| 72 | + needs: check-event-schemas-version-change |
| 73 | + if: needs.check-event-schemas-version-change.outputs.version_changed == 'true' |
| 74 | + runs-on: ubuntu-latest |
| 75 | + permissions: |
| 76 | + contents: read |
| 77 | + packages: read |
| 78 | + steps: |
| 79 | + - name: "Checkout code" |
| 80 | + |
| 81 | + - name: Setup NodeJS |
| 82 | + uses: actions/setup-node@v4 |
| 83 | + with: |
| 84 | + node-version: ${{ inputs.nodejs_version }} |
| 85 | + - name: "Install dependencies" |
| 86 | + run: npm ci |
| 87 | + - name: "Run provider contract tests" |
| 88 | + run: make test-contract-provider |
| 89 | + env: |
| 90 | + GITHUB_PACKAGES_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 91 | + |
| 92 | + publish-event-schemas: |
| 93 | + name: Publish event schemas package to GitHub package registry |
| 94 | + needs: |
| 95 | + - check-event-schemas-version-change |
| 96 | + - test-contract-provider |
| 97 | + if: needs.check-event-schemas-version-change.outputs.version_changed == 'true' |
| 98 | + runs-on: ubuntu-latest |
| 99 | + permissions: |
| 100 | + contents: read |
| 101 | + packages: write |
| 102 | + |
| 103 | + steps: |
| 104 | + - name: Checkout code |
| 105 | + |
| 106 | + |
| 107 | + - name: Setup NodeJS |
| 108 | + uses: actions/setup-node@v4 |
| 109 | + with: |
| 110 | + node-version: ${{ inputs.nodejs_version }} |
| 111 | + registry-url: 'https://npm.pkg.github.com' |
| 112 | + |
| 113 | + - name: Install dependencies |
| 114 | + run: npm ci |
| 115 | + |
| 116 | + - name: Publish to GitHub Packages |
| 117 | + run: npm publish --workspace packages/events |
| 118 | + env: |
| 119 | + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments