Build and Publish Go Binaries #31
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 Publish Go Binaries | |
on: | |
push: | |
branches: [ main ] | |
tags: | |
- '*' | |
pull_request: | |
branches: [ main ] | |
jobs: | |
create-release: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
outputs: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
tag: ${{ steps.get_tag.outputs.TAG }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Get latest tag | |
id: get_tag | |
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
- name: Create Release | |
id: create_release | |
if: startsWith(github.ref, 'refs/tags/') | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.get_tag.outputs.TAG }} | |
release_name: Release ${{ steps.get_tag.outputs.TAG }} | |
draft: false | |
prerelease: false | |
build-and-upload: | |
needs: create-release | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
packages: write | |
strategy: | |
matrix: | |
include: | |
- os: darwin | |
arch: amd64 | |
- os: darwin | |
arch: arm64 | |
- os: linux | |
arch: amd64 | |
- os: linux | |
arch: arm64 | |
- os: windows | |
arch: amd64 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.23' | |
- name: Build binary | |
run: | | |
VERSION=${{ needs.create-release.outputs.tag }} | |
PLUGIN_NAME="ranching.farm" | |
BINARY_NAME="kubectl-${PLUGIN_NAME}_${{ matrix.os }}_${{ matrix.arch }}${{ matrix.os == 'windows' && '.exe' || '' }}" | |
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -ldflags "-X main.version=$VERSION" -o $BINARY_NAME . | |
zip "${BINARY_NAME}.zip" $BINARY_NAME LICENSE | |
- name: Upload Release Asset (Binary) | |
if: startsWith(github.ref, 'refs/tags/') | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ needs.create-release.outputs.upload_url }} | |
asset_path: ./kubectl-ranching.farm_${{ matrix.os }}_${{ matrix.arch }}${{ matrix.os == 'windows' && '.exe' || '' }} | |
asset_name: kubectl-ranching.farm_${{ matrix.os }}_${{ matrix.arch }}${{ matrix.os == 'windows' && '.exe' || '' }} | |
asset_content_type: application/octet-stream | |
- name: Upload Release Asset (Zip) | |
if: startsWith(github.ref, 'refs/tags/') | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ needs.create-release.outputs.upload_url }} | |
asset_path: ./kubectl-ranching.farm_${{ matrix.os }}_${{ matrix.arch }}${{ matrix.os == 'windows' && '.exe' || '' }}.zip | |
asset_name: kubectl-ranching.farm_${{ matrix.os }}_${{ matrix.arch }}${{ matrix.os == 'windows' && '.exe' || '' }}.zip | |
asset_content_type: application/zip |