fix: Calling ghcr-cleanup action directly (#20) #26
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish Docker image | |
on: | |
release: | |
types: [published] | |
push: | |
branches: | |
- master | |
workflow_dispatch: | |
env: | |
IMAGE_NAME: unfurlist | |
jobs: | |
test: | |
name: Test suite | |
runs-on: ubuntu-latest | |
timeout-minutes: 60 | |
steps: | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: 'stable' | |
- uses: actions/checkout@v4 | |
- name: Get dependencies | |
run: go mod download | |
- name: Run tests | |
run: go test -v -race ./... | |
push: | |
needs: test | |
name: Build and push Docker image | |
runs-on: ubuntu-latest | |
timeout-minutes: 60 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Build image | |
run: | | |
docker build . --tag image | |
- name: Log into registry | |
run: echo "${{ secrets.GH_PACKAGES_TOKEN }}" | docker login ghcr.io -u ${GITHUB_ACTOR} --password-stdin | |
- name: Push image | |
run: | | |
set -u | |
# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables | |
IMAGE_ID=ghcr.io/doist/$IMAGE_NAME | |
# Strip git ref prefix from version | |
VERSION=${GITHUB_REF##*/} | |
# Strip "v" prefix from tag name | |
case "${GITHUB_REF}" in refs/tags/*) VERSION=${VERSION#v} ;; esac | |
case "$VERSION" in master) VERSION=latest ;; esac | |
echo IMAGE_ID=$IMAGE_ID | |
echo VERSION=$VERSION | |
echo GITHUB_REF=$GITHUB_REF | |
docker tag image $IMAGE_ID:$VERSION | |
docker push $IMAGE_ID:$VERSION |