Skip to content

Commit 26ba5f8

Browse files
committed
Add github workflows
1 parent eeab885 commit 26ba5f8

File tree

6 files changed

+643
-0
lines changed

6 files changed

+643
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: cdk package code
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
VERSION_NUMBER:
7+
required: true
8+
type: string
9+
COMMIT_ID:
10+
required: true
11+
type: string
12+
13+
jobs:
14+
package_code:
15+
runs-on: ubuntu-22.04
16+
permissions:
17+
id-token: write
18+
contents: read
19+
packages: read
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
with:
24+
ref: ${{ env.BRANCH_NAME }}
25+
26+
# using git commit sha for version of action to ensure we have stable version
27+
- name: Install asdf
28+
uses: asdf-vm/actions/setup@1902764435ca0dd2f3388eea723a4f92a4eb8302
29+
with:
30+
asdf_branch: v0.14.1
31+
32+
- name: Cache asdf
33+
uses: actions/cache@v4
34+
with:
35+
path: |
36+
~/.asdf
37+
key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }}
38+
restore-keys: |
39+
${{ runner.os }}-asdf-
40+
41+
- name: Install asdf dependencies in .tool-versions
42+
uses: asdf-vm/actions/install@1902764435ca0dd2f3388eea723a4f92a4eb8302
43+
with:
44+
asdf_branch: v0.14.1
45+
env:
46+
PYTHON_CONFIGURE_OPTS: --enable-shared
47+
48+
- name: Setting up .npmrc
49+
env:
50+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
run: |
52+
echo "//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}" >> ~/.npmrc
53+
echo "@nhsdigital:registry=https://npm.pkg.github.com" >> ~/.npmrc
54+
55+
- name: make install
56+
run: |
57+
make install
58+
59+
- name: 'Tar files'
60+
run: |
61+
tar -rf artifact.tar \
62+
.tool-versions \
63+
packages \
64+
node_modules \
65+
package.json \
66+
package-lock.json \
67+
tsconfig.defaults.json \
68+
cdk.json
69+
70+
- uses: actions/upload-artifact@v4
71+
name: upload build artifact
72+
with:
73+
name: build_artifact
74+
path: artifact.tar
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
name: cdk release code
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
STACK_NAME:
7+
required: true
8+
type: string
9+
TARGET_ENVIRONMENT:
10+
required: true
11+
type: string
12+
VERSION_NUMBER:
13+
required: true
14+
type: string
15+
COMMIT_ID:
16+
required: true
17+
type: string
18+
CDK_APP_NAME:
19+
required: true
20+
type: string
21+
LOG_RETENTION_IN_DAYS:
22+
required: true
23+
type: string
24+
LOG_LEVEL:
25+
required: true
26+
type: string
27+
ENABLE_MUTUAL_TLS:
28+
required: true
29+
type: boolean
30+
MARK_JIRA_RELEASED:
31+
type: boolean
32+
default: false
33+
secrets:
34+
CLOUD_FORMATION_DEPLOY_ROLE:
35+
required: true
36+
CDK_PULL_IMAGE_ROLE:
37+
required: true
38+
DEV_CLOUD_FORMATION_CHECK_VERSION_ROLE:
39+
required: false
40+
DEV_CLOUD_FORMATION_EXECUTE_LAMBDA_ROLE:
41+
required: false
42+
REGRESSION_TESTS_PEM:
43+
required: false
44+
45+
jobs:
46+
release_code:
47+
runs-on: ubuntu-22.04
48+
environment: ${{ inputs.TARGET_ENVIRONMENT }}
49+
name: deploy cdk app ${{ inputs.CDK_APP_NAME }}
50+
permissions:
51+
id-token: write
52+
contents: write
53+
54+
steps:
55+
- name: Checkout local github actions
56+
uses: actions/checkout@v4
57+
with:
58+
ref: ${{ env.BRANCH_NAME }}
59+
fetch-depth: 0
60+
sparse-checkout: |
61+
.github
62+
63+
- name: Configure AWS Credentials
64+
id: connect-aws-pull-image
65+
uses: aws-actions/configure-aws-credentials@v4
66+
with:
67+
aws-region: eu-west-2
68+
role-to-assume: ${{ secrets.CDK_PULL_IMAGE_ROLE }}
69+
role-session-name: eps-assist-me-pull-image
70+
71+
- name: build_artifact download
72+
uses: actions/download-artifact@v4
73+
with:
74+
name: build_artifact
75+
76+
- name: extract build_artifact
77+
run: |
78+
mkdir -p .build
79+
tar -xf artifact.tar -C .build
80+
81+
- name: Retrieve AWS Account ID
82+
id: retrieve-account-id
83+
run: echo "ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)" >> "$GITHUB_ENV"
84+
85+
- name: Login to Amazon ECR
86+
id: login-ecr
87+
run: |
88+
aws ecr get-login-password --region eu-west-2 | docker login --username AWS --password-stdin ${{ env.ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com
89+
90+
- name: Pull cdk-utils-build from Amazon ECR
91+
run: |
92+
docker pull "${{ env.ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com/cdk-utils-build-repo:latest"
93+
docker tag "${{ env.ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com/cdk-utils-build-repo:latest" cdk-utils-build-repo:latest
94+
95+
- name: Configure AWS Credentials
96+
id: connect-aws
97+
uses: aws-actions/configure-aws-credentials@v4
98+
with:
99+
aws-region: eu-west-2
100+
role-to-assume: ${{ secrets.CLOUD_FORMATION_DEPLOY_ROLE }}
101+
role-session-name: eps-assist-me-deployment
102+
output-credentials: true
103+
104+
- name: fix cdk.json for deployment
105+
run: |
106+
./.github/scripts/fix_cdk_json.sh
107+
env:
108+
STACK_NAME: "${{ inputs.STACK_NAME }}"
109+
VERSION_NUMBER: "${{ inputs.VERSION_NUMBER }}"
110+
COMMIT_ID: "${{ inputs.COMMIT_ID }}"
111+
LOG_RETENTION_IN_DAYS: "${{ inputs.LOG_RETENTION_IN_DAYS }}"
112+
LOG_LEVEL: "${{ inputs.LOG_LEVEL }}"
113+
ENABLE_MUTUAL_TLS: "${{ inputs.ENABLE_MUTUAL_TLS }}"
114+
115+
- name: Show diff
116+
run: |
117+
docker run \
118+
-v "$(pwd)/.build":/home/cdkuser/workspace/ \
119+
-e AWS_ACCESS_KEY_ID=${{ steps.connect-aws.outputs.aws-access-key-id }} \
120+
-e AWS_SECRET_ACCESS_KEY=${{ steps.connect-aws.outputs.aws-secret-access-key }} \
121+
-e AWS_SESSION_TOKEN=${{ steps.connect-aws.outputs.aws-session-token }} \
122+
-e AWS_REGION="eu-west-2" \
123+
-e stack_name="${{ inputs.STACK_NAME }}" \
124+
-e VERSION_NUMBER="${{ inputs.VERSION_NUMBER}}" \
125+
-e COMMIT_ID="${{ inputs.COMMIT_ID}}" \
126+
-e SHOW_DIFF="true" \
127+
-e DEPLOY_CODE="false" \
128+
-e CDK_APP_PATH="packages/cdk/bin/EpsAssistMeApp.ts" \
129+
cdk-utils-build-repo:latest
130+
shell: bash
131+
132+
- name: Deploy code
133+
run: |
134+
docker run \
135+
-v "$(pwd)/.build":/home/cdkuser/workspace/ \
136+
-e AWS_ACCESS_KEY_ID=${{ steps.connect-aws.outputs.aws-access-key-id }} \
137+
-e AWS_SECRET_ACCESS_KEY=${{ steps.connect-aws.outputs.aws-secret-access-key }} \
138+
-e AWS_SESSION_TOKEN=${{ steps.connect-aws.outputs.aws-session-token }} \
139+
-e AWS_REGION="eu-west-2" \
140+
-e stack_name="${{ inputs.STACK_NAME }}" \
141+
-e VERSION_NUMBER="${{ inputs.VERSION_NUMBER}}" \
142+
-e COMMIT_ID="${{ inputs.COMMIT_ID}}" \
143+
-e SHOW_DIFF="false" \
144+
-e DEPLOY_CODE="true" \
145+
-e CDK_APP_PATH="packages/cdk/bin/EpsAssistMeApp.ts" \
146+
cdk-utils-build-repo:latest
147+
shell: bash
148+
149+
- name: mark_released_in_jira
150+
uses: ./.github/actions/mark_jira_released
151+
if: ${{ inputs.MARK_JIRA_RELEASED == true && always() && !failure() && !cancelled() }}
152+
with:
153+
RELEASE_TAG: ${{ inputs.VERSION_NUMBER }}
154+
DEV_CLOUD_FORMATION_EXECUTE_LAMBDA_ROLE: ${{ secrets.DEV_CLOUD_FORMATION_EXECUTE_LAMBDA_ROLE }}
155+
- name: Checkout gh-pages
156+
if: ${{ !startsWith(inputs.STACK_NAME, 'cpt-pr-') }}
157+
uses: actions/checkout@v4
158+
with:
159+
ref: gh-pages
160+
path: gh-pages
161+
162+
- name: Checkout gh-pages
163+
if: ${{ !startsWith(inputs.STACK_NAME, 'lambda-resources-pr-') }}
164+
uses: actions/checkout@v4
165+
with:
166+
ref: gh-pages
167+
path: gh-pages
168+
169+
- name: Update release tag in github pages
170+
if: ${{ !startsWith(inputs.STACK_NAME, 'epsam-pr-') }}
171+
run: |
172+
cd gh-pages
173+
NOW=$(date +'%Y-%m-%dT%H:%M:%S')
174+
echo "tag,release_datetime" > _data/${{ inputs.TARGET_ENVIRONMENT }}_latest.csv
175+
echo "${{ inputs.VERSION_NUMBER }},${NOW}" >> _data/${{ inputs.TARGET_ENVIRONMENT }}_latest.csv
176+
echo "${{ inputs.VERSION_NUMBER }},${NOW}" >> _data/${{ inputs.TARGET_ENVIRONMENT }}_deployments.csv
177+
git config user.name github-actions
178+
git config user.email github-actions@github.com
179+
git add _data/${{ inputs.TARGET_ENVIRONMENT }}_latest.csv
180+
git add _data/${{ inputs.TARGET_ENVIRONMENT }}_deployments.csv
181+
git commit -m 'update releases for ${{ inputs.TARGET_ENVIRONMENT }}'
182+
parallel --retries 10 --delay 3 ::: "git pull --rebase && git push"

.github/workflows/ci.yml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: merge to main workflow
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
env:
8+
BRANCH_NAME: ${{ github.event.ref.BRANCH_NAME }}
9+
10+
jobs:
11+
# quality_checks:
12+
# uses: NHSDigital/eps-workflow-quality-checks/.github/workflows/quality-checks.yml@v4.0.5
13+
# secrets:
14+
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
15+
16+
get_commit_id:
17+
runs-on: ubuntu-22.04
18+
outputs:
19+
commit_id: ${{ steps.commit_id.outputs.commit_id }}
20+
steps:
21+
- name: Get Commit ID
22+
id: commit_id
23+
run: |
24+
echo "commit_id=${{ github.sha }}" >> "$GITHUB_OUTPUT"
25+
26+
tag_release:
27+
# needs: quality_checks
28+
runs-on: ubuntu-22.04
29+
outputs:
30+
version_tag: ${{ steps.output_version_tag.outputs.VERSION_TAG }}
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v4
34+
with:
35+
ref: ${{ env.BRANCH_NAME }}
36+
fetch-depth: 0
37+
38+
# using git commit sha for version of action to ensure we have stable version
39+
- name: Install asdf
40+
uses: asdf-vm/actions/setup@05e0d2ed97b598bfce82fd30daf324ae0c4570e6
41+
with:
42+
asdf_branch: v0.14.1
43+
44+
- name: Cache asdf
45+
uses: actions/cache@v4
46+
with:
47+
path: |
48+
~/.asdf
49+
key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }}
50+
restore-keys: |
51+
${{ runner.os }}-asdf-
52+
53+
- name: Install asdf dependencies in .tool-versions
54+
uses: asdf-vm/actions/install@05e0d2ed97b598bfce82fd30daf324ae0c4570e6
55+
with:
56+
asdf_branch: v0.14.1
57+
env:
58+
PYTHON_CONFIGURE_OPTS: --enable-shared
59+
60+
- name: Setting up .npmrc
61+
env:
62+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
run: |
64+
echo "//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}" >> ~/.npmrc
65+
echo "@nhsdigital:registry=https://npm.pkg.github.com" >> ~/.npmrc
66+
67+
- name: Install Dependencies
68+
run: make install
69+
70+
- name: Set VERSION_TAG env var to be short git SHA and get next tag varsion
71+
id: output_version_tag
72+
run: |
73+
VERSION_TAG=$(git rev-parse --short HEAD)
74+
npx semantic-release --dry-run > semantic-release-output.log
75+
NEXT_VERSION=$(grep -i 'The next release version is' semantic-release-output.log | sed -E 's/.* ([[:digit:].]+)$/\1/')
76+
if [ -z "${NEXT_VERSION}" ]
77+
then
78+
echo "Could not get next tag. Here is the log from semantic-release"
79+
cat semantic-release-output.log
80+
exit 1
81+
fi
82+
tagFormat=$(node -e "const config=require('./release.config.js'); console.log(config.tagFormat)")
83+
if [ "${tagFormat}" = "null" ]
84+
then
85+
tagFormat="v\${version}"
86+
fi
87+
# disabling shellcheck as replace does not work
88+
# shellcheck disable=SC2001
89+
NEW_VERSION_TAG=$(echo "$tagFormat" | sed "s/\${version}/$NEXT_VERSION/")
90+
echo "## VERSION TAG : ${VERSION_TAG}" >> "$GITHUB_STEP_SUMMARY"
91+
echo "## NEXT TAG WILL BE : ${NEW_VERSION_TAG}" >> "$GITHUB_STEP_SUMMARY"
92+
echo "VERSION_TAG=${VERSION_TAG}" >> "$GITHUB_OUTPUT"
93+
echo "VERSION_TAG=${VERSION_TAG}" >> "$GITHUB_ENV"
94+
env:
95+
GITHUB_TOKEN: ${{ github.token }}
96+
97+
package_code:
98+
needs: [get_commit_id, tag_release]
99+
uses: ./.github/workflows/cdk_package_code.yml
100+
with:
101+
VERSION_NUMBER: ${{ needs.tag_release.outputs.version_tag }}
102+
COMMIT_ID: ${{ needs.get_commit_id.outputs.commit_id }}
103+
104+
release_dev:
105+
needs: [get_commit_id, tag_release, package_code]
106+
uses: ./.github/workflows/cdk_release_code.yml
107+
with:
108+
STACK_NAME: epsam
109+
TARGET_ENVIRONMENT: dev
110+
VERSION_NUMBER: ${{ needs.tag_release.outputs.version_tag }}
111+
COMMIT_ID: ${{ needs.get_commit_id.outputs.commit_id }}
112+
CDK_APP_NAME: CptsApiApp
113+
LOG_RETENTION_IN_DAYS: 30
114+
LOG_LEVEL: DEBUG
115+
ENABLE_MUTUAL_TLS: false
116+
MARK_JIRA_RELEASED: false
117+
secrets:
118+
CLOUD_FORMATION_DEPLOY_ROLE: ${{ secrets.DEV_CLOUD_FORMATION_DEPLOY_ROLE }}
119+
CDK_PULL_IMAGE_ROLE: ${{ secrets.DEV_CDK_PULL_IMAGE_ROLE }}
120+
REGRESSION_TESTS_PEM: ${{ secrets.REGRESSION_TESTS_PEM }}
121+
DEV_CLOUD_FORMATION_CHECK_VERSION_ROLE: ${{ secrets.DEV_CLOUD_FORMATION_CHECK_VERSION_ROLE }}
122+
DEV_CLOUD_FORMATION_EXECUTE_LAMBDA_ROLE: ${{ secrets.DEV_CLOUD_FORMATION_EXECUTE_LAMBDA_ROLE }}
123+

0 commit comments

Comments
 (0)