mirror of
https://github.com/komari-monitor/komari.git
synced 2026-11-11 08:42:39 +00:00
145 lines
4.4 KiB
YAML
145 lines
4.4 KiB
YAML
name: Build and Attach Binaries to Release
|
|
|
|
on:
|
|
release:
|
|
types: [published]
|
|
|
|
permissions:
|
|
contents: write
|
|
packages: write
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
jobs:
|
|
build-and-attach-binaries:
|
|
runs-on: ubuntu-latest
|
|
|
|
strategy:
|
|
matrix:
|
|
goos: [windows, linux]
|
|
goarch: [amd64, arm64]
|
|
include:
|
|
- goos: windows
|
|
goarch: amd64
|
|
gcc: x86_64-w64-mingw32-gcc
|
|
CGO_CFLAGS: ''
|
|
CGO_LDFLAGS: ''
|
|
- goos: linux
|
|
goarch: amd64
|
|
gcc: gcc
|
|
CGO_CFLAGS: ''
|
|
CGO_LDFLAGS: ''
|
|
- goos: linux
|
|
goarch: arm64
|
|
gcc: aarch64-linux-gnu-gcc
|
|
CGO_CFLAGS: '-pthread'
|
|
CGO_LDFLAGS: '-pthread'
|
|
exclude:
|
|
- goos: windows
|
|
goarch: arm64
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "23"
|
|
|
|
- name: Clone and build frontend
|
|
run: |
|
|
git clone https://github.com/komari-monitor/komari-web web
|
|
cd web
|
|
npm install
|
|
npm run build
|
|
cd ..
|
|
mkdir -p public/dist
|
|
cp -r web/dist/* public/dist/
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: "1.23"
|
|
|
|
- name: Install cross-compiler
|
|
run: |
|
|
sudo apt-get update
|
|
if [ "${{ matrix.goarch }}" = "arm64" ] && [ "${{ matrix.goos }}" = "linux" ]; then
|
|
sudo apt-get install gcc-aarch64-linux-gnu
|
|
fi
|
|
if [ "${{ matrix.goarch }}" = "amd64" ] && [ "${{ matrix.goos }}" = "windows" ]; then
|
|
sudo apt-get install mingw-w64
|
|
fi
|
|
if [ "${{ matrix.goarch }}" = "arm64" ] && [ "${{ matrix.goos }}" = "windows" ]; then
|
|
sudo apt-get install wget xz-utils
|
|
mkdir -p /tmp/mingw64
|
|
wget https://github.com/mstorsjo/llvm-mingw/releases/download/20250613/llvm-mingw-20250613-ucrt-ubuntu-22.04-aarch64.tar.xz -O /tmp/mingw64.tar.xz
|
|
tar -xf /tmp/mingw64.tar.xz -C /tmp/mingw64 --strip-components=1
|
|
fi
|
|
|
|
- name: Build binary
|
|
env:
|
|
GOOS: ${{ matrix.goos }}
|
|
GOARCH: ${{ matrix.goarch }}
|
|
CGO_ENABLED: 1
|
|
CC: ${{ matrix.gcc }}
|
|
CGO_CFLAGS: ${{ matrix.CGO_CFLAGS }}
|
|
CGO_LDFLAGS: ${{ matrix.CGO_LDFLAGS }}
|
|
GIN_MODE: release
|
|
run: |
|
|
BINARY_NAME=komari-${{ matrix.goos }}-${{ matrix.goarch }}
|
|
if [ "${{ matrix.goos }}" = "windows" ]; then
|
|
BINARY_NAME=${BINARY_NAME}.exe
|
|
fi
|
|
VERSION="${{ github.event.release.tag_name }}"
|
|
VERSION_HASH="${{ github.sha }}"
|
|
go build -trimpath -ldflags="-s -w -X github.com/komari-monitor/komari/utils.CurrentVersion=${VERSION} -X github.com/komari-monitor/komari/utils.VersionHash=${VERSION_HASH}" -o $BINARY_NAME
|
|
|
|
- name: Upload binary to release
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
BINARY_NAME=komari-${{ matrix.goos }}-${{ matrix.goarch }}
|
|
if [ "${{ matrix.goos }}" = "windows" ]; then
|
|
BINARY_NAME=${BINARY_NAME}.exe
|
|
fi
|
|
gh release upload ${{ github.event.release.tag_name }} $BINARY_NAME --repo ${{ github.repository }}
|
|
shell: bash
|
|
|
|
build-and-push-docker:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Log in to the Container registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract metadata (tags, labels) for Docker
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
tags: |
|
|
type=raw,value=${{ github.event.release.tag_name }}
|
|
type=raw,value=latest
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
build-args: |
|
|
VERSION=${{ github.event.release.tag_name }}
|
|
VERSION_HASH=${{ github.sha }}
|