chore: adds all variables in versions.env to build and startup of tes… #1467
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: Frontend | |
| on: | |
| workflow_dispatch: | |
| workflow_run: | |
| workflows: [Infrastructure] | |
| types: completed | |
| branches: | |
| - dev | |
| - stage | |
| - main | |
| push: | |
| paths: | |
| - "frontend_svelte/**" | |
| - "compose*.yml" | |
| - ".github/workflows/frontend_svelte.yml" | |
| # pull_request: | |
| # paths: | |
| # - 'frontend/**' | |
| env: | |
| REGISTRY: ghcr.io | |
| COMMIT_SHA: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.sha }} | |
| jobs: | |
| test: | |
| runs-on: ubuntu-24.04 | |
| environment: test | |
| env: | |
| KEYVAULT_HEALTH: ${{ vars.KEYVAULT_HEALTH }} | |
| POSTGRES_HOST: ${{ vars.POSTGRES_HOST }} | |
| POSTGRES_USER: ${{ secrets.POSTGRES_USER }} | |
| POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} | |
| REDIS_HOST: ${{ vars.REDIS_HOST }} | |
| REDIS_PORT: ${{ vars.REDIS_PORT }} | |
| MONGODB_HOST: ${{ vars.MONGODB_HOST }} | |
| MONGODB_PORT: ${{ vars.MONGODB_PORT }} | |
| FRONTEND_SVELTE_CLIENT_ID: ${{ secrets.FRONTEND_SVELTE_CLIENT_ID }} | |
| FRONTEND_SVELTE_CLIENT_SECRET: ${{ secrets.FRONTEND_SVELTE_CLIENT_SECRET }} | |
| AZ_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} | |
| API_SCOPE: ${{ secrets.API_SCOPE }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Build | |
| run: | | |
| docker compose \ | |
| --env-file versions.env \ | |
| -f compose.yml \ | |
| -f compose.override.test.yml \ | |
| build frontend_svelte | |
| - name: Spin up containers | |
| run: | | |
| docker compose \ | |
| --env-file versions.env \ | |
| -f compose.yml \ | |
| -f compose.override.test.yml \ | |
| up frontend_svelte -d | |
| # - name: run inside the container and show content | |
| # run: | | |
| # docker compose \ | |
| # -f compose.yml \ | |
| # -f compose.override.test.yml \ | |
| # run --rm frontend_svelte \ | |
| # sh -c "ls -la node_modules" | |
| # - name: show image contents | |
| # run: | | |
| # docker compose \ | |
| # -f compose.yml \ | |
| # -f compose.override.test.yml \ | |
| # exec -T frontend_svelte \ | |
| # sh -c "ls -la node_modules" | |
| # TBD change all commands to docker compose run - as the container is up and runnig already! | |
| - name: Code Formating | |
| run: | | |
| docker compose \ | |
| --env-file versions.env \ | |
| -f compose.yml \ | |
| -f compose.override.test.yml \ | |
| exec -T frontend_svelte \ | |
| sh -c "bun format" | |
| - name: Linting | |
| run: | | |
| docker compose \ | |
| --env-file versions.env \ | |
| -f compose.yml \ | |
| -f compose.override.test.yml \ | |
| exec -T frontend_svelte \ | |
| sh -c "bun lint" | |
| - name: Unit testing | |
| run: | | |
| docker compose \ | |
| --env-file versions.env \ | |
| -f compose.yml \ | |
| -f compose.override.test.yml \ | |
| exec -T frontend_svelte \ | |
| sh -c "bun test:unit" | |
| - name: Type checking | |
| run: | | |
| docker compose \ | |
| --env-file versions.env \ | |
| -f compose.yml \ | |
| -f compose.override.test.yml \ | |
| exec -T frontend_svelte \ | |
| sh -c "bun check" | |
| - name: Stop containers | |
| run: | | |
| docker compose \ | |
| --env-file versions.env \ | |
| -f compose.yml \ | |
| -f compose.override.test.yml \ | |
| down | |
| check_for_infrastructure_change: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 2 | |
| - name: echos github variables | |
| run: | | |
| echo "=== github.ref ===" | |
| echo ${{ github.ref }} | |
| echo "=== github.ref_type ===" | |
| echo ${{ github.ref_type }} | |
| echo "=== github.event.workflow_run.head_sha ===" | |
| echo ${{ github.event.workflow_run.head_sha }} | |
| echo "=== github.event_name ===" | |
| echo ${{ github.event_name }} | |
| echo "=== github.sha ===" | |
| echo ${{ github.sha }} | |
| echo "=== github.event.after ===" | |
| echo ${{ github.event.after }} | |
| echo "=== Environment variable: COMMIT_SHA ===" | |
| echo $COMMIT_SHA | |
| - name: Check for infrastructure changes | |
| id: check_for_infrastructure_change | |
| # replace --exit-code with --quite for less output on console if necessary! | |
| run: | | |
| if git diff --exit-code HEAD^ HEAD -- infrastructure/ .github/workflows/infrastructure.yml; then | |
| echo "No infrastructure changes detected." | |
| echo "infrastructure_changed=FALSE" >> $GITHUB_OUTPUT | |
| else | |
| echo "Infrastructure changes detected." | |
| echo "infrastructure_changed=TRUE" >> $GITHUB_OUTPUT | |
| fi | |
| echo "=== Contents of $GITHUB_OUTPUT ===" | |
| cat $GITHUB_OUTPUT | |
| outputs: | |
| infrastructure_changed: ${{ steps.check_for_infrastructure_change.outputs.infrastructure_changed }} | |
| containerize: | |
| # if: ${{ github.event.ref == 'refs/heads/main' || github.event.ref == 'refs/heads/stage' }} | |
| # only run on stage and main branch | |
| # only run if no infrastructure changes were detected, but do run, if the workflow was triggered by a workflow_run event (then the github.event.workflow_run.head_sha is not null) | |
| # TBD: split into multiline if statement: | |
| if: ${{((github.event.ref == 'refs/heads/main' || github.event.ref == 'refs/heads/stage') && needs.check_for_infrastructure_change.outputs.infrastructure_changed == 'FALSE' ) || ( ( github.event.workflow_run.head_branch == 'main' || github.event.workflow_run.head_branch == 'stage' ) && github.event.workflow_run.name == 'Infrastructure' && github.event.workflow_run.conclusion == 'success') }} | |
| needs: [test, check_for_infrastructure_change] | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| id-token: write | |
| contents: read | |
| packages: write | |
| environment: stage | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.event.workflow_run.head_sha }} | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build for production | |
| run: | | |
| docker compose --env-file versions.env -f compose.yml -f compose.prod.yml build --build-arg COMMIT_SHA=${{env.COMMIT_SHA}} frontend_svelte | |
| - name: Show images | |
| run: docker image list | |
| - name: Tag and push with latest and commit hash | |
| run: | | |
| docker tag \ | |
| ${{github.event.repository.name}}-frontend_svelte:latest \ | |
| ${{env.REGISTRY}}/${{github.repository}}-frontend_svelte:latest | |
| docker tag \ | |
| ${{github.event.repository.name}}-frontend_svelte:latest \ | |
| ${{env.REGISTRY}}/${{github.repository}}-frontend_svelte:$COMMIT_SHA | |
| docker push \ | |
| ${{env.REGISTRY}}/${{github.repository}}-frontend_svelte:latest | |
| docker push \ | |
| ${{env.REGISTRY}}/${{github.repository}}-frontend_svelte:$COMMIT_SHA | |
| deploy_stage: | |
| needs: containerize | |
| # if: ${{ github.event.ref == 'refs/heads/main' || github.event.ref == 'refs/heads/stage' }} | |
| # if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/stage' }} | |
| if: ${{((github.event.ref == 'refs/heads/main' || github.event.ref == 'refs/heads/stage') && needs.check_for_infrastructure_change.outputs.infrastructure_changed == 'FALSE' ) || ( ( github.event.workflow_run.head_branch == 'main' || github.event.workflow_run.head_branch == 'stage' ) && github.event.workflow_run.name == 'Infrastructure' && github.event.workflow_run.conclusion == 'success') }} | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| id-token: write | |
| packages: read | |
| environment: stage | |
| # env: | |
| # AZURE_AUTHORITY: https://login.microsoftonline.com/${{ secrets.AZURE_TENANT_ID }} | |
| steps: | |
| # - name: echos github.event.after variable | |
| # run: | | |
| # echo "=== Is this the correct tag: github.event.after? ===" | |
| # echo ${{ github.event.after }} | |
| # echo $CONTAINER_TAG | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Login to Azure | |
| uses: azure/login@v3 | |
| with: | |
| client-id: ${{ secrets.AZURE_GITHUBACTIONSMANAGEDIDENTITY_CLIENT_ID }} | |
| tenant-id: ${{ vars.AZURE_TENANT_ID }} | |
| subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
| - name: Deploy to staging | |
| run: | | |
| az containerapp update \ | |
| --name ${{ vars.AZURE_CONTAINERAPP_FRONTEND }} \ | |
| --resource-group ${{vars.AZURE_RESOURCE_GROUP}} \ | |
| --image ${{env.REGISTRY}}/${{github.repository}}-frontend_svelte:$COMMIT_SHA | |
| # implemented as in https://learn.microsoft.com/en-us/azure/container-apps/manage-secrets?tabs=azure-cli | |
| # TBD: consider putting all of this into a deploymentscript and reuse it and in deploy_prod! | |
| - name: Logout from Azure | |
| uses: azure/CLI@v3 | |
| with: | |
| inlineScript: | | |
| az logout | |
| az cache purge | |
| az account clear | |
| deploy_prod: | |
| needs: [deploy_stage] | |
| # if: ${{ github.event.ref == 'refs/heads/main' }} | |
| if: ${{ github.event.ref == 'refs/heads/main' || github.event.workflow_run.head_branch == 'main' }} | |
| # as this environmnet requires a manual review: | |
| # also wait on the pull request from postgres migrations to be merged | |
| # if check migrations detected changes. | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| id-token: write | |
| packages: read | |
| environment: prod | |
| # env: | |
| # AZURE_AUTHORITY: https://login.microsoftonline.com/${{ secrets.AZURE_TENANT_ID }} | |
| steps: | |
| # - name: echos github.event.after variable | |
| # run: | | |
| # echo "=== Is this the correct tag: github.event.after? ===" | |
| # echo ${{ github.event.after }} | |
| # echo $CONTAINER_TAG | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Login to Azure | |
| uses: azure/login@v3 | |
| with: | |
| client-id: ${{ secrets.AZURE_GITHUBACTIONSMANAGEDIDENTITY_CLIENT_ID }} | |
| tenant-id: ${{ vars.AZURE_TENANT_ID }} | |
| subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
| - name: Deploy to production | |
| run: | | |
| az containerapp update \ | |
| --name ${{ vars.AZURE_CONTAINERAPP_FRONTEND }} \ | |
| --resource-group ${{vars.AZURE_RESOURCE_GROUP}} \ | |
| --image ${{env.REGISTRY}}/${{github.repository}}-frontend_svelte:$COMMIT_SHA | |
| # implemented as in https://learn.microsoft.com/en-us/azure/container-apps/manage-secrets?tabs=azure-cli | |
| # TBD: consider putting all of this into a deploymentscript and reuse it and in deploy_prod! | |
| - name: Logout from Azure | |
| uses: azure/CLI@v3 | |
| with: | |
| inlineScript: | | |
| az logout | |
| az cache purge | |
| az account clear |