mirror of
https://github.com/xxnuo/MTranServer.git
synced 2026-09-03 06:35:20 +08:00
Update Makefile
Update Makefile Update Makefile Update Makefile Update gen_records.go Update build.yml Update build.yml fix: cross build Update build.yml fix: cross build Update build.yml Update build.yml
This commit is contained in:
186
.github/workflows/build.yml
vendored
186
.github/workflows/build.yml
vendored
@@ -1,145 +1,87 @@
|
||||
name: Build and Publish Docker Image
|
||||
name: Build and Release
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [test]
|
||||
tags: ["v*"]
|
||||
pull_request:
|
||||
branches: [test]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
goos: linux
|
||||
goarch: amd64
|
||||
- os: ubuntu-latest
|
||||
goos: linux
|
||||
goarch: arm64
|
||||
- os: ubuntu-latest
|
||||
goos: linux
|
||||
goarch: 386
|
||||
- os: macos-latest
|
||||
goos: darwin
|
||||
goarch: amd64
|
||||
- os: macos-latest
|
||||
goos: darwin
|
||||
goarch: arm64
|
||||
- os: windows-latest
|
||||
goos: windows
|
||||
goarch: amd64
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Update packages
|
||||
run: make update
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
platforms: "arm64,amd64"
|
||||
go-version: "1.25.3"
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
- name: Download resources
|
||||
run: make download
|
||||
env:
|
||||
GOOS: ${{ matrix.goos }}
|
||||
GOARCH: ${{ matrix.goarch }}
|
||||
|
||||
- name: Login to Docker Hub
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v2
|
||||
- name: Build docs
|
||||
run: make generate-docs
|
||||
env:
|
||||
GOOS: ${{ matrix.goos }}
|
||||
GOARCH: ${{ matrix.goarch }}
|
||||
|
||||
- name: Build binary
|
||||
run: make build
|
||||
env:
|
||||
GOOS: ${{ matrix.goos }}
|
||||
GOARCH: ${{ matrix.goarch }}
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
name: mtranserver-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||
path: dist/mtranserver-${{ matrix.goos }}-${{ matrix.goarch }}*
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v2
|
||||
release:
|
||||
needs: build
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Download all artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
path: artifacts
|
||||
|
||||
- name: Extract metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v4
|
||||
- name: Create Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
images: |
|
||||
ghcr.io/${{ github.repository }}
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=ref,event=pr
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=raw,value=latest,enable=${{ github.ref_type == 'tag' }}
|
||||
# 确保标准镜像使用不带后缀的标签
|
||||
flavor: |
|
||||
latest=true
|
||||
|
||||
- name: Build and push standard image
|
||||
id: build-standard
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64/v8
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
- name: Extract metadata for Chinese model
|
||||
id: meta-zh
|
||||
uses: docker/metadata-action@v4
|
||||
with:
|
||||
images: |
|
||||
ghcr.io/${{ github.repository }}
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}
|
||||
tags: |
|
||||
type=ref,event=branch,suffix=-zh
|
||||
type=ref,event=pr,suffix=-zh
|
||||
type=semver,pattern={{version}}-zh
|
||||
type=semver,pattern={{major}}.{{minor}}-zh
|
||||
type=raw,value=latest,enable=${{ github.ref_type == 'tag' }}
|
||||
# 确保生成的标签与其他镜像不冲突
|
||||
flavor: |
|
||||
suffix=-zh,onlatest=true
|
||||
|
||||
- name: Build and push Chinese model image
|
||||
id: build-zh
|
||||
# 确保中文镜像在标准镜像构建完成后构建
|
||||
if: ${{ success() && (steps.build-standard.outcome == 'success' || steps.build-standard.outcome == 'skipped') }}
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile.model
|
||||
platforms: linux/amd64,linux/arm64/v8
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta-zh.outputs.tags }}
|
||||
labels: ${{ steps.meta-zh.outputs.labels }}
|
||||
build-args: |
|
||||
PRELOAD_SRC_LANG=zh-Hans
|
||||
PRELOAD_TARGET_LANG=zh-Hans
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
- name: Extract metadata for Japanese model
|
||||
id: meta-ja
|
||||
uses: docker/metadata-action@v4
|
||||
with:
|
||||
images: |
|
||||
ghcr.io/${{ github.repository }}
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}
|
||||
tags: |
|
||||
type=ref,event=branch,suffix=-ja
|
||||
type=ref,event=pr,suffix=-ja
|
||||
type=semver,pattern={{version}}-ja
|
||||
type=semver,pattern={{major}}.{{minor}}-ja
|
||||
type=raw,value=latest,enable=${{ github.ref_type == 'tag' }}
|
||||
# 确保生成的标签与其他镜像不冲突
|
||||
flavor: |
|
||||
suffix=-ja,onlatest=true
|
||||
|
||||
- name: Build and push Japanese model image
|
||||
id: build-ja
|
||||
# 确保日语镜像在标准镜像构建完成后构建
|
||||
if: ${{ success() && (steps.build-standard.outcome == 'success' || steps.build-standard.outcome == 'skipped') }}
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile.model
|
||||
platforms: linux/amd64,linux/arm64/v8
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta-ja.outputs.tags }}
|
||||
labels: ${{ steps.meta-ja.outputs.labels }}
|
||||
build-args: |
|
||||
PRELOAD_SRC_LANG=ja
|
||||
PRELOAD_TARGET_LANG=ja
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
files: artifacts/**/*
|
||||
draft: false
|
||||
prerelease: false
|
||||
make_latest: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
11
Makefile
11
Makefile
@@ -1,4 +1,4 @@
|
||||
.PHONY: download-core download-records download generate-docs
|
||||
.PHONY: download download-core download-records generate-docs
|
||||
|
||||
# Detect OS and architecture
|
||||
GOOS ?= $(shell go env GOOS)
|
||||
@@ -24,23 +24,22 @@ DOWNLOAD_URL := https://github.com/$(GITHUB_REPO)/releases/latest/download/$(WOR
|
||||
# Extra: js-wasm
|
||||
download-core:
|
||||
touch ./bin/worker
|
||||
@go generate ./bin
|
||||
@GOOS= GOARCH= go generate ./bin
|
||||
@echo "Downloaded core binary from repository successfully"
|
||||
|
||||
download-records:
|
||||
touch ./data/records.json
|
||||
@go run ./data/gen_records.go
|
||||
@GOOS= GOARCH= go generate ./data
|
||||
|
||||
download: download-core download-records
|
||||
@echo "Downloaded successfully"
|
||||
|
||||
generate-docs:
|
||||
@echo "Generating docs..."
|
||||
@go install github.com/swaggo/swag/cmd/swag@latest
|
||||
@swag init -g ./cmd/mtranserver/main.go -o ./internal/docs
|
||||
@GOOS= GOARCH= go run github.com/swaggo/swag/cmd/swag@latest init -g ./cmd/mtranserver/main.go -o ./internal/docs
|
||||
@echo "Docs generated successfully"
|
||||
|
||||
build: generate-docs
|
||||
@echo "Building..."
|
||||
@go build -o ./dist/mtranserver-$(GOOS)-$(GOARCH)$(SUFFIX) ./cmd/mtranserver
|
||||
@echo "Built successfully"
|
||||
@echo "Built successfully"
|
||||
|
||||
@@ -2,8 +2,8 @@ package bin
|
||||
|
||||
import "crypto/sha256"
|
||||
|
||||
//go:generate go run gen_update.go
|
||||
//go:generate go run gen_hash.go
|
||||
//go:generate env GOOS= GOARCH= go run gen_update.go
|
||||
//go:generate env GOOS= GOARCH= go run gen_hash.go
|
||||
|
||||
// GetWorkerInfo returns information about the embedded worker binary
|
||||
func GetWorkerInfo() (hash string, size int) {
|
||||
|
||||
@@ -14,7 +14,7 @@ func main() {
|
||||
log.Printf("Downloading records.json from %s...", models.RecordsUrl)
|
||||
|
||||
// Download using downloader
|
||||
d := downloader.New("./data")
|
||||
d := downloader.New(".")
|
||||
err := d.Download(models.RecordsUrl, models.RecordsFileName, &downloader.DownloadOptions{
|
||||
Context: context.Background(),
|
||||
Overwrite: true,
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
package data
|
||||
|
||||
//go:generate go run gen_records.go
|
||||
//go:generate env GOOS= GOARCH= go run gen_records.go
|
||||
|
||||
Reference in New Issue
Block a user