|
1 | | -name: CI/CD pull request - devtest |
| 1 | +name: 'CI/CD pull request - devtest' |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | tags: |
6 | 6 | - 'devtest' |
7 | 7 |
|
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + id-token: write |
| 11 | + pull-requests: write |
| 12 | + |
8 | 13 | jobs: |
9 | | - print-debug-info: |
| 14 | + metadata: |
| 15 | + name: "Set CI/CD metadata" |
10 | 16 | runs-on: ubuntu-latest |
| 17 | + timeout-minutes: 1 |
| 18 | + permissions: |
| 19 | + pull-requests: read |
| 20 | + outputs: |
| 21 | + build_datetime_london: ${{ steps.variables.outputs.build_datetime_london }} |
| 22 | + build_datetime: ${{ steps.variables.outputs.build_datetime }} |
| 23 | + build_timestamp: ${{ steps.variables.outputs.build_timestamp }} |
| 24 | + build_epoch: ${{ steps.variables.outputs.build_epoch }} |
| 25 | + nodejs_version: ${{ steps.variables.outputs.nodejs_version }} |
| 26 | + python_version: ${{ steps.variables.outputs.python_version }} |
| 27 | + terraform_version: ${{ steps.variables.outputs.terraform_version }} |
| 28 | + environment_tag: ${{ steps.variables.outputs.environment_tag }} |
| 29 | + version: ${{ steps.variables.outputs.version }} |
| 30 | + does_pull_request_exist: ${{ steps.pr_exists.outputs.does_pull_request_exist }} |
11 | 31 | steps: |
12 | | - - name: Display Information |
| 32 | + - name: "Checkout code" |
| 33 | + uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + submodules: 'true' |
| 36 | + - name: "Set CI/CD variables" |
| 37 | + id: variables |
| 38 | + run: | |
| 39 | + datetime=$(date -u +'%Y-%m-%dT%H:%M:%S%z') |
| 40 | + BUILD_DATETIME=$datetime make version-create-effective-file |
| 41 | + echo "build_datetime_london=$(TZ=Europe/London date --date=$datetime +'%Y-%m-%dT%H:%M:%S%z')" >> $GITHUB_OUTPUT |
| 42 | + echo "build_datetime=$datetime" >> $GITHUB_OUTPUT |
| 43 | + echo "build_timestamp=$(date --date=$datetime -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT |
| 44 | + echo "build_epoch=$(date --date=$datetime -u +'%s')" >> $GITHUB_OUTPUT |
| 45 | + echo "nodejs_version=$(grep "^nodejs" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT |
| 46 | + echo "python_version=$(grep "^nodejs" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT |
| 47 | + echo "terraform_version=$(grep "^terraform" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT |
| 48 | + echo "version=$(head -n 1 .version 2> /dev/null || echo unknown)" >> $GITHUB_OUTPUT |
| 49 | + echo "environment_tag=development" >> $GITHUB_OUTPUT |
| 50 | + - name: "Check if pull request exists for this branch" |
| 51 | + id: pr_exists |
| 52 | + env: |
| 53 | + GH_TOKEN: ${{ github.token }} |
| 54 | + run: | |
| 55 | + branch_name=${GITHUB_HEAD_REF:-$(echo $GITHUB_REF | sed 's#refs/heads/##')} |
| 56 | + echo "Current branch is '$branch_name'" |
| 57 | + if gh pr list --head $branch_name | grep -q .; then |
| 58 | + echo "Pull request exists" |
| 59 | + echo "does_pull_request_exist=true" >> $GITHUB_OUTPUT |
| 60 | + else |
| 61 | + echo "Pull request doesn't exist" |
| 62 | + echo "does_pull_request_exist=false" >> $GITHUB_OUTPUT |
| 63 | + fi |
| 64 | + - name: "List variables" |
13 | 65 | run: | |
14 | | - echo "Workflow triggered by tag!" |
15 | | - echo "--------------------------------------" |
16 | | - echo "Tag/Ref Name : $GITHUB_REF" |
17 | | - echo "Commit Hash : $GITHUB_SHA" |
18 | | - echo "Triggered By : $GITHUB_ACTOR" |
19 | | - echo "Event Name : $GITHUB_EVENT_NAME" |
20 | | - echo "--------------------------------------" |
| 66 | + export BUILD_DATETIME_LONDON="${{ steps.variables.outputs.build_datetime_london }}" |
| 67 | + export BUILD_DATETIME="${{ steps.variables.outputs.build_datetime }}" |
| 68 | + export BUILD_TIMESTAMP="${{ steps.variables.outputs.build_timestamp }}" |
| 69 | + export BUILD_EPOCH="${{ steps.variables.outputs.build_epoch }}" |
| 70 | + export NODEJS_VERSION="${{ steps.variables.outputs.nodejs_version }}" |
| 71 | + export PYTHON_VERSION="${{ steps.variables.outputs.python_version }}" |
| 72 | + export TERRAFORM_VERSION="${{ steps.variables.outputs.terraform_version }}" |
| 73 | + export ENVIRONMENT_TAG="${{ steps.variables.outputs.environment_tag }}" |
| 74 | + export VERSION="${{ steps.variables.outputs.version }}" |
| 75 | + export DOES_PULL_REQUEST_EXIST="${{ steps.pr_exists.outputs.does_pull_request_exist }}" |
| 76 | + make list-variables |
| 77 | + commit-stage: # Recommended maximum execution time is 2 minutes |
| 78 | + name: "Commit stage" |
| 79 | + needs: [metadata] |
| 80 | + uses: ./.github/workflows/stage-1-commit.yaml |
| 81 | + with: |
| 82 | + build_datetime: "${{ needs.metadata.outputs.build_datetime }}" |
| 83 | + build_timestamp: "${{ needs.metadata.outputs.build_timestamp }}" |
| 84 | + build_epoch: "${{ needs.metadata.outputs.build_epoch }}" |
| 85 | + nodejs_version: "${{ needs.metadata.outputs.nodejs_version }}" |
| 86 | + python_version: "${{ needs.metadata.outputs.python_version }}" |
| 87 | + terraform_version: "${{ needs.metadata.outputs.terraform_version }}" |
| 88 | + version: "${{ needs.metadata.outputs.version }}" |
| 89 | + test-stage: # Recommended maximum execution time is 5 minutes |
| 90 | + name: 'Test stage' |
| 91 | + needs: [metadata] |
| 92 | + uses: ./.github/workflows/stage-2-test.yaml |
| 93 | + with: |
| 94 | + unit_test_dir: tests/UnitTests |
| 95 | + app_dir: application/CohortManager |
| 96 | + build_datetime: '${{ needs.metadata.outputs.build_datetime }}' |
| 97 | + build_timestamp: '${{ needs.metadata.outputs.build_timestamp }}' |
| 98 | + build_epoch: '${{ needs.metadata.outputs.build_epoch }}' |
| 99 | + nodejs_version: '${{ needs.metadata.outputs.nodejs_version }}' |
| 100 | + python_version: '${{ needs.metadata.outputs.python_version }}' |
| 101 | + terraform_version: '${{ needs.metadata.outputs.terraform_version }}' |
| 102 | + version: '${{ needs.metadata.outputs.version }}' |
| 103 | + secrets: inherit |
| 104 | + analysis-stage: # Recommended maximum execution time is 5 minutes |
| 105 | + name: "Analysis stage" |
| 106 | + needs: [metadata, commit-stage, test-stage] |
| 107 | + uses: ./.github/workflows/stage-2-analyse.yaml |
| 108 | + secrets: |
| 109 | + sonar_token: ${{ secrets.SONAR_TOKEN }} |
| 110 | + with: |
| 111 | + unit_test_dir: tests/UnitTests |
| 112 | + build_datetime: "${{ needs.metadata.outputs.build_datetime }}" |
| 113 | + build_timestamp: "${{ needs.metadata.outputs.build_timestamp }}" |
| 114 | + build_epoch: "${{ needs.metadata.outputs.build_epoch }}" |
| 115 | + nodejs_version: "${{ needs.metadata.outputs.nodejs_version }}" |
| 116 | + python_version: "${{ needs.metadata.outputs.python_version }}" |
| 117 | + terraform_version: "${{ needs.metadata.outputs.terraform_version }}" |
| 118 | + version: "${{ needs.metadata.outputs.version }}" |
| 119 | + build-image-stage: # Recommended maximum execution time is 3 minutes |
| 120 | + name: "Image build stage" |
| 121 | + needs: [metadata, commit-stage, test-stage, analysis-stage] |
| 122 | + uses: ./.github/workflows/stage-3-build-images-devtest.yaml |
| 123 | + secrets: |
| 124 | + client_id: ${{ secrets.AZURE_CLIENT_ID }} |
| 125 | + tenant_id: ${{ secrets.AZURE_TENANT_ID }} |
| 126 | + subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
| 127 | + acr_name: ${{ secrets.ACR_NAME }} |
| 128 | + with: |
| 129 | + docker_compose_file: application/CohortManager/compose.yaml |
| 130 | + excluded_containers_csv_list: azurite,azurite-setup,sql-server |
| 131 | + environment_tag: ${{ needs.metadata.outputs.environment_tag }} |
| 132 | + function_app_source_code_path: application/CohortManager/src |
| 133 | + project_name: cohort-manager |
| 134 | + build_all_images: true |
| 135 | + deploy-stage: |
| 136 | + if: github.event_name == 'push' |
| 137 | + name: Deploy DevTest environment for commit ${{ github.sha }} |
| 138 | + needs: [metadata, build-image-stage] |
| 139 | + permissions: |
| 140 | + id-token: write |
| 141 | + contents: read |
| 142 | + uses: ./.github/workflows/stage-4-deploy-devtest.yaml |
| 143 | + secrets: |
| 144 | + client_id: ${{ secrets.AZURE_CLIENT_ID }} |
| 145 | + tenant_id: ${{ secrets.AZURE_TENANT_ID }} |
| 146 | + subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
| 147 | + with: |
| 148 | + environments: "[\"development\"]" |
| 149 | + commit_sha: ${{ github.sha }} |
| 150 | + name: Validate PR title |
| 151 | + runs-on: ubuntu-latest |
| 152 | + permissions: |
| 153 | + pull-requests: write |
| 154 | + env: |
| 155 | + GITHUB_TOKEN: ${{ github.token }} |
| 156 | + if: github.event_name == 'push' |
| 157 | + steps: |
| 158 | + - uses: amannn/action-semantic-pull-request@v5 |
| 159 | + id: validate |
| 160 | + - uses: thollander/actions-comment-pull-request@v2 |
| 161 | + if: ${{ failure() && steps.validate.conclusion == 'failure' }} |
| 162 | + with: |
| 163 | + message: | |
| 164 | + Your Pull Request title must meet the conventional commit standards, please see the following documentation - https://www.conventionalcommits.org/en/v1.0.0/#specification |
0 commit comments