olaf v1.0.0 ☃️ #23
Workflow file for this run
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 binaries | |
on: | |
release: | |
types: [published] | |
push: | |
pull_request: | |
permissions: | |
contents: read | |
jobs: | |
build: | |
name: Build binaries | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- {GOOS: linux, GOARCH: amd64} | |
- {GOOS: windows, GOARCH: amd64} | |
steps: | |
- name: Install Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: 1.x | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Build binary | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y libx11-dev | |
cp LICENSE "$RUNNER_TEMP/LICENSE" | |
echo -e "\n---\n" >> "$RUNNER_TEMP/LICENSE" | |
curl -L "https://raw.githubusercontent.com/golang-design/clipboard/main/LICENSE" >> "$RUNNER_TEMP/LICENSE" | |
echo -e "\n---\n" >> "$RUNNER_TEMP/LICENSE" | |
curl -L "https://raw.githubusercontent.com/golang-design/hotkey/main/LICENSE" >> "$RUNNER_TEMP/LICENSE" | |
echo -e "\n---\n" >> "$RUNNER_TEMP/LICENSE" | |
curl -L "https://go.dev/LICENSE?m=text" >> "$RUNNER_TEMP/LICENSE" | |
VERSION="$(git describe --tags)" | |
DIR="$(mktemp -d)" | |
mkdir "$DIR/olaf" | |
cp "$RUNNER_TEMP/LICENSE" "$DIR/olaf" | |
go build -o "$DIR/olaf" -ldflags "-X main.Version=$VERSION" -trimpath . | |
if [ "$GOOS" == "windows" ]; then | |
( cd "$DIR"; zip olaf.zip -r olaf ) | |
mv "$DIR/olaf.zip" "olaf-$VERSION-$GOOS-$GOARCH.zip" | |
else | |
tar -cvzf "olaf-$VERSION-$GOOS-$GOARCH.tar.gz" -C "$DIR" olaf | |
fi | |
env: | |
CGO_ENABLED: 1 | |
GOOS: ${{ matrix.GOOS }} | |
GOARCH: ${{ matrix.GOARCH }} | |
- name: Upload workflow artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: olaf-binaries | |
path: olaf-* | |
upload: | |
name: Upload release binaries | |
if: github.event_name == 'release' | |
needs: build | |
permissions: | |
contents: write | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download workflow artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: olaf-binaries | |
- name: Upload release artifacts | |
run: gh release upload "$GITHUB_REF_NAME" olaf-* | |
env: | |
GH_REPO: ${{ github.repository }} | |
GH_TOKEN: ${{ github.token }} |