Skip to content

build_and_publish

build_and_publish #35

name: build_and_publish
on:
workflow_run:
workflows: [tag_bump]
branches: [main]
types:
- completed
permissions:
contents: write
packages: write
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: Check out code
with:
fetch-depth: '0'
- name: Fetch all tags
run: git fetch --force --tags
# Verify only golang or Docker files have changed before we bump
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45
with:
files_yaml: |
golang:
- '**/*.go'
- 'go.*'
- '.goreleaser.yml'
docker:
- 'Dockerfile'
- 'goreleaser.Dockerfile'
- name: Set up Go
uses: actions/setup-go@v5
if: steps.changed-files-yaml.outputs.test_any_changed == 'true'
with:
go-version: 1.22
- name: Cache Go modules
uses: actions/cache@v4
if: steps.changed-files-yaml.outputs.test_any_changed == 'true'
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Docker Login
uses: docker/login-action@v3
if: steps.changed-files-yaml.outputs.test_any_changed == 'true'
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
if: steps.changed-files-yaml.outputs.test_any_changed == 'true'
with:
args: release --clean
distribution: goreleaser
version: latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}