name: goreleaser
on:
push:
# run only against tags
tags:
- "v*"
permissions:
contents: write
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
persist-credentials: false
- name: Extract release notes from CHANGELOG.md
run: |
VERSION=${GITHUB_REF_NAME#v}
# Extract the section for this version from CHANGELOG.md.
# Matches from "## [X.Y.Z]" until the next "## [" or end of file,
# excluding the heading itself and any trailing link references.
if [ -f CHANGELOG.md ]; then
awk -v ver="$VERSION" '
/^## \[/ {
if (found) exit
if ($0 ~ "## \\[" ver "\\]") found=1
next
}
/^\[.*\]: https:\/\// { next }
found { print }
' CHANGELOG.md > /tmp/release-notes.md
fi
# If CHANGELOG.md is missing or has no section for this version, fall back
if [ ! -s /tmp/release-notes.md ]; then
echo "Release ${GITHUB_REF_NAME}" > /tmp/release-notes.md
fi
- name: Set up Go
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
with:
go-version: stable
# Do not use any caches when creating a release.
cache: false
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@4247c53b304edb39a4e6a0808f415d3eebad450a
with:
distribution: goreleaser
# 'latest', 'nightly', or a semver
version: "~> v2"
args: release --clean --release-notes=/tmp/release-notes.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}