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 }}
36+ promoted_environment : ${{ steps.promoted_env.outputs.promoted_environment }}
3537 steps :
3638 - name : " Checkout ref"
3739 uses : actions/checkout@v5
7476 echo "ref=$REF"
7577 echo "environment=$ENVIRONMENT"
7678
79+ - name : " Resolve the dev-* tag for this commit"
80+ id : tag
81+ run : |
82+ git fetch --tags --force
83+ SHA="${{ github.event.workflow_run.head_sha }}"
84+ TAG=$(git tag --points-at "$SHA" | grep '^dev-' | head -n1 || true)
85+ if [ -z "$TAG" ]; then
86+ echo "No dev-* tag found on $SHA" >&2
87+ exit 1
88+ fi
89+ echo "name=$TAG" >> $GITHUB_OUTPUT
90+ echo "Resolved tag: $TAG"
91+
92+ - name : " Resolve promoted environment"
93+ id : promoted_env
94+ run : |
95+ ENV="${{ steps.variables.outputs.environment }}"
96+ if [[ "$ENV" == "preprod" ]]; then
97+ echo "promoted_environment=test" >> $GITHUB_OUTPUT
98+ elif [[ "$ENV" == "prod" ]]; then
99+ echo "promoted_environment=preprod" >> $GITHUB_OUTPUT
100+ else
101+ echo "promoted_environment=$ENV" >> $GITHUB_OUTPUT
102+ fi
103+
104+ download-lambda-artifact :
105+ name : " Fetch the lambda artifact from previous stage"
106+ runs-on : ubuntu-latest
107+ needs : [metadata]
108+ timeout-minutes : 45
109+ permissions :
110+ id-token : write
111+ contents : write
112+ environment : ${{ needs.metadata.outputs.promoted_environment }}
113+ steps :
114+ - name : " Checkout repository at ref"
115+ uses : actions/checkout@v5
116+ with :
117+ ref : ${{ needs.metadata.outputs.ref }}
118+ fetch-depth : 0
119+
120+ - name : " Configure AWS Credentials"
121+ uses : aws-actions/configure-aws-credentials@v5
122+ with :
123+ role-to-assume : arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/service-roles/github-actions-api-deployment-role
124+ aws-region : eu-west-2
125+
126+ - name : " Extract S3 bucket name from Terraform output"
127+ id : tf_output
128+ run : |
129+ BUCKET=$(terraform output -raw lambda_artifact_bucket)
130+ echo "bucket_name=$BUCKET" >> $GITHUB_OUTPUT
131+ working-directory : ./infrastructure/stacks/api-layer
132+
133+ - name : " Download lambda artifact from S3"
134+ run : |
135+ aws s3 cp \
136+ s3://${{ steps.tf_output.outputs.bucket_name }}/artifacts/${{ needs.metadata.outputs.tag }}/lambda.zip \
137+ ./build/lambda.zip \
138+ --region eu-west-2
139+
140+ - name : " Upload lambda artifact for the current workflow"
141+ uses : actions/upload-artifact@v4
142+ with :
143+ name : lambda-${{ needs.metadata.outputs.tag }}
144+ path : ./build/lambda.zip
145+
146+
77147 deploy :
78148 name : " Deploy to ${{ needs.metadata.outputs.environment }}"
79149 runs-on : ubuntu-latest
@@ -95,36 +165,10 @@ jobs:
95165 with :
96166 terraform_version : ${{ needs.metadata.outputs.terraform_version }}
97167
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"
168+ - name : " Download Lambda Artifact"
125169 uses : actions/download-artifact@v5
126170 with :
127- name : lambda
171+ name : lambda-${{ needs.metadata.outputs.tag }}
128172 path : ./build
129173
130174 - name : " Configure AWS Credentials"
@@ -153,6 +197,19 @@ jobs:
153197 echo "Running: make terraform env=$ENVIRONMENT workspace=$WORKSPACE stack=api-layer tf-command=apply"
154198 make terraform env=$ENVIRONMENT stack=api-layer tf-command=apply workspace=$WORKSPACE
155199
200+ - name : " Extract S3 bucket name from Terraform output"
201+ id : tf_output
202+ run : |
203+ BUCKET=$(terraform output -raw lambda_artifact_bucket)
204+ echo "bucket_name=$BUCKET" >> $GITHUB_OUTPUT
205+ working-directory : ./infrastructure/stacks/api-layer
206+
207+ - name : " Upload lambda artifact to S3"
208+ run : |
209+ aws s3 cp ./build/lambda.zip \
210+ s3://${{ steps.tf_output.outputs.bucket_name }}/artifacts/${{ needs.metadata.outputs.tag }}/lambda.zip \
211+ --region eu-west-2
212+
156213 - name : " Validate Feature Toggles"
157214 env :
158215 ENV : ${{ needs.metadata.outputs.environment }}
0 commit comments