Build and Deploy to Docker Hub and GitHub Packages #5
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: Build and Deploy to Docker Hub | |
on: | |
workflow_run: | |
workflows: ["Application Tests"] | |
types: | |
- completed | |
branches: [main] | |
jobs: | |
check_previous_success: | |
runs-on: ubuntu-latest | |
outputs: | |
success: ${{ steps.check_success.outputs.success }} | |
steps: | |
- name: Check if previous workflows were successful | |
id: check_success | |
run: | | |
if [[ "${{ github.event.workflow_run.conclusion }}" != "success" ]]; then | |
echo "One or more of the required workflows failed." | |
echo "::set-output name=success::false" | |
exit 1 | |
fi | |
echo "::set-output name=success::true" | |
build-and-push: | |
needs: check_previous_success | |
if: needs.check_previous_success.outputs.success == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_TOKEN }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v2 | |
with: | |
push: true | |
tags: | | |
aaronzi/go-demo-api:${{ github.sha }} | |
aaronzi/go-demo-api:latest |