Skip to content

chore(pre-commit): autoupdate hooks (#498) #290

chore(pre-commit): autoupdate hooks (#498)

chore(pre-commit): autoupdate hooks (#498) #290

name: Deploy
on:
workflow_dispatch:
push:
branches:
- main
tags:
# pre-release tag
- "202[3-9].[0-9][0-9].[0-9]+-rc[0-9]+"
# release tags
- "202[3-9].[0-9][0-9].[0-9]+"
defaults:
run:
shell: bash
concurrency:
# this expression gives us the name of the deployment environment. It works like a ternary operation (see https://github.com/actions/runner/issues/409#issuecomment-727565588)
group: ${{ github.ref_type != 'tag' && github.ref_name || contains(github.ref, '-rc') && 'test' || 'prod' }}
cancel-in-progress: true
jobs:
test:
uses: ./.github/workflows/run-tests.yml
if: github.ref_type == 'tag'
deploy:
needs: test
# !cancelled() is needed because if the whole workflow was cancelled, we don't want this job to run.
# (github.ref_type != 'tag' || needs.test.result == 'success') is needed because if `test` did run, we only want this to run if `test` succeeded.
if: (!cancelled() && (github.ref_type != 'tag' || needs.test.result == 'success'))
runs-on: ubuntu-latest
environment: ${{ github.ref_type != 'tag' && github.ref_name || contains(github.ref, '-rc') && 'test' || 'prod' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version-file: .github/workflows/.python-version
- name: Create /static directory
run: mkdir -p static
- name: Write python packages to file
run: |
python -m pip install --upgrade pip
pip install pipdeptree setuptools_scm
pip install -e .
python -m setuptools_scm
pipdeptree >> static/requirements.txt
- name: Write commit SHA to file
run: echo "${{ github.sha }}" >> static/sha.txt
- name: Write version to file
run: echo "${{ github.ref_name }}" >> static/version.txt
- name: Docker Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Build, tag, and push image to GitHub Container Registry
uses: docker/build-push-action@v6
with:
builder: ${{ steps.buildx.outputs.name }}
build-args: GIT-SHA=${{ github.sha }}
cache-from: type=gha,scope=cal-itp
cache-to: type=gha,scope=cal-itp,mode=max
context: .
file: Dockerfile
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ github.sha }}
- name: Deploy to MST Azure Web App
uses: azure/webapps-deploy@v2
with:
app-name: ${{ vars.MST_AZURE_WEBAPP_NAME }}
images: ghcr.io/${{ github.repository }}:${{ github.sha }}
publish-profile: ${{ secrets.MST_AZURE_WEBAPP_PUBLISH_PROFILE }}
- name: Deploy to SBMTD Azure Web App
uses: azure/webapps-deploy@v2
with:
app-name: ${{ vars.SBMTD_AZURE_WEBAPP_NAME }}
images: ghcr.io/${{ github.repository }}:${{ github.sha }}
publish-profile: ${{ secrets.SBMTD_AZURE_WEBAPP_PUBLISH_PROFILE }}