1
mirror of https://github.com/jakejarvis/hugo-docker.git synced 2025-04-26 03:45:22 -04:00

Create publish.yml

This commit is contained in:
Jake Jarvis 2020-09-02 12:25:22 -04:00 committed by GitHub
parent a80a8bb35e
commit e79e76c961
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

52
.github/workflows/publish.yml vendored Normal file
View File

@ -0,0 +1,52 @@
name: Publish to GitHub Container Registry
on:
push:
# Publish `v*` tags as releases.
tags:
- v*
pull_request:
env:
IMAGE_NAME: hugo-extended
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build image
run: docker build . --file Dockerfile
# Push image to GitHub Container Registry
push:
runs-on: ubuntu-latest
if: github.event_name == 'push'
needs: build
steps:
- uses: actions/checkout@v2
- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME
- name: Login to GitHub Container Registry
run: echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push image to GitHub
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
# Push image with both version tag and `latest` tag
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:latest
docker push $IMAGE_ID:$VERSION
docker push $IMAGE_ID:latest