Add publish workflow #1
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: Publish | |
on: | |
push: | |
tags: | |
- 'v*.*.*' | |
jobs: | |
build-and-publish: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
os: [linux, darwin] | |
arch: [amd64, arm64] | |
include: | |
- os: linux | |
extension: '' | |
- os: windows | |
extension: '.exe' | |
- os: darwin | |
extension: '' | |
env: | |
APP_NAME: whereisit | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: '1.23' | |
- name: Cache Go modules | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/go/pkg/mod | |
~/.cache/go-build | |
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
${{ runner.os }}-go- | |
- name: Install dependencies | |
run: go mod download | |
- name: Build binary | |
run: | | |
mkdir -p dist | |
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -o dist/${{ env.APP_NAME }}-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.extension }} | |
- name: Create GitHub Release | |
id: create_release | |
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' && matrix.os == 'linux' }} | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ github.ref }} | |
release_name: Release ${{ github.ref }} | |
draft: false | |
prerelease: false | |
- name: Upload Binary | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: dist/${{ env.APP_NAME }}-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.extension }} | |
asset_name: ${{ env.APP_NAME }}-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.extension }} | |
asset_content_type: application/octet-stream |