Files
OpenFlare/.gitea/workflows/release.yml
T
2026-06-01 19:04:01 +08:00

123 lines
4.0 KiB
YAML

name: Release
on:
workflow_dispatch:
push:
tags: ["v*"]
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: https://github.com/actions/checkout@v4
with:
fetch-depth: 0
- name: Resolve version metadata
id: version
shell: bash
run: |
SHOULD_RUN=true
POINTED_TAG="$(git tag --points-at HEAD --list 'v*' | sort -V | tail -n1)"
if [[ "${GITHUB_REF}" == refs/heads/main ]] && [[ -n "$POINTED_TAG" ]]; then
SHOULD_RUN=false
VERSION="$POINTED_TAG"
elif [[ "${GITHUB_REF}" == refs/tags/* ]]; then
VERSION="${GITHUB_REF_NAME}"
else
VERSION="$(git describe --tags)"
fi
echo "should_run=$SHOULD_RUN" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
if [[ "$VERSION" =~ ^v[0-9]+(\.[0-9]+)*$ ]]; then
echo "is_prerelease=false" >> "$GITHUB_OUTPUT"
else
echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
fi
- name: Set up Node.js
if: steps.version.outputs.should_run == 'true'
uses: https://github.com/actions/setup-node@v4
with:
node-version: 20
- name: Build Frontend
if: steps.version.outputs.should_run == 'true'
env:
CI: ""
VERSION: ${{ steps.version.outputs.version }}
run: |
cd openflare_server/web
corepack enable
pnpm install --frozen-lockfile
NEXT_PUBLIC_APP_VERSION="$VERSION" pnpm build
- name: Set up Go
if: steps.version.outputs.should_run == 'true'
uses: https://github.com/actions/setup-go@v5
with:
go-version-file: openflare_server/go.mod
- name: Build Server Binaries
if: steps.version.outputs.should_run == 'true'
shell: bash
env:
CGO_ENABLED: 0
VERSION: ${{ steps.version.outputs.version }}
run: |
set -euo pipefail
mkdir -p dist
cd openflare_server
go mod download
while read -r GOOS GOARCH ASSET_NAME; do
GOOS="$GOOS" GOARCH="$GOARCH" \
go build -trimpath -ldflags "-s -w -X 'openflare/common.Version=$VERSION'" -o "../dist/$ASSET_NAME" .
done <<'EOF'
linux amd64 openflare-server-linux-amd64
linux arm64 openflare-server-linux-arm64
darwin amd64 openflare-server-darwin-amd64
darwin arm64 openflare-server-darwin-arm64
windows amd64 openflare-server-windows-amd64.exe
EOF
- name: Build Agent Binaries
if: steps.version.outputs.should_run == 'true'
shell: bash
env:
CGO_ENABLED: 0
VERSION: ${{ steps.version.outputs.version }}
run: |
set -euo pipefail
cd openflare_agent
go mod download
while read -r GOOS GOARCH ASSET_NAME; do
GOOS="$GOOS" GOARCH="$GOARCH" \
go build -trimpath -ldflags "-s -w -X 'openflare-agent/internal/config.Version=$VERSION'" -o "../dist/$ASSET_NAME" ./cmd/agent
done <<'EOF'
linux amd64 openflare-agent-linux-amd64
linux arm64 openflare-agent-linux-arm64
darwin amd64 openflare-agent-darwin-amd64
darwin arm64 openflare-agent-darwin-arm64
windows amd64 openflare-agent-windows-amd64.exe
EOF
- name: Publish Release
if: steps.version.outputs.should_run == 'true'
uses: https://gitea.com/actions/gitea-release-action@v1
with:
tag_name: ${{ steps.version.outputs.version }}
name: ${{ steps.version.outputs.version }}
target_commitish: ${{ github.sha }}
files: |
dist/*
draft: false
prerelease: ${{ steps.version.outputs.is_prerelease == 'true' }}