Skip to content

CI/CD deploy

CI/CD deploy #299

Workflow file for this run

name: "CI/CD deploy"
on:
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy to'
type: environment
required: true
env:
AWS_REGION: eu-west-2
jobs:
metadata:
name: "Set CI/CD metadata"
runs-on: ubuntu-latest
timeout-minutes: 1
outputs:
build_datetime: ${{ steps.variables.outputs.build_datetime }}
build_timestamp: ${{ steps.variables.outputs.build_timestamp }}
build_epoch: ${{ steps.variables.outputs.build_epoch }}
nodejs_version: ${{ steps.variables.outputs.nodejs_version }}
python_version: ${{ steps.variables.outputs.python_version }}
terraform_version: ${{ steps.variables.outputs.terraform_version }}
version: ${{ steps.variables.outputs.version }}
tag: ${{ steps.variables.outputs.tag }}
steps:
- name: "Check ref"
run: |
if ${{ !startsWith(github.ref, 'refs/tags/') }}; then
echo "❌ Only tagged deployments allowed."
exit 1
fi
- name: "Checkout code"
uses: actions/checkout@v5
- name: "Set CI/CD variables"
id: variables
run: |
datetime=$(date -u +'%Y-%m-%dT%H:%M:%S%z')
echo "build_datetime=$datetime" | tee -a $GITHUB_OUTPUT
echo "build_timestamp=$(date --date=$datetime -u +'%Y%m%d%H%M%S')" | tee -a $GITHUB_OUTPUT
echo "build_epoch=$(date --date=$datetime -u +'%s')" | tee -a $GITHUB_OUTPUT
echo "nodejs_version=$(grep "^nodejs" .tool-versions | cut -f2 -d' ')" | tee -a $GITHUB_OUTPUT
echo "python_version=$(grep "^nodejs" .tool-versions | cut -f2 -d' ')" | tee -a $GITHUB_OUTPUT
echo "terraform_version=$(grep "^terraform" .tool-versions | cut -f2 -d' ')" | tee -a $GITHUB_OUTPUT
# TODO: Get the version, but it may not be the .version file as this should come from the CI/CD Pull Request Workflow
echo "version=$(head -n 1 .version 2> /dev/null || echo unknown)" | tee -a $GITHUB_OUTPUT
echo "tag=${{ github.ref_name }}" | tee -a $GITHUB_OUTPUT
- name: "List variables"
run: |
export BUILD_DATETIME="${{ steps.variables.outputs.build_datetime }}"
export BUILD_TIMESTAMP="${{ steps.variables.outputs.build_timestamp }}"
export BUILD_EPOCH="${{ steps.variables.outputs.build_epoch }}"
export NODEJS_VERSION="${{ steps.variables.outputs.nodejs_version }}"
export PYTHON_VERSION="${{ steps.variables.outputs.python_version }}"
export TERRAFORM_VERSION="${{ steps.variables.outputs.terraform_version }}"
export VERSION="${{ steps.variables.outputs.version }}"
export TAG="${{ steps.variables.outputs.tag }}"
make list-variables
deploy-stage:
name: "Deploy stage"
needs: [metadata]
uses: ./.github/workflows/stage-4-deploy.yaml
with:
environment: ${{ github.event.inputs.environment }}
terraform_version: "${{ needs.metadata.outputs.terraform_version }}"
secrets: inherit
acceptance-stage:
name: "Acceptance stage"
if: ${{ contains(fromJSON('["dev","preprod"]'), github.event.inputs.environment) }}
needs: [metadata, deploy-stage]
uses: ./.github/workflows/stage-5-acceptance.yaml
with:
environment: ${{ github.event.inputs.environment}}
checkout_ref: ${{ github.ref }}
secrets: inherit