3232 terraform_version : ${{ steps.variables.outputs.terraform_version }}
3333 ref : ${{ steps.variables.outputs.ref }}
3434 environment : ${{ steps.variables.outputs.environment }}
35+ tag : ${{ steps.tag.outputs.name }}
3536 steps :
3637 - name : " Checkout ref"
3738 uses : actions/checkout@v5
7475 echo "ref=$REF"
7576 echo "environment=$ENVIRONMENT"
7677
78+ - name : " Resolve the dev-* tag for this commit"
79+ id : tag
80+ run : |
81+ git fetch --tags --force
82+ SHA="${{ github.event.workflow_run.head_sha }}"
83+ TAG=$(git tag --points-at "$SHA" | grep '^dev-' | head -n1 || true)
84+ if [ -z "$TAG" ]; then
85+ echo "No dev-* tag found on $SHA" >&2
86+ exit 1
87+ fi
88+ echo "name=$TAG" >> $GITHUB_OUTPUT
89+ echo "Resolved tag: $TAG"
90+
91+ download-lambda-artifact :
92+ name : " Fetch the lambda artifact from previous stage"
93+ runs-on : ubuntu-latest
94+ needs : [metadata]
95+ timeout-minutes : 45
96+ permissions :
97+ id-token : write
98+ contents : write
99+ env :
100+ PROMOTED_ENV : ${{
101+ contains(needs.metadata.outputs.environment, 'preprod') && 'test' ||
102+ contains(needs.metadata.outputs.environment, 'prod') && 'preprod' ||
103+ needs.metadata.outputs.environment
104+ }}
105+ environment : ${{ env.PROMOTED_ENV }}
106+ steps :
107+ - name : " Checkout repository at ref"
108+ uses : actions/checkout@v5
109+ with :
110+ ref : ${{ needs.metadata.outputs.ref }}
111+ fetch-depth : 0
112+
113+ - name : " Extract S3 bucket name from Terraform output"
114+ id : tf_output
115+ run : |
116+ BUCKET=$(terraform output -raw lambda_artifact_bucket)
117+ echo "bucket_name=$BUCKET" >> $GITHUB_OUTPUT
118+ working-directory : ./infrastructure/stacks/api-layer
119+
120+ - name : " Download lambda artifact from S3"
121+ run : |
122+ aws s3 cp \
123+ s3://${{ steps.tf_output.outputs.bucket_name }}/artifacts/${{ needs.metadata.outputs.tag }}/lambda.zip \
124+ ./build/lambda.zip \
125+ --region eu-west-2
126+
127+ - name : " Upload lambda artifact for the current workflow"
128+ uses : actions/upload-artifact@v4
129+ with :
130+ name : lambda-${{ needs.metadata.outputs.tag }}
131+ path : ./build/lambda.zip
132+
133+
77134 deploy :
78135 name : " Deploy to ${{ needs.metadata.outputs.environment }}"
79136 runs-on : ubuntu-latest
@@ -95,36 +152,10 @@ jobs:
95152 with :
96153 terraform_version : ${{ needs.metadata.outputs.terraform_version }}
97154
98- - name : " Install Poetry"
99- run : |
100- curl -sSL https://install.python-poetry.org | python3 -
101- echo "$HOME/.local/bin" >> $GITHUB_PATH
102-
103- - name : " Set up Python"
104- uses : actions/setup-python@v6
105- with :
106- python-version : " 3.13"
107- cache : ' poetry'
108-
109- - name : " Install dependencies"
110- run : poetry install
111-
112- - name : " Build lambda artefact"
113- shell : bash
114- run : |
115- make dependencies install-python
116- make build
117-
118- - name : " Upload lambda artefact"
119- uses : actions/upload-artifact@v4
120- with :
121- name : lambda
122- path : dist/lambda.zip
123-
124- - name : " Download Built Lambdas"
155+ - name : " Download Lambda Artifact"
125156 uses : actions/download-artifact@v5
126157 with :
127- name : lambda
158+ name : lambda-${{ needs.metadata.outputs.tag }}
128159 path : ./build
129160
130161 - name : " Configure AWS Credentials"
@@ -153,6 +184,19 @@ jobs:
153184 echo "Running: make terraform env=$ENVIRONMENT workspace=$WORKSPACE stack=api-layer tf-command=apply"
154185 make terraform env=$ENVIRONMENT stack=api-layer tf-command=apply workspace=$WORKSPACE
155186
187+ - name : " Extract S3 bucket name from Terraform output"
188+ id : tf_output
189+ run : |
190+ BUCKET=$(terraform output -raw lambda_artifact_bucket)
191+ echo "bucket_name=$BUCKET" >> $GITHUB_OUTPUT
192+ working-directory : ./infrastructure/stacks/api-layer
193+
194+ - name : " Upload lambda artifact to S3"
195+ run : |
196+ aws s3 cp ./build/lambda.zip \
197+ s3://${{ steps.tf_output.outputs.bucket_name }}/artifacts/${{ needs.metadata.outputs.tag }}/lambda.zip \
198+ --region eu-west-2
199+
156200 - name : " Validate Feature Toggles"
157201 env :
158202 ENV : ${{ needs.metadata.outputs.environment }}
0 commit comments