Add gitea action to build bins

This commit is contained in:
2025-12-23 11:46:12 +01:00
parent 84b221118a
commit 4c6d3e0dde

View File

@@ -0,0 +1,132 @@
name: Build and Release
on:
push:
tags:
- 'v*'
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
include:
# Linux architectures
- goos: linux
goarch: amd64
name: linux-amd64
- goos: linux
goarch: arm64
name: linux-arm64
- goos: linux
goarch: arm
goarm: '7'
name: linux-armv7
- goos: linux
goarch: '386'
name: linux-386
- goos: linux
goarch: ppc64le
name: linux-ppc64le
# Windows architectures
- goos: windows
goarch: amd64
name: windows-amd64
- goos: windows
goarch: '386'
name: windows-386
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'
- name: Get version
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GOARM: ${{ matrix.goarm }}
VERSION: ${{ steps.version.outputs.VERSION }}
BUILD_TIME: ${{ github.event.head_commit.timestamp }}
run: |
mkdir -p bin
OUTPUT_NAME="safelineApi-${{ matrix.name }}"
if [ "${{ matrix.goos }}" = "windows" ]; then
OUTPUT_NAME="${OUTPUT_NAME}.exe"
fi
go build -ldflags "-X main.Version=${VERSION} -X main.BuildTime=${BUILD_TIME}" \
-o bin/${OUTPUT_NAME} ./cmd/safelineApi
echo "BINARY_PATH=bin/${OUTPUT_NAME}" >> $GITHUB_ENV
echo "BINARY_NAME=${OUTPUT_NAME}" >> $GITHUB_ENV
- name: Create release assets directory
run: |
mkdir -p release-assets
cp ${{ env.BINARY_PATH }} release-assets/
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}
path: release-assets/${{ env.BINARY_NAME }}
retention-days: 1
release:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: release-artifacts
- name: Get version
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Flatten artifacts
run: |
mkdir -p final-release
find release-artifacts -type f -exec mv {} final-release/ \;
ls -la final-release/
- name: Create Release
uses: gitea-github-actions/actions/gitea-release@main
with:
files: final-release/*
draft: false
prerelease: false
title: Release ${{ steps.version.outputs.VERSION }}
body: |
# SafelineAPI ${{ steps.version.outputs.VERSION }}
## Available Downloads
### Linux
- **amd64**: safelineApi-linux-amd64
- **ARM64**: safelineApi-linux-arm64
- **ARMv7**: safelineApi-linux-armv7
- **386**: safelineApi-linux-386
- **PowerPC 64LE**: safelineApi-linux-ppc64le
### Windows
- **amd64**: safelineApi-windows-amd64.exe
- **386**: safelineApi-windows-386.exe
Built at: ${{ github.event.head_commit.timestamp }}
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
GITEA_SERVER: ${{ gitea.server_url }}