feat: initial version of the new workflows #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 'CI/CD pull request' | ||
|
Check failure on line 1 in .github/workflows/cicd-1-pull-request-devtest.yaml
|
||
| on: | ||
| push: | ||
| tags: | ||
| - 'devtest' | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| pull-requests: write | ||
| jobs: | ||
| metadata: | ||
| name: "Set CI/CD metadata" | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 1 | ||
| permissions: | ||
| pull-requests: read | ||
| outputs: | ||
| build_datetime_london: ${{ steps.variables.outputs.build_datetime_london }} | ||
| 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 }} | ||
| environment_tag: ${{ steps.variables.outputs.environment_tag }} | ||
| version: ${{ steps.variables.outputs.version }} | ||
| does_pull_request_exist: ${{ steps.pr_exists.outputs.does_pull_request_exist }} | ||
| steps: | ||
| - name: "Checkout code" | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| submodules: 'true' | ||
| - name: "Set CI/CD variables" | ||
| id: variables | ||
| run: | | ||
| datetime=$(date -u +'%Y-%m-%dT%H:%M:%S%z') | ||
| BUILD_DATETIME=$datetime make version-create-effective-file | ||
| echo "build_datetime_london=$(TZ=Europe/London date --date=$datetime +'%Y-%m-%dT%H:%M:%S%z')" >> $GITHUB_OUTPUT | ||
| echo "build_datetime=$datetime" >> $GITHUB_OUTPUT | ||
| echo "build_timestamp=$(date --date=$datetime -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT | ||
| echo "build_epoch=$(date --date=$datetime -u +'%s')" >> $GITHUB_OUTPUT | ||
| echo "nodejs_version=$(grep "^nodejs" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT | ||
| echo "python_version=$(grep "^nodejs" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT | ||
| echo "terraform_version=$(grep "^terraform" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT | ||
| echo "version=$(head -n 1 .version 2> /dev/null || echo unknown)" >> $GITHUB_OUTPUT | ||
| echo "environment_tag=development" >> $GITHUB_OUTPUT | ||
| - name: "Check if pull request exists for this branch" | ||
| id: pr_exists | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| branch_name=${GITHUB_HEAD_REF:-$(echo $GITHUB_REF | sed 's#refs/heads/##')} | ||
| echo "Current branch is '$branch_name'" | ||
| if gh pr list --head $branch_name | grep -q .; then | ||
| echo "Pull request exists" | ||
| echo "does_pull_request_exist=true" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "Pull request doesn't exist" | ||
| echo "does_pull_request_exist=false" >> $GITHUB_OUTPUT | ||
| fi | ||
| - name: "List variables" | ||
| run: | | ||
| export BUILD_DATETIME_LONDON="${{ steps.variables.outputs.build_datetime_london }}" | ||
| 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 ENVIRONMENT_TAG="${{ steps.variables.outputs.environment_tag }}" | ||
| export VERSION="${{ steps.variables.outputs.version }}" | ||
| export DOES_PULL_REQUEST_EXIST="${{ steps.pr_exists.outputs.does_pull_request_exist }}" | ||
| make list-variables | ||
| commit-stage: # Recommended maximum execution time is 2 minutes | ||
| name: "Commit stage" | ||
| needs: [metadata] | ||
| uses: ./.github/workflows/stage-1-commit.yaml | ||
| with: | ||
| build_datetime: "${{ needs.metadata.outputs.build_datetime }}" | ||
| build_timestamp: "${{ needs.metadata.outputs.build_timestamp }}" | ||
| build_epoch: "${{ needs.metadata.outputs.build_epoch }}" | ||
| nodejs_version: "${{ needs.metadata.outputs.nodejs_version }}" | ||
| python_version: "${{ needs.metadata.outputs.python_version }}" | ||
| terraform_version: "${{ needs.metadata.outputs.terraform_version }}" | ||
| version: "${{ needs.metadata.outputs.version }}" | ||
| test-stage: # Recommended maximum execution time is 5 minutes | ||
| name: 'Test stage' | ||
| needs: [metadata] | ||
| uses: ./.github/workflows/stage-2-test.yaml | ||
| with: | ||
| build_datetime: '${{ needs.metadata.outputs.build_datetime }}' | ||
| build_timestamp: '${{ needs.metadata.outputs.build_timestamp }}' | ||
| build_epoch: '${{ needs.metadata.outputs.build_epoch }}' | ||
| nodejs_version: '${{ needs.metadata.outputs.nodejs_version }}' | ||
| python_version: '${{ needs.metadata.outputs.python_version }}' | ||
| terraform_version: '${{ needs.metadata.outputs.terraform_version }}' | ||
| version: '${{ needs.metadata.outputs.version }}' | ||
| secrets: inherit | ||
| analysis-stage: # Recommended maximum execution time is 5 minutes | ||
| name: "Analysis stage" | ||
| needs: [metadata, commit-stage, test-stage] | ||
| uses: ./.github/workflows/stage-2-analyse.yaml | ||
| secrets: | ||
| sonar_token: ${{ secrets.SONAR_TOKEN }} | ||
| with: | ||
| unit_test_dir: tests/UnitTests | ||
| build_datetime: "${{ needs.metadata.outputs.build_datetime }}" | ||
| build_timestamp: "${{ needs.metadata.outputs.build_timestamp }}" | ||
| build_epoch: "${{ needs.metadata.outputs.build_epoch }}" | ||
| nodejs_version: "${{ needs.metadata.outputs.nodejs_version }}" | ||
| python_version: "${{ needs.metadata.outputs.python_version }}" | ||
| terraform_version: "${{ needs.metadata.outputs.terraform_version }}" | ||
| version: "${{ needs.metadata.outputs.version }}" | ||
| build-image-stage: # Recommended maximum execution time is 3 minutes | ||
| name: "Image build stage" | ||
| needs: [metadata, commit-stage, test-stage, analysis-stage] | ||
| uses: ./.github/workflows/stage-3-build-images-devtest.yaml | ||
| secrets: | ||
| client_id: ${{ secrets.AZURE_CLIENT_ID }} | ||
| tenant_id: ${{ secrets.AZURE_TENANT_ID }} | ||
| subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | ||
| acr_name: ${{ secrets.ACR_NAME }} | ||
| if: needs.metadata.outputs.does_pull_request_exist == 'true' || (github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened')) | ||
| with: | ||
| docker_compose_file: application/CohortManager/compose.yaml | ||
| excluded_containers_csv_list: azurite,azurite-setup,sql-server | ||
| environment_tag: ${{ needs.metadata.outputs.environment_tag }} | ||
| function_app_source_code_path: application/CohortManager/src | ||
| project_name: cohort-manager | ||
| build_all_images: true | ||
| deploy-stage: | ||
| if: contains(github.event.pull_request.labels.*.name, 'deploy') | ||
| name: Deploy review app pr-${{ github.event.pull_request.number }} | ||
| needs: [build-stage] | ||
| permissions: | ||
| id-token: write | ||
| uses: ./.github/workflows/stage-4-deploy.yaml | ||
| with: | ||
| environments: '["review"]' | ||
| commit_sha: ${{ github.event.pull_request.head.sha }} | ||
| pr_number: ${{ github.event.pull_request.number }} | ||
| secrets: inherit | ||
| post-url: | ||
| if: contains(github.event.pull_request.labels.*.name, 'deploy') | ||
| name: Post URL pr-${{ github.event.pull_request.number }} to PR comments | ||
| runs-on: ubuntu-latest | ||
| needs: [deploy-stage] | ||
| permissions: | ||
| pull-requests: write | ||
| steps: | ||
| - name: Post URL to PR comments | ||
| uses: marocchino/sticky-pull-request-comment@5060d4700a91de252c87eeddd2da026382d9298a | ||
| with: | ||
| message: | | ||
| The review app is available at this URL: | ||
| https://pr-${{ github.event.pull_request.number }}.manage-breast-screening.non-live.screening.nhs.uk | ||
| You must authenticate with HTTP basic authentication. Ask the team for credentials. | ||