Skip to content

Commit 300e284

Browse files
committed
create gha
1 parent 5494fb1 commit 300e284

1 file changed

Lines changed: 118 additions & 0 deletions

File tree

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: example
2+
on:
3+
pull_request:
4+
# types:
5+
# - opened
6+
7+
workflow_dispatch:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
deploy-and-test:
15+
runs-on: ubuntu-latest
16+
env:
17+
AWS_REGION: eu-west-2
18+
STACK_PREFIX: test
19+
REPO_NAME: ${{ github.event.repository.name }}-frontend-${{ github.event.pull_request.number || github.run_id }}
20+
IMAGE_TAG: ${{ github.sha }}
21+
steps:
22+
- name: Checkout Current Repository
23+
uses: actions/checkout@v4
24+
25+
- name: Assume AWS Role
26+
uses: aws-actions/configure-aws-credentials@v4
27+
with:
28+
role-to-assume: ${{ secrets.DEV_GH_ACTIONS_ROLE_ARN }}
29+
aws-region: ${{ env.AWS_REGION }}
30+
role-session-name: GitHubActions-${{ github.run_id }}
31+
role-duration-seconds: 3600
32+
33+
- name: Checkout API Repository
34+
uses: actions/checkout@v4
35+
with:
36+
repository: govuk-one-login/ipv-cri-check-hmrc-api
37+
ref: main
38+
path: ipv-cri-check-hmrc-api
39+
40+
- name: Build API
41+
run: |
42+
mkdir -p api
43+
sam build -t ipv-cri-check-hmrc-api/infrastructure/template.yaml -b api/
44+
45+
- name: Deploy API
46+
run: |
47+
sam deploy \
48+
--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM \
49+
--no-fail-on-empty-changeset \
50+
--no-confirm-changeset \
51+
--resolve-s3 \
52+
--template-file api/.aws-sam/build/template.yaml \
53+
--stack-name ${{ env.STACK_PREFIX }}-api-${{ github.event.pull_request.number || github.run_id }} \
54+
--region ${{ env.AWS_REGION }}
55+
56+
- name: Fetch PublicAPIGatewayId
57+
id: fetch-api-id
58+
run: |
59+
PRIVATE_API_GATEWAY_ID=$(aws cloudformation describe-stacks \
60+
--stack-name ${{ env.STACK_PREFIX }}-api-${{ github.event.pull_request.number || github.run_id }} \
61+
--query "Stacks[0].Outputs[?OutputKey=='PrivateAPIGatewayId'].OutputValue" \
62+
--output text)
63+
echo "PRIVATE_API_GATEWAY_ID=$PRIVATE_API_GATEWAY_ID" >> $GITHUB_ENV
64+
65+
- name: Build Frontend
66+
run: |
67+
mkdir -p frontend
68+
sam build -t deploy/template.yaml -b frontend/
69+
70+
- name: Create ECR Repository
71+
run: |
72+
aws ecr create-repository \
73+
--repository-name ${{ env.REPO_NAME }} \
74+
--region ${{ env.AWS_REGION }} \
75+
--image-scanning-configuration scanOnPush=true \
76+
--encryption-configuration encryptionType=AES256 || echo "Repository already exists"
77+
78+
- name: Get ECR Repository URL
79+
id: get-ecr-url
80+
run: |
81+
REPO_URI=$(aws ecr describe-repositories \
82+
--repository-names ${{ env.REPO_NAME }} \
83+
--region ${{ env.AWS_REGION }} \
84+
--query "repositories[0].repositoryUri" \
85+
--output text)
86+
echo "REPO_URI=$REPO_URI" >> $GITHUB_ENV
87+
88+
- name: Build and Push Frontend Image
89+
run: |
90+
aws ecr get-login-password --region ${{ env.AWS_REGION }} | docker login \
91+
--username AWS --password-stdin ${{ env.REPO_URI }}
92+
docker build -t ${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }} .
93+
docker tag ${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }} ${{ env.REPO_URI }}:${{ env.IMAGE_TAG }}
94+
docker push ${{ env.REPO_URI }}:${{ env.IMAGE_TAG }}
95+
96+
- name: Deploy Frontend
97+
run: |
98+
sam deploy \
99+
--capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM \
100+
--no-fail-on-empty-changeset \
101+
--no-confirm-changeset \
102+
--resolve-s3 \
103+
--template-file frontend/.aws-sam/build/template.yaml \
104+
--stack-name ${{ env.STACK_PREFIX }}-frontend-${{ github.event.pull_request.number || github.run_id }} \
105+
--parameter-overrides \
106+
Environment=localdev \
107+
VpcStackName=cri-vpc \
108+
CRIPrivateApiGatewayId=${{ env.PRIVATE_API_GATEWAY_ID }} \
109+
ContainerImageName=${{ env.REPO_URI }}:${{ env.IMAGE_TAG }} \
110+
--region ${{ env.AWS_REGION }}
111+
112+
- name: Run Tests
113+
env:
114+
API_STACK: ${{ env.STACK_PREFIX }}-api-${{ github.event.pull_request.number || github.run_id }}
115+
FRONTEND_STACK: ${{ env.STACK_PREFIX }}-frontend-${{ github.event.pull_request.number || github.run_id }}
116+
run: |
117+
npm ci
118+
npm run test

0 commit comments

Comments
 (0)