fix: git workflow assets v0.0.2 #40
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 Go Project | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
permissions: write-all | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: 1.23 | |
- name: Build for Linux, macOS, and Windows | |
run: | | |
GIT_WORKSPACE="${{ github.workspace }}" | |
OUTPUT_DIR="${{ github.workspace }}/bin" # Save the binaries outside of src | |
BINARY_NAME="flag" | |
mkdir -p $OUTPUT_DIR/linux $OUTPUT_DIR/macos $OUTPUT_DIR/windows | |
cd $GIT_WORKSPACE/src # Change to the src directory | |
# Build for Linux | |
GOOS=linux GOARCH=amd64 go build -trimpath -o $OUTPUT_DIR/linux/$BINARY_NAME | |
# Build for macOS | |
GOOS=darwin GOARCH=amd64 go build -trimpath -o $OUTPUT_DIR/macos/$BINARY_NAME | |
# Build for Windows | |
GOOS=windows GOARCH=amd64 go build -trimpath -o $OUTPUT_DIR/windows/$BINARY_NAME.exe | |
# Zip only the linux, macos, and windows folders without the full path | |
cd $OUTPUT_DIR | |
zip -j flag-windows.zip windows/$BINARY_NAME.exe | |
zip -j flag-linux.zip linux/$BINARY_NAME | |
zip -j flag-macos.zip macos/$BINARY_NAME | |
- name: List contents of bin directory | |
run: | | |
pwd | |
ls -la ${{ github.workspace }}/bin | |
- name: Upload build artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: build | |
path: ${{ github.workspace }}/bin | |
- name: Set Release Version | |
id: set_version | |
run: echo "RELEASE_VERSION=$(date +'%Y%m%d.%H%M%S')" >> $GITHUB_ENV | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
with: | |
tag_name: ${{ env.RELEASE_VERSION }} | |
release_name: Release ${{ env.RELEASE_VERSION }} | |
draft: false | |
prerelease: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload Windows Release Asset | |
uses: actions/upload-release-asset@v1 | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ${{ github.workspace }}/bin/flag-windows.zip | |
asset_name: flag-windows.zip | |
asset_content_type: application/zip | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload Linux Release Asset | |
uses: actions/upload-release-asset@v1 | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ${{ github.workspace }}/bin/flag-linux.zip | |
asset_name: flag-linux.zip | |
asset_content_type: application/zip | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload macOS Release Asset | |
uses: actions/upload-release-asset@v1 | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ${{ github.workspace }}/bin/flag-macos.zip | |
asset_name: flag-macos.zip | |
asset_content_type: application/zip | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |