Skip to content

Build and Compress Go Application #23

Build and Compress Go Application

Build and Compress Go Application #23

Workflow file for this run

name: Build and Compress Go Application
on:
workflow_dispatch:
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
ext: ""
- os: windows-latest
ext: ".exe"
# - os: macos-latest
# ext: ""
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: Install UPX on Linux
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update && sudo apt-get install -y upx-ucl
- name: Install UPX on Windows
if: matrix.os == 'windows-latest'
run: choco install upx
- name: Build the application
shell: bash
run: |
if [[ "$RUNNER_OS" == "macOS" ]]; then
sed -i '' 's/AppId\s*=\s*".*"/AppId = "${{ secrets.AppId }}"/' main.go
sed -i '' 's/AppSecret\s*=\s*".*"/AppSecret = "${{ secrets.AppSecret }}"/' main.go
else
sed -i 's/AppId\s*=\s*".*"/AppId = "${{ secrets.AppId }}"/' main.go
sed -i 's/AppSecret\s*=\s*".*"/AppSecret = "${{ secrets.AppSecret }}"/' main.go
fi
go build -ldflags="-s -w" -o bin/main
if [[ "$RUNNER_OS" == "macOS" ]]; then
mv bin/main bin/dandanplay${{ matrix.ext }}
fi
rm -f main.go
- name: Compress with UPX
if: matrix.os != 'macos-latest'
run: upx --best --lzma -o bin/dandanplay${{ matrix.ext }} bin/main
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: dandanplay-${{ matrix.os }}
path: bin/dandanplay${{ matrix.ext }}