Skip to content

Manual Branch Deploy to Staging #5

Manual Branch Deploy to Staging

Manual Branch Deploy to Staging #5

name: Manual Branch Deploy to Staging
on:
# only run this workflow manually
workflow_dispatch:
jobs:
#############################################
# jobs dispatched to a separate workflow file
#############################################
check-if-image-exists:
runs-on: ubuntu-latest
outputs:
image-exists: ${{ contains(steps.*.outputs.image-exists, 'true') && 'true' || 'false' }}
steps:
- name: Log into container registry
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Check if image with commit sha already exists
run: docker manifest inspect ghcr.io/${{ github.repository }}:${{ github.sha }}
- name: Set output if image exists
id: set-output-1
if: ${{ success() }}
run: echo "image-exists=true" >> "$GITHUB_OUTPUT"
- name: Set output if image does not exist
id: set-output-2
if: ${{ failure() }}
run: echo "image-exists=false" >> "$GITHUB_OUTPUT"
create-docker-image-job:
needs:
- check-if-image-exists
if: ${{ needs.check-if-image-exists.outputs.image-exists == 'false' }}
permissions:
security-events: write # upload-sarif
packages: write
id-token: write
contents: read
uses: ./.github/workflows/create-docker-image-job.yml
with:
container-registry: ghcr.io
container-image-name: ${{ github.repository }}
container-image-version: ${{ github.sha }}
secrets: inherit # e.g. sonar token
push-docker-image-job:
needs:
- create-docker-image-job
permissions:
security-events: write # upload-sarif
packages: write
id-token: write
contents: read
uses: ./.github/workflows/push-docker-image-job.yml
with:
container-registry: ghcr.io
container-image-name: ${{ github.repository }}
container-image-version: ${{ github.sha }}
secrets: inherit # e.g. sonar token
deploy-staging-job:
needs:
- push-docker-image-job
- check-if-image-exists
if: ${{ always() && ( needs.check-if-image-exists.outputs.image-exists == 'true' || needs.push-docker-image-job.result == 'success' ) }}
permissions:
id-token: write
uses: ./.github/workflows/deploy-staging-job.yml
secrets: inherit