fix: update workflow #21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Upload Release Assets | |
on: | |
push: | |
branches: | |
- master | |
release: | |
types: [published] | |
jobs: | |
manage-nightly: | |
if: github.event_name == 'push' && github.ref == 'refs/heads/master' | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Delete previous nightly release and tag | |
run: | | |
gh release delete nightly --yes || true | |
git tag -d nightly || true | |
git push origin :refs/tags/nightly || true | |
- name: Create and push new nightly tag from master | |
run: | | |
git fetch origin | |
git tag nightly origin/master | |
git push origin nightly | |
build: | |
runs-on: ${{ matrix.runner }} | |
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-13 | |
- goos: darwin | |
goarch: arm64 | |
runner: macos-13 | |
- goos: windows | |
goarch: amd64 | |
runner: windows-2022 | |
- goos: windows | |
goarch: '386' | |
runner: windows-2022 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.21' | |
- name: Get the version and set file extension | |
id: get_version | |
shell: pwsh | |
run: | | |
if ( ${{ github.event_name }} == 'release' ) { | |
$VERSION = $(git describe --tags --exact-match 2>$null || git rev-parse HEAD) | |
} else { | |
$VERSION = 'nightly' | |
} | |
echo "VERSION=$VERSION" >> $env:GITHUB_ENV | |
if ("${{ matrix.goos }}" -eq "windows") { | |
echo "EXT=.exe" >> $env:GITHUB_ENV | |
} else { | |
echo "EXT=" >> $env:GITHUB_ENV | |
} | |
- name: Build binary | |
run: | | |
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} CGO_ENABLED=0 \ | |
go build -ldflags="-X main.version=${{ env.VERSION }} -s -w" \ | |
-o vcw-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ env.EXT }} | |
shell: bash | |
- name: Strip binary (Linux AMD64) | |
if: matrix.goos == 'linux' && matrix.goarch == 'amd64' | |
run: | | |
strip vcw-${{ 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 vcw-${{ 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 vcw-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ env.EXT }} > vcw-${{ 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 vcw-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ env.EXT }} SHA256 > vcw-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ env.EXT }}.sha256 | |
$lines = Get-Content vcw-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ env.EXT }}.sha256 | |
$lines[1..$($lines.Length-1)] | Set-Content vcw-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ env.EXT }}.sha256 | |
shell: pwsh | |
- name: Upload binary and checksum file as artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: vcw-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }} | |
path: | | |
vcw-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ env.EXT }} | |
vcw-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ env.EXT }}.sha256 | |
release: | |
needs: [build] | |
if: github.event_name == 'release' | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Download build artifacts | |
uses: actions/download-artifact@v3 | |
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@v1 | |
with: | |
files: ./dist/* | |
env: | |
GH_TOKEN: ${{ secrets.GH_TOKEN }} |