Files
jekyll-build-pages/.github/workflows/docker-publish.yml
T
2021-12-15 17:17:51 -05:00

86 lines
2.6 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:
- 'main'
paths-ignore:
- 'README.md'
# Publish semver tags as releases. Allow for '-alpha'
# stage releases as well.
tags:
- 'v*.*.*-beta'
- 'v*.*.*-alpha'
- 'v*'
pull_request:
branches:
- 'main'
paths-ignore:
- 'README.md'
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Render Action Metadata
if: ${{ github.event_name != 'pull_request' }}
run: |
./bin/render_action_metadata "docker://ghcr.io/actions/jekyll-build-pages:${{ github.ref_name }}" > action.yml
git add action.yml
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git commit -m "Add generated action.yml 🤖"
if [[ '${{ github.ref_type }}' == 'tag' ]]; then
echo "Pushing tag ${{ github.ref_name }}"
git tag -f ${{ github.ref_name }}
git push -f origin ${{ github.ref_name }}
else
echo "Pushing branch ${{ github.ref_name }}"
git push origin ${{ github.ref_name }}
fi