|
4 | 4 | workflow_dispatch: |
5 | 5 | inputs: |
6 | 6 | 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" |
8 | 8 | required: true |
9 | 9 | 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 |
10 | 18 |
|
11 | 19 | jobs: |
12 | 20 | metadata: |
|
23 | 31 | version: ${{ steps.variables.outputs.version }} |
24 | 32 | tag: ${{ steps.variables.outputs.tag }} |
25 | 33 | steps: |
26 | | - - name: "Checkout code" |
| 34 | + - name: "Checkout tag" |
27 | 35 | uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + ref: ${{ github.event.inputs.tag }} |
| 38 | + |
28 | 39 | - name: "Set CI/CD variables" |
29 | 40 | id: variables |
30 | 41 | run: | |
@@ -52,12 +63,85 @@ jobs: |
52 | 63 | deploy: |
53 | 64 | name: "Deploy to an environment" |
54 | 65 | runs-on: ubuntu-latest |
55 | | - needs: [metadata] |
| 66 | + needs: [ metadata ] |
56 | 67 | timeout-minutes: 10 |
| 68 | + permissions: |
| 69 | + id-token: write |
| 70 | + contents: read |
57 | 71 | 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 |
61 | 145 | # success: |
62 | 146 | # name: "Success notification" |
63 | 147 | # runs-on: ubuntu-latest |
|
0 commit comments