Skip to content

Add GitHub Actions build workflow #1

Add GitHub Actions build workflow

Add GitHub Actions build workflow #1

Workflow file for this run

name: Build
on:
push:
branches:
- main
tags:
- "v*"
pull_request:
workflow_dispatch:
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Run tests
run: go test ./...
build:
name: Build ${{ matrix.name }}
needs: test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: Linux
os: ubuntu-latest
goos: linux
goarch: amd64
artifact: M45-Relay-Client-Linux.zip
- name: macOS
os: macos-latest
artifact: M45-Relay-Client-Mac.zip
- name: Windows
os: windows-latest
goos: windows
goarch: amd64
artifact: M45-Relay-Client-Win.zip
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Resolve version
id: version
shell: bash
run: |
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
VERSION="${GITHUB_REF_NAME}"
else
VERSION="dev-${GITHUB_SHA::7}"
fi
echo "value=${VERSION}" >> "${GITHUB_OUTPUT}"
- name: Build Linux
if: matrix.name == 'Linux'
shell: bash
run: |
APP_NAME="M45-Relay-Client"
VERSION="${{ steps.version.outputs.value }}"
GOOS="${{ matrix.goos }}" GOARCH="${{ matrix.goarch }}" go build \
-ldflags "-X main.publicClientFlag=true -X main.version=${VERSION}" \
-o "${APP_NAME}"
zip "${{ matrix.artifact }}" "${APP_NAME}" readme.txt READ-ME.html
- name: Build macOS universal app
if: matrix.name == 'macOS'
shell: bash
run: |
APP_NAME="M45-Relay-Client"
VERSION="${{ steps.version.outputs.value }}"
BINARY_NAME="${APP_NAME}"
WRAPPER_SCRIPT="run.sh"
IDENTIFIER="com.M45.M45-Relay-Client"
GOOS=darwin GOARCH=amd64 go build \
-ldflags "-X main.publicClientFlag=true -X main.version=${VERSION}" \
-o "${BINARY_NAME}-amd64" .
GOOS=darwin GOARCH=arm64 go build \
-ldflags "-X main.publicClientFlag=true -X main.version=${VERSION}" \
-o "${BINARY_NAME}-arm64" .
lipo -create \
"${BINARY_NAME}-amd64" "${BINARY_NAME}-arm64" \
-output "${BINARY_NAME}"
rm -rf "${APP_NAME}.app"
mkdir -p "${APP_NAME}.app/Contents/MacOS"
mkdir -p "${APP_NAME}.app/Contents/Resources"
mv "${BINARY_NAME}" "${APP_NAME}.app/Contents/MacOS/${BINARY_NAME}"
cat > "${APP_NAME}.app/Contents/MacOS/${WRAPPER_SCRIPT}" <<EOF
#!/bin/bash
SELF_DIR="\$(cd "\$(dirname "\${BASH_SOURCE[0]}")" && pwd)"
osascript <<OSASCRIPT
tell application "Terminal"
activate
do script "\\\"\$SELF_DIR/${BINARY_NAME}\\\""
end tell
OSASCRIPT
exit 0
EOF
chmod +x "${APP_NAME}.app/Contents/MacOS/${WRAPPER_SCRIPT}"
cat > "${APP_NAME}.app/Contents/Info.plist" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>${APP_NAME}</string>
<key>CFBundleDisplayName</key>
<string>${APP_NAME}</string>
<key>CFBundleExecutable</key>
<string>${WRAPPER_SCRIPT}</string>
<key>CFBundleIdentifier</key>
<string>${IDENTIFIER}</string>
<key>CFBundleVersion</key>
<string>${VERSION}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
</dict>
</plist>
EOF
ditto -c -k --sequesterRsrc --keepParent \
"${APP_NAME}.app" "${{ matrix.artifact }}"
- name: Build Windows unsigned
if: matrix.name == 'Windows'
shell: bash
run: |
APP_NAME="M45-Relay-Client"
VERSION="${{ steps.version.outputs.value }}"
GOOS="${{ matrix.goos }}" GOARCH="${{ matrix.goarch }}" go build \
-ldflags "-X main.publicClientFlag=true -X main.version=${VERSION}" \
-o "${APP_NAME}.exe"
powershell -NoProfile -Command \
"Compress-Archive -Path '${APP_NAME}.exe','readme.txt','READ-ME.html' -DestinationPath '${{ matrix.artifact }}'"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: ${{ matrix.artifact }}
if-no-files-found: error