Merge pull request #13 from OpenIPC/ci-docker-skip-without-secrets #3
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: ci | |
| on: | |
| push: | |
| branches: | |
| - master | |
| workflow_dispatch: | |
| jobs: | |
| docker: | |
| runs-on: ubuntu-latest | |
| # Publish only from master, even for manual workflow_dispatch runs, so a | |
| # dispatch from a feature branch can't overwrite the :latest image. | |
| if: github.ref == 'refs/heads/master' | |
| steps: | |
| # Without DockerHub credentials the publish can't run; skip it (and keep | |
| # the job green) instead of failing every push to master. The secrets are | |
| # scoped to this step only (the login action takes them via its inputs). | |
| - name: Check DockerHub credentials | |
| id: creds | |
| env: | |
| DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
| DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | |
| run: | | |
| if [ -n "$DOCKERHUB_USERNAME" ] && [ -n "$DOCKERHUB_TOKEN" ]; then | |
| echo "present=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "present=false" >> "$GITHUB_OUTPUT" | |
| echo "::notice::DOCKERHUB_USERNAME/DOCKERHUB_TOKEN are not set; skipping the image publish." | |
| fi | |
| - name: Set up QEMU | |
| if: steps.creds.outputs.present == 'true' | |
| uses: docker/setup-qemu-action@v1 | |
| - name: Set up Docker Buildx | |
| if: steps.creds.outputs.present == 'true' | |
| uses: docker/setup-buildx-action@v1 | |
| - name: Login to DockerHub | |
| if: steps.creds.outputs.present == 'true' | |
| uses: docker/login-action@v1 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push | |
| if: steps.creds.outputs.present == 'true' | |
| uses: docker/build-push-action@v2 | |
| with: | |
| push: true | |
| tags: braunbearded/python-dvr:latest,braunbearded/python-dvr:${{ github.sha }} |