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:
parent
a80a8bb35e
commit
e79e76c961
52
.github/workflows/publish.yml
vendored
Normal file
52
.github/workflows/publish.yml
vendored
Normal 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
|
Loading…
x
Reference in New Issue
Block a user