Skip to content

chore: prepare release v0.2.0 #4

chore: prepare release v0.2.0

chore: prepare release v0.2.0 #4

Workflow file for this run

name: release
on:
push:
tags:
- 'v*'
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
create-release:
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get version
id: get_version
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
else
VERSION=$(git describe --tags --always)
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Version: ${VERSION}"
- name: Extract release notes from CHANGELOG
id: extract_notes
run: |
VERSION=${{ steps.get_version.outputs.version }}
# Extract notes for this version from CHANGELOG.md
if [ -f CHANGELOG.md ]; then
# Get content between version header and next version or end
NOTES=$(awk "/## \[${VERSION#v}\]/{flag=1; next} /## \[/{flag=0} flag" CHANGELOG.md)
if [ -z "$NOTES" ]; then
NOTES="Release ${VERSION}"$'\n\n'"Built with Neutrino v0.16.0"$'\n\n'"See [CHANGELOG.md](CHANGELOG.md) for details."
fi
else
NOTES="Release ${VERSION}"
fi
echo "notes<<EOF" >> $GITHUB_OUTPUT
echo "$NOTES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create Release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create ${{ steps.get_version.outputs.version }} \
--title "${{ steps.get_version.outputs.version }}" \
--notes "${{ steps.extract_notes.outputs.notes }}"
build-binaries:
needs: create-release
runs-on: ubuntu-latest
permissions:
contents: write
strategy:
matrix:
include:
- goos: linux
goarch: amd64
output: neutrinod-linux-amd64
- goos: linux
goarch: arm64
output: neutrinod-linux-arm64
- goos: darwin
goarch: amd64
output: neutrinod-darwin-amd64
- goos: darwin
goarch: arm64
output: neutrinod-darwin-arm64
- goos: windows
goarch: amd64
output: neutrinod-windows-amd64.exe
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
cache-dependency-path: neutrino_server/go.sum
- name: Get dependencies
working-directory: neutrino_server
run: go mod download
- name: Build binary
working-directory: neutrino_server
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
VERSION=${{ needs.create-release.outputs.version }}
BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S')
COMMIT_HASH=$(git rev-parse --short HEAD)
go build \
-ldflags="-s -w -X main.version=${VERSION} -X main.buildTime=${BUILD_TIME} -X main.commit=${COMMIT_HASH}" \
-o ${{ matrix.output }} \
./cmd/neutrinod
- name: Upload Release Asset
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release upload ${{ needs.create-release.outputs.version }} \
"neutrino_server/${{ matrix.output }}"
build-docker:
needs: create-release
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./neutrino_server
file: ./neutrino_server/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=${{ needs.create-release.outputs.version }}
BUILD_TIME=${{ github.event.repository.updated_at }}
COMMIT=${{ github.sha }}
checksums:
needs: [create-release, build-binaries]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download release assets
env:
GH_TOKEN: ${{ github.token }}
run: |
mkdir -p artifacts
cd artifacts
gh release download ${{ needs.create-release.outputs.version }} \
--repo ${{ github.repository }} \
--pattern 'neutrinod-*'
- name: Generate checksums
run: |
cd artifacts
sha256sum * > SHA256SUMS
cat SHA256SUMS
- name: Upload checksums
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release upload ${{ needs.create-release.outputs.version }} \
./artifacts/SHA256SUMS \
--repo ${{ github.repository }}