Compare commits
4 Commits
121acebb66
...
v1.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
| 30f4ebbd6d | |||
| 17a0346aa8 | |||
| 6578e93a16 | |||
| 4c6d3e0dde |
105
.gitea/workflows/build-release.yml
Normal file
105
.gitea/workflows/build-release.yml
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
name: Build and Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-release:
|
||||||
|
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_NAME=${OUTPUT_NAME}" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Create or Update Release
|
||||||
|
run: |
|
||||||
|
VERSION="${{ steps.version.outputs.VERSION }}"
|
||||||
|
REPO="${{ gitea.repository }}"
|
||||||
|
SERVER="${{ gitea.server_url }}"
|
||||||
|
TOKEN="${{ secrets.GITEA_TOKEN }}"
|
||||||
|
|
||||||
|
# Try to create release (ignore error if already exists)
|
||||||
|
curl -X POST "${SERVER}/api/v1/repos/${REPO}/releases" \
|
||||||
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"tag_name": "'${VERSION}'",
|
||||||
|
"target_commitish": "main",
|
||||||
|
"name": "Release '${VERSION}'",
|
||||||
|
"body": "# SafelineAPI '${VERSION}'\n\n## Available Downloads\n\n### Linux\n- **amd64**: safelineApi-linux-amd64\n- **ARM64**: safelineApi-linux-arm64\n- **ARMv7**: safelineApi-linux-armv7\n- **386**: safelineApi-linux-386\n- **PowerPC 64LE**: safelineApi-linux-ppc64le\n\n### Windows\n- **amd64**: safelineApi-windows-amd64.exe\n- **386**: safelineApi-windows-386.exe",
|
||||||
|
"draft": false,
|
||||||
|
"prerelease": false
|
||||||
|
}' || true
|
||||||
|
|
||||||
|
- name: Upload Binary Asset
|
||||||
|
run: |
|
||||||
|
VERSION="${{ steps.version.outputs.VERSION }}"
|
||||||
|
REPO="${{ gitea.repository }}"
|
||||||
|
SERVER="${{ gitea.server_url }}"
|
||||||
|
TOKEN="${{ secrets.GITEA_TOKEN }}"
|
||||||
|
BINARY="${{ env.BINARY_NAME }}"
|
||||||
|
|
||||||
|
# Get release ID
|
||||||
|
RELEASE_ID=$(curl -s "${SERVER}/api/v1/repos/${REPO}/releases/tags/${VERSION}" \
|
||||||
|
-H "Authorization: token ${TOKEN}" | grep '"id"' | head -1 | grep -o '[0-9]*')
|
||||||
|
|
||||||
|
# Upload the binary
|
||||||
|
curl -X POST "${SERVER}/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets" \
|
||||||
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
-F "attachment=@bin/${BINARY}" || true
|
||||||
Reference in New Issue
Block a user