mirror of
https://github.com/LiteyukiStudio/spage.git
synced 2026-01-26 05:31:58 +00:00
117 lines
3.4 KiB
YAML
117 lines
3.4 KiB
YAML
name: Build & Publish All-in-One
|
||
|
||
on:
|
||
push:
|
||
branches: [main]
|
||
tags: [v*]
|
||
|
||
env:
|
||
REGISTRY: ghcr.io
|
||
IMAGE_NAME: <your-image-name>
|
||
REPO_OWNER: ${{ github.repository_owner }}
|
||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||
BIN_OUT: build
|
||
DOCKERFILE: ./Dockerfile
|
||
|
||
concurrency:
|
||
group: 'build-aio'
|
||
cancel-in-progress: true
|
||
|
||
jobs:
|
||
build:
|
||
name: Build
|
||
runs-on: ubuntu-latest
|
||
strategy:
|
||
matrix:
|
||
goos: [linux, darwin, windows]
|
||
goarch: [amd64, arm64]
|
||
steps:
|
||
- name: Checkout code
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Setup Go
|
||
uses: actions/setup-go@v5
|
||
|
||
- name: Setup Node.js
|
||
uses: actions/setup-node@v4
|
||
with:
|
||
node-version: 22
|
||
|
||
- name: Build frontend
|
||
run: |
|
||
cd web-src
|
||
npm install pnpm -g
|
||
pnpm install
|
||
pnpm build
|
||
cp -r out/* ../static/dist/
|
||
|
||
- name: Build Go binary
|
||
env:
|
||
GOOS: ${{ matrix.goos }}
|
||
GOARCH: ${{ matrix.goarch }}
|
||
run: |
|
||
mkdir -p ${{ env.BIN_OUT }}/${{ matrix.goos }}-${{ matrix.goarch }}
|
||
go build -o ${{ env.BIN_OUT }}/${{ matrix.goos }}-${{ matrix.goarch }}/spage ./cmd/server
|
||
|
||
- name: Upload artifact
|
||
uses: actions/upload-artifact@v4
|
||
with:
|
||
name: spage-${{ matrix.goos }}-${{ matrix.goarch }}
|
||
path: ${{ env.BIN_OUT }}/${{ matrix.goos }}-${{ matrix.goarch }}/spage
|
||
|
||
publish:
|
||
name: Publish Artifacts & Images
|
||
runs-on: ubuntu-latest
|
||
needs: build
|
||
steps:
|
||
- name: Download all artifacts
|
||
uses: actions/download-artifact@v4
|
||
with:
|
||
pattern: spage-*
|
||
path: ${{ env.BIN_OUT }}
|
||
|
||
- name: Set version/tag
|
||
id: version
|
||
run: |
|
||
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
|
||
VERSION="${GITHUB_REF#refs/tags/}"
|
||
TAG="${VERSION}"
|
||
NIGHTLY="false"
|
||
else
|
||
VERSION="${GITHUB_SHA}"
|
||
TAG="nightly"
|
||
NIGHTLY="true"
|
||
fi
|
||
echo "version=${VERSION}" >> $GITHUB_OUTPUT
|
||
echo "tag=${TAG}" >> $GITHUB_OUTPUT
|
||
echo "nightly=${NIGHTLY}" >> $GITHUB_OUTPUT
|
||
|
||
- name: Build and push container image
|
||
env:
|
||
TAG: ${{ steps.version.outputs.tag }}
|
||
REGISTRY: ${{ env.REGISTRY }}
|
||
IMAGE_NAME: ${{ env.IMAGE_NAME }}
|
||
REPO_OWNER: ${{ env.REPO_OWNER }}
|
||
GH_TOKEN: ${{ env.GH_TOKEN }}
|
||
run: |
|
||
echo "${GH_TOKEN}" | docker login $REGISTRY -u $REPO_OWNER --password-stdin
|
||
docker build -f ${{ env.DOCKERFILE }} -t $REGISTRY/$REPO_OWNER/$IMAGE_NAME:$TAG .
|
||
docker push $REGISTRY/$REPO_OWNER/$IMAGE_NAME:$TAG
|
||
# 如果是release,额外推送latest标签
|
||
if [[ "${{ steps.version.outputs.nightly }}" == "false" ]]; then
|
||
docker tag $REGISTRY/$REPO_OWNER/$IMAGE_NAME:$TAG $REGISTRY/$REPO_OWNER/$IMAGE_NAME:latest
|
||
docker push $REGISTRY/$REPO_OWNER/$IMAGE_NAME:latest
|
||
fi
|
||
|
||
- name: Publish GitHub Release
|
||
if: ${{ steps.version.outputs.nightly == 'false' }}
|
||
uses: softprops/action-gh-release@v2
|
||
with:
|
||
tag_name: ${{ steps.version.outputs.tag }}
|
||
name: Release ${{ steps.version.outputs.tag }}
|
||
body: |
|
||
Release ${{ steps.version.outputs.tag }}
|
||
Built from tag ${{ steps.version.outputs.tag }}
|
||
files: |
|
||
${{ env.BIN_OUT }}/**/spage
|