Skip to content

feature: convert the script to golang #1

feature: convert the script to golang

feature: convert the script to golang #1

Workflow file for this run

name: Build and Release
on:
push:
branches: [ main, feat/golang ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, windows, darwin]
goarch: [amd64, arm64, "386", arm]
exclude:
# Exclude unsupported combinations
- goos: darwin
goarch: "386"
- goos: darwin
goarch: arm
- goos: windows
goarch: arm
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Get dependencies
run: go mod download
- name: Build
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
# Create output directory
mkdir -p dist
# Set binary name based on OS
BINARY_NAME="flac-converter"
if [ "${{ matrix.goos }}" = "windows" ]; then
BINARY_NAME="flac-converter.exe"
fi
# Set output filename with architecture info
OUTPUT_NAME="flac-converter-${{ matrix.goos }}-${{ matrix.goarch }}"
if [ "${{ matrix.goos }}" = "windows" ]; then
OUTPUT_NAME="flac-converter-${{ matrix.goos }}-${{ matrix.goarch }}.exe"
fi
# Build the binary
go build -ldflags="-s -w" -o "dist/${OUTPUT_NAME}" .
# Create archive
if [ "${{ matrix.goos }}" = "windows" ]; then
cd dist && zip "${OUTPUT_NAME%.exe}.zip" "${OUTPUT_NAME}" && cd ..
else
cd dist && tar -czf "${OUTPUT_NAME}.tar.gz" "${OUTPUT_NAME}" && cd ..
fi
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: flac-converter-${{ matrix.goos }}-${{ matrix.goarch }}
path: |
dist/flac-converter-${{ matrix.goos }}-${{ matrix.goarch }}*
release:
name: Create Release
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/feat/golang')
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Display structure of downloaded files
run: ls -la artifacts/
- name: Prepare release assets
run: |
mkdir -p release
find artifacts -name "*.tar.gz" -o -name "*.zip" -o -name "flac-converter*" | while read file; do
cp "$file" release/
done
ls -la release/
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: build-${{ github.sha }}
name: Build ${{ github.sha }}
body: |
Automated build from commit ${{ github.sha }}
Built binaries for:
- Linux (x64, ARM64, x86, ARM)
- Windows (x64, ARM64, x86)
- macOS (x64, ARM64)
files: release/*
draft: false
prerelease: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}