Skip to content

Commit 9058587

Browse files
committed
added deployment code (plan for now) to workflow and retags for semantic versioning and releases
1 parent 9700cfa commit 9058587

2 files changed

Lines changed: 93 additions & 6 deletions

File tree

.github/workflows/cicd-2-publish.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ jobs:
4848
runs-on: ubuntu-latest
4949
needs: [metadata]
5050
timeout-minutes: 10
51+
permissions:
52+
id-token: write
53+
contents: read
5154
steps:
5255
- name: "Setup Terraform"
5356
uses: hashicorp/setup-terraform@v3

.github/workflows/cicd-3-deploy.yaml

Lines changed: 90 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@ on:
44
workflow_dispatch:
55
inputs:
66
tag:
7-
description: "This is the tag that is oging to be deployed"
7+
description: "This is the tag that is going to be deployed"
88
required: true
99
default: "latest"
10+
environment:
11+
description: "Target environment (e.g., ref or prod)"
12+
required: true
13+
type: choice
14+
options:
15+
- ref
16+
- prod
17+
- dev
1018

1119
jobs:
1220
metadata:
@@ -23,8 +31,11 @@ jobs:
2331
version: ${{ steps.variables.outputs.version }}
2432
tag: ${{ steps.variables.outputs.tag }}
2533
steps:
26-
- name: "Checkout code"
34+
- name: "Checkout tag"
2735
uses: actions/checkout@v4
36+
with:
37+
ref: ${{ github.event.inputs.tag }}
38+
2839
- name: "Set CI/CD variables"
2940
id: variables
3041
run: |
@@ -52,12 +63,85 @@ jobs:
5263
deploy:
5364
name: "Deploy to an environment"
5465
runs-on: ubuntu-latest
55-
needs: [metadata]
66+
needs: [ metadata ]
5667
timeout-minutes: 10
68+
permissions:
69+
id-token: write
70+
contents: read
5771
steps:
58-
- name: "Checkout code"
59-
uses: actions/checkout@v4
60-
# TODO: More jobs or/and steps here
72+
- name: "Setup Terraform"
73+
uses: hashicorp/setup-terraform@v3
74+
with:
75+
terraform_version: ${{ needs.metadata.outputs.terraform_version }}
76+
77+
- name: "Set up Python"
78+
uses: actions/setup-python@v5
79+
with:
80+
python-version: '3.13'
81+
82+
- name: "Download Built Lambdas"
83+
uses: actions/download-artifact@v4
84+
with:
85+
name: lambda
86+
path: ./build
87+
88+
- name: "Configure AWS Credentials"
89+
uses: aws-actions/configure-aws-credentials@v4
90+
with:
91+
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/service-roles/github-actions-dev-deployment-role
92+
aws-region: eu-west-2
93+
94+
- name: "Terraform Apply"
95+
env:
96+
ENVIRONMENT: ${{ inputs.environment }}
97+
WORKSPACE: "default"
98+
TF_VAR_API_CA_CERT: ${{ secrets.API_CA_CERT }}
99+
TF_VAR_API_CLIENT_CERT: ${{ secrets.API_CLIENT_CERT }}
100+
TF_VAR_API_PRIVATE_KEY_CERT: ${{ secrets.API_PRIVATE_KEY_CERT }}
101+
102+
# just planning for now for safety and until review
103+
run: |
104+
mkdir -p ./build
105+
echo "Running: make terraform env=$ENVIRONMENT workspace=$WORKSPACE stack=networking tf-command=plan"
106+
make terraform env=$ENVIRONMENT stack=networking tf-command=plan workspace=$WORKSPACE
107+
echo "Running: make terraform env=$ENVIRONMENT workspace=$WORKSPACE stack=api-layer tf-command=plan"
108+
make terraform env=$ENVIRONMENT stack=api-layer tf-command=plan workspace=$WORKSPACE
109+
working-directory: ./infrastructure
110+
111+
- name: "Tag the deployment using incremental semantic versioning"
112+
id: next_tag
113+
run: |
114+
# Fetch all tags and sort them semantically
115+
git fetch --tags
116+
latest_tag=$(git tag --list 'v*' | sort -V | tail -n 1)
117+
echo "Latest tag: $latest_tag"
118+
119+
if [[ -z "$latest_tag" ]]; then
120+
next_tag="v0.1.0"
121+
else
122+
# Extract the version numbers
123+
IFS='.' read -r major minor patch <<< "${latest_tag#v}"
124+
patch=$((patch + 1))
125+
next_tag="v${major}.${minor}.${patch}"
126+
fi
127+
128+
echo "Next tag: $next_tag"
129+
echo "tag=$next_tag" >> $GITHUB_OUTPUT
130+
131+
- name: "Create GitHub Release"
132+
uses: actions/create-release@v1
133+
env:
134+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
135+
with:
136+
tag_name: ${{ steps.next_tag.outputs.next_tag }}
137+
release_name: Release ${{ steps.next_tag.outputs.next_tag }}
138+
body: |
139+
Auto-release created during deployment.
140+
draft: false
141+
prerelease: ${{ inputs.environment == 'ref' }}
142+
143+
144+
# TODO: complete notify step
61145
# success:
62146
# name: "Success notification"
63147
# runs-on: ubuntu-latest

0 commit comments

Comments
 (0)