166 lines
5.2 KiB
YAML
166 lines
5.2 KiB
YAML
name: Build and publish Jiaowu packages and container image
|
||
|
||
on:
|
||
push:
|
||
tags:
|
||
- "v*"
|
||
workflow_dispatch:
|
||
inputs:
|
||
include_extended_platforms:
|
||
description: "同时构建 Windows ARM64 和 macOS x64/ARM64"
|
||
required: false
|
||
default: false
|
||
type: boolean
|
||
|
||
env:
|
||
GITEA_IMAGE: git.biss.click/biss/academic-affairs-system
|
||
|
||
jobs:
|
||
publish:
|
||
name: Test, package and publish
|
||
runs-on: ubuntu-latest
|
||
permissions:
|
||
code: read
|
||
packages: write
|
||
releases: write
|
||
|
||
steps:
|
||
- name: Check out repository
|
||
uses: https://github.com/actions/checkout@v4
|
||
|
||
- name: Set up .NET
|
||
uses: https://github.com/actions/setup-dotnet@v4
|
||
with:
|
||
dotnet-version: "10.0.302"
|
||
|
||
- name: Set up Node.js
|
||
uses: https://github.com/actions/setup-node@v4
|
||
with:
|
||
node-version: "24"
|
||
cache: npm
|
||
cache-dependency-path: web/package-lock.json
|
||
|
||
- name: Build Vue application
|
||
working-directory: web
|
||
run: |
|
||
npm ci
|
||
npm run build
|
||
|
||
- name: Run backend tests
|
||
run: dotnet test Jiaowu.slnx --configuration Release
|
||
|
||
- name: Determine package version and platform profile
|
||
id: package
|
||
shell: bash
|
||
env:
|
||
REF_TYPE: ${{ gitea.ref_type }}
|
||
REF_NAME: ${{ gitea.ref_name }}
|
||
RUN_NUMBER: ${{ gitea.run_number }}
|
||
INCLUDE_EXTENDED_PLATFORMS: ${{ inputs.include_extended_platforms }}
|
||
run: |
|
||
set -euo pipefail
|
||
if [[ "$REF_TYPE" == "tag" && "$REF_NAME" == v* ]]; then
|
||
version="${REF_NAME#v}"
|
||
else
|
||
version="0.0.0-dev.${RUN_NUMBER:-0}"
|
||
fi
|
||
|
||
profile=default
|
||
if [[ "${INCLUDE_EXTENDED_PLATFORMS:-false}" == "true" ]]; then
|
||
profile=all
|
||
fi
|
||
|
||
echo "version=$version" >> "$GITHUB_OUTPUT"
|
||
echo "profile=$profile" >> "$GITHUB_OUTPUT"
|
||
|
||
- name: Build self-contained platform packages
|
||
shell: bash
|
||
run: |
|
||
bash ./scripts/publish-platform-packages.sh \
|
||
"${{ steps.package.outputs.version }}" \
|
||
"artifacts/packages" \
|
||
"${{ steps.package.outputs.profile }}"
|
||
|
||
- name: Upload platform packages as workflow artifact
|
||
uses: https://github.com/christopherHX/gitea-upload-artifact@v4
|
||
with:
|
||
name: jiaowu-${{ steps.package.outputs.version }}-${{ steps.package.outputs.profile }}-packages
|
||
path: artifacts/packages/*
|
||
if-no-files-found: error
|
||
|
||
- name: Set up QEMU
|
||
uses: https://github.com/docker/setup-qemu-action@v3
|
||
|
||
- name: Set up Docker Buildx
|
||
uses: https://github.com/docker/setup-buildx-action@v3
|
||
|
||
- name: Log in to Gitea Container Registry
|
||
uses: https://github.com/docker/login-action@v3
|
||
with:
|
||
registry: git.biss.click
|
||
username: ${{ gitea.actor }}
|
||
password: ${{ secrets.GITEA_TOKEN }}
|
||
|
||
- name: Generate image tags and labels
|
||
id: metadata
|
||
uses: https://github.com/docker/metadata-action@v5
|
||
with:
|
||
images: ${{ env.GITEA_IMAGE }}
|
||
flavor: latest=auto
|
||
tags: |
|
||
type=sha,format=short,prefix=sha-
|
||
type=semver,pattern={{version}}
|
||
type=semver,pattern={{major}}.{{minor}}
|
||
type=raw,value=manual-${{ gitea.run_number }},enable=${{ gitea.ref_type != 'tag' }}
|
||
|
||
- name: Build and push multi-architecture image
|
||
uses: https://github.com/docker/build-push-action@v6
|
||
with:
|
||
context: .
|
||
file: ./Dockerfile
|
||
platforms: linux/amd64,linux/arm64
|
||
push: true
|
||
tags: ${{ steps.metadata.outputs.tags }}
|
||
labels: ${{ steps.metadata.outputs.labels }}
|
||
cache-from: type=registry,ref=${{ env.GITEA_IMAGE }}:buildcache
|
||
cache-to: type=registry,ref=${{ env.GITEA_IMAGE }}:buildcache,mode=max
|
||
|
||
- name: Detect release type
|
||
id: release
|
||
if: gitea.ref_type == 'tag'
|
||
shell: bash
|
||
env:
|
||
REF_NAME: ${{ gitea.ref_name }}
|
||
run: |
|
||
case "$REF_NAME" in
|
||
*-*) prerelease=true ;;
|
||
*) prerelease=false ;;
|
||
esac
|
||
echo "prerelease=$prerelease" >> "$GITHUB_OUTPUT"
|
||
|
||
- name: Create Gitea release
|
||
if: gitea.ref_type == 'tag'
|
||
uses: https://github.com/akkuman/gitea-release-action@v1
|
||
with:
|
||
token: ${{ secrets.GITEA_TOKEN }}
|
||
tag_name: ${{ gitea.ref_name }}
|
||
name: ${{ gitea.ref_name }}
|
||
prerelease: ${{ steps.release.outputs.prerelease }}
|
||
files: |
|
||
artifacts/packages/*
|
||
body: |
|
||
已发布大学教务管理系统 ${{ gitea.ref_name }}:
|
||
|
||
- Windows x64:`.zip`
|
||
- Linux x64 / ARM64:`.tar.gz`
|
||
- `SHA256SUMS`:发布包校验值
|
||
- 自包含程序包无需预装 .NET 或 ASP.NET Core Runtime
|
||
|
||
Windows ARM64 与 macOS Intel / Apple Silicon 包可通过手动运行工作流并启用扩展平台生成。
|
||
|
||
Docker 多架构镜像(linux/amd64、linux/arm64):
|
||
|
||
```text
|
||
docker pull ${{ env.GITEA_IMAGE }}:${{ steps.metadata.outputs.version }}
|
||
```
|