Manual Branch Deploy to Staging #4
This file contains 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: 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: | |
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 | |
if: ${{ success() }} | |
run: echo "image-exists=true" >> "$GITHUB_OUTPUT" | |
- name: Set output if image does not exist | |
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 |