1+ # Description: Deploys merged code to the dev environment.
2+ # Triggered on push to main. Tags the commit with a dev-<timestamp> label.
3+ # Does not create GitHub Releases or production tags (v1.x.x).
4+
15name : " CI/CD publish"
26
37on :
4- pull_request :
5- types : [closed]
8+ push :
69 branches :
710 - main
811
912jobs :
1013 metadata :
1114 name : " Set CI/CD metadata"
1215 runs-on : ubuntu-latest
13- if : github.event.pull_request.merged == true
1416 timeout-minutes : 1
1517 outputs :
1618 build_datetime : ${{ steps.variables.outputs.build_datetime }}
2325 steps :
2426 - name : " Checkout code"
2527 uses : actions/checkout@v4
28+
2629 - name : " Set CI/CD variables"
2730 id : variables
2831 run : |
@@ -33,52 +36,105 @@ jobs:
3336 echo "nodejs_version=$(grep "^nodejs" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
3437 echo "python_version=$(grep "^nodejs" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
3538 echo "terraform_version=$(grep "^terraform" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
36- # TODO: Get the version, but it may not be the .version file as this should come from the CI/CD Pull Request Workflow
37- echo "version=$(head -n 1 .version 2> /dev/null || echo unknown)" >> $GITHUB_OUTPUT
39+ echo " version=dev-$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
40+
3841 - name : " List variables"
3942 run : |
40- export BUILD_DATETIME="${{ steps.variables.outputs.build_datetime }}"
41- export BUILD_TIMESTAMP="${{ steps.variables.outputs.build_timestamp }}"
42- export BUILD_EPOCH="${{ steps.variables.outputs.build_epoch }}"
43- export NODEJS_VERSION="${{ steps.variables.outputs.nodejs_version }}"
44- export PYTHON_VERSION="${{ steps.variables.outputs.python_version }}"
45- export TERRAFORM_VERSION="${{ steps.variables.outputs.terraform_version }}"
46- export VERSION="${{ steps.variables.outputs.version }}"
47- make list-variables
43+ echo "Deploying to: DEV"
44+ echo "VERSION=${{ steps.variables.outputs.version }}"
45+
4846 publish :
49- name : " Publish packages "
47+ name : " Publish to dev "
5048 runs-on : ubuntu-latest
5149 needs : [metadata]
52- if : github.event.pull_request.merged == true
53- timeout-minutes : 3
50+ timeout-minutes : 10
51+ permissions :
52+ id-token : write
53+ contents : read
5454 steps :
55- - name : " Checkout code"
55+ - name : " Setup Terraform"
56+ uses : hashicorp/setup-terraform@v3
57+ with :
58+ terraform_version : ${{ needs.metadata.outputs.terraform_version }}
59+
60+ - name : " Set up Python"
61+ uses : actions/setup-python@v5
62+ with :
63+ python-version : ' 3.13'
64+
65+ - name : " Checkout Repository"
5666 uses : actions/checkout@v4
57- - name : " Get the artefacts"
67+
68+ - name : " Build lambda artefact"
5869 run : |
59- echo "Getting the artefacts created by the build stage ..."
60- # TODO: Use either action/cache or action/upload-artifact
61- - name : " Create release"
62- id : create_release
63- uses : actions/create-release@v1
64- env :
65- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
70+ make dependencies install-python
71+ make build
72+
73+ - name : " Upload lambda artefact"
74+ uses : actions/upload-artifact@v4
75+ with :
76+ name : lambda
77+ path : dist/lambda.zip
78+
79+ - name : " Download Built Lambdas"
80+ uses : actions/download-artifact@v4
6681 with :
67- tag_name : ${{ needs.metadata.outputs.version }}
68- release_name : Release ${{ needs.metadata.outputs.version }}
69- body : |
70- Release of ${{ needs.metadata.outputs.version }}
71- draft : false
72- prerelease : false
82+ name : lambda
83+ path : ./build
84+
85+ - name : " Configure AWS Credentials"
86+ uses : aws-actions/configure-aws-credentials@v4
87+ with :
88+ role-to-assume : arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/service-roles/github-actions-dev-deployment-role
89+ aws-region : eu-west-2
90+
91+ - name : " Terraform Plan Stacks"
92+ env :
93+ ENVIRONMENT : dev
94+ WORKSPACE : " default"
95+ TF_VAR_API_CA_CERT : ${{ secrets.API_CA_CERT }}
96+ TF_VAR_API_CLIENT_CERT : ${{ secrets.API_CLIENT_CERT }}
97+ TF_VAR_API_PRIVATE_KEY_CERT : ${{ secrets.API_PRIVATE_KEY_CERT }}
98+
99+ # just planning for now for safety and until review
100+ run : |
101+ mkdir -p ./build
102+ echo "Running: make terraform env=$ENVIRONMENT workspace=$WORKSPACE stack=networking tf-command=plan"
103+ make terraform env=$ENVIRONMENT stack=networking tf-command=plan workspace=$WORKSPACE
104+ echo "Running: make terraform env=$ENVIRONMENT workspace=$WORKSPACE stack=api-layer tf-command=plan"
105+ make terraform env=$ENVIRONMENT stack=api-layer tf-command=plan workspace=$WORKSPACE
106+ working-directory : ./infrastructure
107+
108+ - name : " Tag the dev deployment"
109+ run : |
110+ git config user.name "github-actions"
111+ git config user.email "[email protected] " 112+ git tag ${{ needs.metadata.outputs.version }}
113+ git push origin ${{ needs.metadata.outputs.version }}
114+
115+ # --- Keeping these just in case: Uncomment to release to GitHub ---
116+ # - name: "Create release"
117+ # id: create_release
118+ # uses: actions/create-release@v1
119+ # env:
120+ # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
121+ # with:
122+ # tag_name: ${{ needs.metadata.outputs.version }}
123+ # release_name: Release ${{ needs.metadata.outputs.version }}
124+ # body: |
125+ # Release of ${{ needs.metadata.outputs.version }}
126+ # draft: false
127+ # prerelease: true
128+
73129 # - name: "Upload release asset"
74130 # uses: actions/upload-release-asset@v1
75131 # env:
76132 # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77133 # with:
78134 # upload_url: "${{ steps.create_release.outputs.upload_url }}"
79- # asset_path: ./*
80- # asset_name: repository-template- ${{ needs.metadata.outputs.version }}.tar.gz
81- # asset_content_type: " application/gzip"
135+ # asset_path: ./build/lambda.zip
136+ # asset_name: lambda- ${{ needs.metadata.outputs.version }}.zip
137+ # asset_content_type: application/zip
82138 success :
83139 name : " Success notification"
84140 runs-on : ubuntu-latest
0 commit comments