127 lines
3.4 KiB
Plaintext
127 lines
3.4 KiB
Plaintext
name: Release
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
|
|
jobs:
|
|
ci:
|
|
uses: ./.github/workflows/ci.yml
|
|
|
|
build:
|
|
needs: ci
|
|
strategy:
|
|
matrix:
|
|
include:
|
|
- os: ubuntu-latest
|
|
goos: linux
|
|
goarch: amd64
|
|
- os: ubuntu-latest
|
|
goos: linux
|
|
goarch: arm64
|
|
- os: macos-latest
|
|
goos: darwin
|
|
goarch: amd64
|
|
- os: macos-latest
|
|
goos: darwin
|
|
goarch: arm64
|
|
- os: windows-latest
|
|
goos: windows
|
|
goarch: amd64
|
|
runs-on: ${{ matrix.os }}
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: '1.23'
|
|
|
|
- name: Build
|
|
shell: bash
|
|
env:
|
|
GOOS: ${{ matrix.goos }}
|
|
GOARCH: ${{ matrix.goarch }}
|
|
run: |
|
|
VERSION="${GITHUB_REF#refs/tags/}"
|
|
COMMIT="${GITHUB_SHA:0:7}"
|
|
BUILD_DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
LDFLAGS="-X main.version=$VERSION -X main.commit=$COMMIT -X main.date=$BUILD_DATE"
|
|
|
|
go build -ldflags "$LDFLAGS" -o {{PROJECT_NAME}}${{ matrix.goos == 'windows' && '.exe' || '' }}
|
|
|
|
- name: Package (Unix)
|
|
if: matrix.goos != 'windows'
|
|
run: |
|
|
tar czf {{PROJECT_NAME}}-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz {{PROJECT_NAME}}
|
|
|
|
- name: Package (Windows)
|
|
if: matrix.goos == 'windows'
|
|
run: |
|
|
7z a {{PROJECT_NAME}}-${{ matrix.goos }}-${{ matrix.goarch }}.zip {{PROJECT_NAME}}.exe
|
|
|
|
- name: Upload artifacts
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: {{PROJECT_NAME}}-${{ matrix.goos }}-${{ matrix.goarch }}
|
|
path: |
|
|
{{PROJECT_NAME}}-*.tar.gz
|
|
{{PROJECT_NAME}}-*.zip
|
|
|
|
release:
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Download all artifacts
|
|
uses: actions/download-artifact@v4
|
|
|
|
- name: Generate checksums
|
|
run: |
|
|
find . -name "{{PROJECT_NAME}}-*" -type f \( -name "*.tar.gz" -o -name "*.zip" \) -exec sha256sum {} \; > checksums.txt
|
|
|
|
- name: Create Release
|
|
uses: softprops/action-gh-release@v2
|
|
with:
|
|
files: |
|
|
{{PROJECT_NAME}}-*/*.tar.gz
|
|
{{PROJECT_NAME}}-*/*.zip
|
|
checksums.txt
|
|
generate_release_notes: true
|
|
|
|
# Uncomment to build and push Docker image
|
|
# docker:
|
|
# needs: build
|
|
# runs-on: ubuntu-latest
|
|
# steps:
|
|
# - name: Checkout code
|
|
# uses: actions/checkout@v4
|
|
#
|
|
# - name: Set up Docker Buildx
|
|
# uses: docker/setup-buildx-action@v3
|
|
#
|
|
# - name: Login to Docker Hub
|
|
# uses: docker/login-action@v3
|
|
# with:
|
|
# username: ${{ secrets.DOCKER_USERNAME }}
|
|
# password: ${{ secrets.DOCKER_PASSWORD }}
|
|
#
|
|
# - name: Extract version
|
|
# id: version
|
|
# run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
|
#
|
|
# - name: Build and push
|
|
# uses: docker/build-push-action@v5
|
|
# with:
|
|
# context: .
|
|
# push: true
|
|
# tags: |
|
|
# yourusername/{{PROJECT_NAME}}:${{ steps.version.outputs.VERSION }}
|
|
# yourusername/{{PROJECT_NAME}}:latest
|