Skip to content

ghcr.io publish API

ghcr.io publish API #2

Workflow file for this run

name: ghcr.io publish API
on:
workflow_dispatch:
env:
REGISTRY: ghcr.io/gman-au/recipe-formatter
IMAGE_NAME: recipe-formatter
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image
run: docker build --file ./src/Recipe.Formatter.Host/Dockerfile --tag built-image ./src
- name: Push image
run: |
IMAGE_ID=$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,')
REGISTRY=${{ env.REGISTRY }}
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
echo REGISTRY=$REGISTRY
docker tag built-image $REGISTRY/$IMAGE_ID:$VERSION
docker tag built-image $REGISTRY/$IMAGE_ID:latest
docker push $REGISTRY/$IMAGE_ID:$VERSION
docker push $REGISTRY/$IMAGE_ID:latest