generated from NHSDigital/nhs-notify-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
148 lines (129 loc) · 4.87 KB
/
pr_closed.yaml
File metadata and controls
148 lines (129 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: PR Closed
on:
workflow_dispatch:
pull_request:
types: [closed]
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
check-merge-or-workflow-dispatch:
runs-on: ubuntu-latest
outputs:
deploy: ${{ steps.check.outputs.deploy }}
steps:
- name: Check if PR was merged or workflow is triggered by workflow_dispatch
id: check
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "deploy=true" >> $GITHUB_OUTPUT
echo "Job triggered by workflow_dispatch - running 'deploy-main'"
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.merged }}" == "true" ]]; then
echo "deploy=true" >> $GITHUB_OUTPUT
echo "Job triggered by Merged PR - running 'deploy-main'"
else
echo "deploy=false" >> $GITHUB_OUTPUT
echo "Job not triggered by workflow_dispatch or Merged PR - Skipping 'deploy-main'"
fi
deploy-main:
needs: check-merge-or-workflow-dispatch
name: Deploy changes to main in dev AWS account
runs-on: ubuntu-latest
if: needs.check-merge-or-workflow-dispatch.outputs.deploy == 'true'
permissions:
id-token: write
contents: read
strategy:
max-parallel: 1
matrix:
component: [acct, app]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Updating Main Environment
env:
APP_PEM_FILE: ${{ secrets.APP_PEM_FILE }}
APP_CLIENT_ID: ${{ secrets.APP_CLIENT_ID }}
run: |
bash .github/scripts/dispatch_internal_repo_workflow.sh \
--releaseVersion "main" \
--targetWorkflow "dispatch-deploy-static-notify-web-template-management-env.yaml" \
--targetEnvironment "main" \
--targetAccountGroup "nhs-notify-template-management-dev" \
--targetComponent "${{ matrix.component }}" \
--terraformAction "apply"
check-event-schemas-version-change:
name: Check for event schemas package version change
needs: check-merge-or-workflow-dispatch
if: needs.check-merge-or-workflow-dispatch.outputs.deploy == 'true'
outputs:
version_changed: ${{ steps.check-version.outputs.version_changed }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
steps:
- name: Checkout code
uses: actions/checkout@v5.0.0
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: '20.18.2'
registry-url: 'https://npm.pkg.github.com'
- name: check if local version differs from latest published version
id: check-version
run: |
published_version=$(npm view @nhsdigital/nhs-notify-event-schemas-template-management --json 2>/dev/null | jq -r '.["dist-tags"].latest // "null"')
echo "Published version: $published_version"
local_version=$(jq -r '.version' packages/event-schemas/package.json)
echo "Local version: $local_version"
if [[ $local_version = $published_version ]]; then
echo "Local version is the same as the latest published version - skipping publish"
echo "version_changed=false" >> $GITHUB_OUTPUT
else
echo "Local version is different to the latest published version - publishing new version"
echo "version_changed=true" >> $GITHUB_OUTPUT
fi
test-contract-provider:
name: "Test contracts (provider)"
needs: check-event-schemas-version-change
if: needs.check-event-schemas-version-change.outputs.version_changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
- name: "Install dependencies"
run: npm ci
- name: "Run provider contract tests"
run: make test-contract-provider
env:
GITHUB_PACKAGES_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-event-schemas:
name: Publish event schemas package to GitHub package registry
needs:
- check-event-schemas-version-change
- test-contract-provider
if: needs.check-event-schemas-version-change.outputs.version_changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v5.0.0
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: '20.18.2'
registry-url: 'https://npm.pkg.github.com'
- name: Install dependencies
run: npm ci
- name: Publish to GitHub Packages
run: npm publish --workspace packages/event-schemas
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}