mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-05 00:45:29 +08:00
170 lines
4.6 KiB
YAML
170 lines
4.6 KiB
YAML
name: Release Artifacts
|
|
|
|
on:
|
|
release:
|
|
types:
|
|
- published
|
|
|
|
permissions:
|
|
contents: write
|
|
packages: write
|
|
|
|
jobs:
|
|
build-and-upload:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: "1.24.x"
|
|
|
|
- name: Setup Node
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "20"
|
|
cache: "npm"
|
|
cache-dependency-path: webui/package-lock.json
|
|
|
|
- name: Build WebUI
|
|
run: |
|
|
npm ci --prefix webui
|
|
npm run build --prefix webui
|
|
|
|
- name: Build Multi-Platform Archives
|
|
run: |
|
|
set -euo pipefail
|
|
TAG="${{ github.event.release.tag_name }}"
|
|
mkdir -p dist
|
|
|
|
targets=(
|
|
"linux/amd64"
|
|
"linux/arm64"
|
|
"darwin/amd64"
|
|
"darwin/arm64"
|
|
"windows/amd64"
|
|
)
|
|
|
|
for target in "${targets[@]}"; do
|
|
GOOS="${target%/*}"
|
|
GOARCH="${target#*/}"
|
|
PKG="ds2api_${TAG}_${GOOS}_${GOARCH}"
|
|
STAGE="dist/${PKG}"
|
|
BIN="ds2api"
|
|
if [ "${GOOS}" = "windows" ]; then
|
|
BIN="ds2api.exe"
|
|
fi
|
|
|
|
mkdir -p "${STAGE}/static"
|
|
CGO_ENABLED=0 GOOS="${GOOS}" GOARCH="${GOARCH}" \
|
|
go build -trimpath -ldflags="-s -w" -o "${STAGE}/${BIN}" ./cmd/ds2api
|
|
|
|
cp config.example.json .env.example sha3_wasm_bg.7b9ca65ddd.wasm LICENSE README.MD README.en.md "${STAGE}/"
|
|
cp -R static/admin "${STAGE}/static/admin"
|
|
|
|
if [ "${GOOS}" = "windows" ]; then
|
|
(cd dist && zip -rq "${PKG}.zip" "${PKG}")
|
|
else
|
|
tar -C dist -czf "dist/${PKG}.tar.gz" "${PKG}"
|
|
fi
|
|
|
|
rm -rf "${STAGE}"
|
|
done
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract Docker metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ghcr.io/${{ github.repository }}
|
|
tags: |
|
|
type=raw,value=${{ github.event.release.tag_name }}
|
|
type=raw,value=latest
|
|
|
|
- name: Build and Push Docker Image
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile
|
|
push: true
|
|
platforms: linux/amd64,linux/arm64
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
|
|
- name: Export Docker image archives for release assets
|
|
run: |
|
|
set -euo pipefail
|
|
TAG="${{ github.event.release.tag_name }}"
|
|
|
|
docker buildx build \
|
|
--platform linux/amd64 \
|
|
--output type=docker,dest="dist/ds2api_${TAG}_docker_linux_amd64.tar" \
|
|
.
|
|
|
|
docker buildx build \
|
|
--platform linux/arm64 \
|
|
--output type=docker,dest="dist/ds2api_${TAG}_docker_linux_arm64.tar" \
|
|
.
|
|
|
|
gzip -f "dist/ds2api_${TAG}_docker_linux_amd64.tar"
|
|
gzip -f "dist/ds2api_${TAG}_docker_linux_arm64.tar"
|
|
|
|
- name: Generate checksums
|
|
run: |
|
|
set -euo pipefail
|
|
(cd dist && sha256sum *.tar.gz *.zip > sha256sums.txt)
|
|
|
|
- name: Upload Release Assets
|
|
uses: softprops/action-gh-release@v2
|
|
with:
|
|
files: |
|
|
dist/*.tar.gz
|
|
dist/*.zip
|
|
dist/sha256sums.txt
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract Docker metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ghcr.io/${{ github.repository }}
|
|
tags: |
|
|
type=raw,value=${{ github.event.release.tag_name }}
|
|
type=raw,value=latest
|
|
|
|
- name: Build and Push Docker Image
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile
|
|
push: true
|
|
platforms: linux/amd64,linux/arm64
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|