Skip to content

Update: Upgrade GitHub Actions to latest versions for better reliabil… #2

Update: Upgrade GitHub Actions to latest versions for better reliabil…

Update: Upgrade GitHub Actions to latest versions for better reliabil… #2

name: Build and Release
on:
push:
tags:
- 'v*'
branches:
- main
pull_request:
branches:
- main
jobs:
build:
name: Build Go Binary
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
include:
- os: ubuntu-latest
artifact_name: commit
asset_name: commit-linux-amd64
- os: windows-latest
artifact_name: commit.exe
asset_name: commit-windows-amd64.exe
- os: macos-latest
artifact_name: commit
asset_name: commit-macos-amd64
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22' # Use the appropriate Go version for your project
- name: Get dependencies
run: go mod download
- name: Build
run: |
if [ "${{ matrix.os }}" = "windows-latest" ]; then
go build -v -o ${{ matrix.artifact_name }} -ldflags="-s -w" ./src
else
go build -v -o ${{ matrix.artifact_name }} -ldflags="-s -w" ./src
fi
shell: bash
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset_name }}
path: ${{ matrix.artifact_name }}
release:
needs: build
if: startsWith(github.ref, 'refs/tags/v')
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: Create Release
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: |
commit-linux-amd64/commit
commit-windows-amd64.exe/commit.exe
commit-macos-amd64/commit
draft: false
prerelease: false
generate_release_notes: true
publish:
name: Publish to GitHub Packages
needs: build
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Download Linux artifact
uses: actions/download-artifact@v4
with:
name: commit-linux-amd64
path: ./dist/linux-amd64
- name: Download Windows artifact
uses: actions/download-artifact@v4
with:
name: commit-windows-amd64.exe
path: ./dist/windows-amd64
- name: Download macOS artifact
uses: actions/download-artifact@v4
with:
name: commit-macos-amd64
path: ./dist/darwin-amd64
- name: Make binaries executable
run: |
chmod +x ./dist/linux-amd64/commit
chmod +x ./dist/darwin-amd64/commit
- name: Prepare release assets
run: |
mkdir -p ./release
# Linux package
tar -C ./dist/linux-amd64 -czf ./release/commit-linux-amd64.tar.gz commit
# Windows package
zip -j ./release/commit-windows-amd64.zip ./dist/windows-amd64/commit.exe
# macOS package
tar -C ./dist/darwin-amd64 -czf ./release/commit-macos-amd64.tar.gz commit
- name: Upload release packages to GitHub Releases
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: |
./release/commit-linux-amd64.tar.gz
./release/commit-windows-amd64.zip
./release/commit-macos-amd64.tar.gz