Skip to content

Build and Upload Release Assets #38

Build and Upload Release Assets

Build and Upload Release Assets #38

Workflow file for this run

name: Build and Upload Release Assets
on:
release:
types: [published]
env:
app_name: cache-warmer
jobs:
build:
strategy:
matrix:
include:
- goos: linux
goarch: amd64
runner: ubuntu-24.04
- goos: linux
goarch: arm64
runner: ubuntu-24.04
- goos: darwin
goarch: amd64
runner: macos-14
- goos: darwin
goarch: arm64
runner: macos-14
- goos: windows
goarch: amd64
runner: windows-2022
- goos: windows
goarch: '386'
runner: windows-2022
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Get the version and set file extension
id: get_version
run: |
$VERSION = $(git describe --tags --exact-match 2>$null || git rev-parse HEAD)
echo "VERSION=$VERSION" >> $env:GITHUB_ENV
if ("${{ matrix.goos }}" -eq "windows") {
echo "EXT=.exe" >> $env:GITHUB_ENV
} else {
echo "EXT=" >> $env:GITHUB_ENV
}
shell: pwsh
- name: Build binary
run: |
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} CGO_ENABLED=0 \
go build -ldflags="-X main.version=${{ env.VERSION }} -s -w" \
-o ${{ env.app_name }}-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ env.EXT }}
shell: bash
- name: Strip binary (Linux AMD64)
if: matrix.goos == 'linux' && matrix.goarch == 'amd64'
run: |
strip ${{ env.app_name }}-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}
shell: bash
- name: Strip binary (Linux ARM64)
if: matrix.goos == 'linux' && matrix.goarch == 'arm64'
run: |
sudo apt-get update && sudo apt-get install -y binutils-aarch64-linux-gnu
aarch64-linux-gnu-strip ${{ env.app_name }}-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}
shell: bash
- name: Calculate SHA-256 checksum and create checksum file (Linux and macOS)
if: matrix.goos != 'windows'
run: |
shasum -a 256 ${{ env.app_name }}-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ env.EXT }} > ${{ env.app_name }}-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ env.EXT }}.sha256
shell: bash
- name: Calculate SHA-256 checksum and create checksum file (Windows)
if: matrix.goos == 'windows'
run: |
certutil -hashfile ${{ env.app_name }}-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ env.EXT }} SHA256 > ${{ env.app_name }}-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ env.EXT }}.sha256
$lines = Get-Content ${{ env.app_name }}-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ env.EXT }}.sha256
$lines[1..$($lines.Length-1)] | Set-Content ${{ env.app_name }}-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ env.EXT }}.sha256
shell: pwsh
- name: Upload binary and checksum file as artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ env.app_name }}-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}
path: |
${{ env.app_name }}-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ env.EXT }}
${{ env.app_name }}-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ env.EXT }}.sha256
release:
needs: build
runs-on: ubuntu-24.04
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
path: ./dist
- name: Move files to temp directory
run: |
mkdir temp
find ./dist -mindepth 2 -type f -exec mv {} temp/ \;
- name: Cleanup and rename temp to dist
run: |
rm -rf ./dist
mv temp dist
- name: Upload binaries and checksums to GitHub Release
uses: softprops/action-gh-release@v2
with:
files: ./dist/*
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}