goshort/.github/workflows/release.yml
Gustavo Maronato 67f07b7601
Some checks failed
Go / checks (push) Has been cancelled
use separate test and release actions
2023-09-21 16:20:59 -03:00

86 lines
3.1 KiB
YAML

name: Release
# Controls when the workflow will run
on:
release:
types:
- published
jobs:
buildpush:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- # Get the repository's code
name: Checkout
uses: actions/checkout@v2
- # https://github.com/vegardit/docker-gitea-act-runner/issues/23
name: Fix docker sock permissions
run: sudo chmod 666 /var/run/docker.sock
- # https://github.com/docker/setup-qemu-action
name: Set up QEMU
uses: docker/setup-qemu-action@v1
- # https://github.com/docker/setup-buildx-action
name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- # https://github.com/docker/login-action
name: Log in to the Container registry
uses: docker/login-action@v2
with:
# Maybe there is a default env var for this?
registry: git.maronato.dev
username: ${{ github.repository_owner }}}
# Ideally, we should only need to set "permissions: package: write", but
# Gitea is having issues with that. For now, this is a manually created
# token available user-wise, with the "package:write" permission.
password: ${{ secrets.PACKAGE_WRITE_TOKEN }}
- # https://github.com/docker/metadata-action
# Generate tags and labels for the image
# according to the commit and the branch
name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
# The container image name needs the custom registry in it.
# Maybe there is a default env var for this?
images: git.maronato.dev/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- # httos://github.com/actions/cache
name: Cache Docker layers
uses: actions/cache@v3
with:
path: |
/go/pkg/mod/
/tmp/.npm-cache
/tmp/.go-build-cache
/tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- # https://github.com/docker/build-push-action
name: Build and push
uses: docker/build-push-action@v2
with:
context: .
build-args: |
VERSION=${{ steps.meta.outputs.version }}
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
- # Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache