Files
starter-workflows/ci/docker-publish.yml
T
Sven Pfleiderer 7b6d03675b Revert "Remove pull request condition"
This reverts commit 9d73235e03.
2021-06-02 15:58:44 -07:00

82 lines
2.3 KiB
YAML

name: Docker
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
on:
push:
branches: [ $default-branch ]
# Publish `v1.2.3` tags as releases.
tags: [ 'v*.*.*' ]
pull_request_target:
branches: [ $default-branch ]
# Run tests for any PRs.
pull_request:
env:
# TODO: Creates container named ACCOUNT/REPO
# Append /IMAGE-NAME to create a container named ACCOUNT/REPO/IMAGE-NAME
IMAGE_NAME: ${{ github.repository }}
# Registry. Use docker.io for DockerHub
REGISTRY: ghcr.io
jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run tests
run: |
if [ -f docker-compose.test.yml ]; then
docker-compose --file docker-compose.test.yml build
docker-compose --file docker-compose.test.yml run sut
else
docker build . --file Dockerfile
fi
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Ensure test job passes before pushing image.
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push'
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
# Don't push on pull requests
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}