mirror of
https://github.com/jakejarvis/hugo-docker.git
synced 2025-04-26 21:08:26 -04:00
53 lines
1.5 KiB
YAML
53 lines
1.5 KiB
YAML
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
|