mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-10-07 02:06:38 +08:00
test
This commit is contained in:
@@ -1,99 +1,203 @@
|
|||||||
name: Build and Push Images + GOST
|
name: Build and Push Images Based on Version
|
||||||
|
|
||||||
|
# 在这里定义统一版本号
|
||||||
|
env:
|
||||||
|
VERSION: "v3.1.0"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
workflow_dispatch: # 可以手动触发
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
check-version:
|
||||||
|
name: Check Version and Decide Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
version: ${{ env.VERSION }}
|
||||||
|
should_build: ${{ steps.check-tag.outputs.should_build }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # 获取所有历史和 tags
|
||||||
|
|
||||||
|
- name: Display version
|
||||||
|
run: |
|
||||||
|
echo "Current version: ${{ env.VERSION }}"
|
||||||
|
|
||||||
|
- name: Check if tag exists
|
||||||
|
id: check-tag
|
||||||
|
run: |
|
||||||
|
if git rev-parse "${{ env.VERSION }}" >/dev/null 2>&1; then
|
||||||
|
echo "Tag ${{ env.VERSION }} already exists, skip build"
|
||||||
|
echo "should_build=false" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "Tag ${{ env.VERSION }} does not exist, will build all components"
|
||||||
|
echo "should_build=true" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
|
build-gost:
|
||||||
|
name: Build & Compress GOST Binary
|
||||||
|
needs: check-version
|
||||||
|
if: needs.check-version.outputs.should_build == 'true'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- uses: actions/checkout@v3
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Set release version
|
- name: Set up Go
|
||||||
# 直接写这次更新的版本号,或者用 workflow_dispatch 输入
|
uses: actions/setup-go@v4
|
||||||
run: |
|
with:
|
||||||
RELEASE_VERSION="2.0.0"
|
go-version: '1.21'
|
||||||
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
|
|
||||||
echo "Release version: $RELEASE_VERSION"
|
|
||||||
|
|
||||||
- name: Get latest Git tag
|
- name: Cache Go modules
|
||||||
id: get_tag
|
uses: actions/cache@v3
|
||||||
run: |
|
with:
|
||||||
LATEST_TAG=$(git describe --tags --abbrev=0 || echo "")
|
path: |
|
||||||
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
|
~/.cache/go-build
|
||||||
echo "Latest tag: $LATEST_TAG"
|
~/go/pkg/mod
|
||||||
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-go-
|
||||||
|
|
||||||
- name: Compare version with latest tag
|
- name: Install UPX
|
||||||
id: compare
|
|
||||||
run: |
|
run: |
|
||||||
if [ "v${RELEASE_VERSION}" = "$LATEST_TAG" ]; then
|
wget https://github.com/upx/upx/releases/download/v4.2.1/upx-4.2.1-amd64_linux.tar.xz
|
||||||
echo "Version matches latest tag, skipping build"
|
tar -xf upx-4.2.1-amd64_linux.tar.xz
|
||||||
echo "SKIP_BUILD=true" >> $GITHUB_ENV
|
sudo mv upx-4.2.1-amd64_linux/upx /usr/local/bin/
|
||||||
else
|
rm -rf upx-4.2.1-amd64_linux*
|
||||||
echo "New version detected, building"
|
|
||||||
echo "SKIP_BUILD=false" >> $GITHUB_ENV
|
|
||||||
fi
|
|
||||||
- name: Create Git tag for new version
|
|
||||||
if: env.SKIP_BUILD == 'false'
|
|
||||||
run: |
|
|
||||||
git config user.name "github-actions"
|
|
||||||
git config user.email "github-actions@users.noreply.github.com"
|
|
||||||
git tag -a "v${RELEASE_VERSION}" -m "Release v${RELEASE_VERSION}"
|
|
||||||
git push origin "v${RELEASE_VERSION}"
|
|
||||||
|
|
||||||
- name: Build & Release GOST
|
- name: Build GOST binary
|
||||||
if: env.SKIP_BUILD == 'false'
|
working-directory: ./go-gost
|
||||||
env:
|
|
||||||
GH_TOKEN: ${{ github.token }}
|
|
||||||
run: |
|
run: |
|
||||||
cd go-gost
|
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o gost
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o gost
|
||||||
|
|
||||||
|
- name: Compress with UPX
|
||||||
|
working-directory: ./go-gost
|
||||||
|
run: |
|
||||||
upx --best --lzma gost
|
upx --best --lzma gost
|
||||||
cd ..
|
|
||||||
|
- name: Upload GOST artifact
|
||||||
if gh release view "v${RELEASE_VERSION}" 2>/dev/null; then
|
uses: actions/upload-artifact@v3
|
||||||
echo "Release exists, updating GOST binary"
|
with:
|
||||||
else
|
name: gost-binary
|
||||||
gh release create "v${RELEASE_VERSION}" go-gost/gost \
|
path: ./go-gost/gost
|
||||||
--title "GOST Binary v${RELEASE_VERSION}" \
|
|
||||||
--notes "GOST compiled from commit ${{ github.sha }}"
|
build-vite:
|
||||||
fi
|
name: Build & Push Vite Frontend
|
||||||
gh release upload "v${RELEASE_VERSION}" ./go-gost/gost --clobber
|
needs: check-version
|
||||||
|
if: needs.check-version.outputs.should_build == 'true'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 20
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
if: env.SKIP_BUILD == 'false'
|
|
||||||
uses: docker/setup-buildx-action@v2
|
uses: docker/setup-buildx-action@v2
|
||||||
|
|
||||||
- name: Docker login
|
- name: Log in to DockerHub
|
||||||
if: env.SKIP_BUILD == 'false'
|
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKER_HUB_TOKEN }}
|
password: ${{ secrets.DOCKER_HUB_TOKEN }}
|
||||||
|
|
||||||
- name: Build and push Vite Docker
|
- name: Build and push Vite Docker images
|
||||||
if: env.SKIP_BUILD == 'false'
|
|
||||||
run: |
|
run: |
|
||||||
|
VERSION="${{ needs.check-version.outputs.version }}"
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--platform linux/amd64 \
|
--platform linux/amd64 \
|
||||||
--push \
|
--push \
|
||||||
-t bqlpfy/vite-frontend:${RELEASE_VERSION} \
|
|
||||||
-t bqlpfy/vite-frontend:latest \
|
-t bqlpfy/vite-frontend:latest \
|
||||||
|
-t bqlpfy/vite-frontend:${VERSION} \
|
||||||
./vite-frontend
|
./vite-frontend
|
||||||
|
|
||||||
- name: Build and push Java Docker
|
build-java:
|
||||||
if: env.SKIP_BUILD == 'false'
|
name: Build & Push Spring Boot Backend
|
||||||
|
needs: check-version
|
||||||
|
if: needs.check-version.outputs.should_build == 'true'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up JDK and Maven
|
||||||
|
uses: actions/setup-java@v3
|
||||||
|
with:
|
||||||
|
java-version: 21
|
||||||
|
distribution: 'temurin'
|
||||||
|
|
||||||
|
- name: Cache Maven dependencies
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: ~/.m2
|
||||||
|
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
||||||
|
restore-keys: ${{ runner.os }}-m2
|
||||||
|
|
||||||
|
- name: Build Java JAR
|
||||||
|
working-directory: ./springboot-backend
|
||||||
|
run: mvn clean package -DskipTests
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
|
||||||
|
- name: Log in to DockerHub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_HUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push Java Docker images
|
||||||
run: |
|
run: |
|
||||||
cd springboot-backend
|
VERSION="${{ needs.check-version.outputs.version }}"
|
||||||
mvn clean package -DskipTests
|
|
||||||
cd ..
|
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--platform linux/amd64 \
|
--platform linux/amd64 \
|
||||||
--push \
|
--push \
|
||||||
-t bqlpfy/springboot-backend:${RELEASE_VERSION} \
|
|
||||||
-t bqlpfy/springboot-backend:latest \
|
-t bqlpfy/springboot-backend:latest \
|
||||||
|
-t bqlpfy/springboot-backend:${VERSION} \
|
||||||
./springboot-backend
|
./springboot-backend
|
||||||
|
|
||||||
|
create-release:
|
||||||
|
name: Create Release and Tag
|
||||||
|
needs: [check-version, build-gost, build-vite, build-java]
|
||||||
|
if: needs.check-version.outputs.should_build == 'true'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Download GOST binary
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: gost-binary
|
||||||
|
path: ./artifacts
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
run: |
|
||||||
|
VERSION="${{ needs.check-version.outputs.version }}"
|
||||||
|
|
||||||
|
# 创建并推送 tag
|
||||||
|
git tag "${VERSION}" ${{ github.sha }}
|
||||||
|
git push origin "${VERSION}"
|
||||||
|
|
||||||
|
# 创建 release
|
||||||
|
gh release create "${VERSION}" \
|
||||||
|
--title "Release ${VERSION}" \
|
||||||
|
--notes "Version ${VERSION}
|
||||||
|
|
||||||
|
## Components
|
||||||
|
- GOST Binary (Linux AMD64, compressed with UPX)
|
||||||
|
- Vite Frontend Docker Image: \`bqlpfy/vite-frontend:${VERSION}\`
|
||||||
|
- Spring Boot Backend Docker Image: \`bqlpfy/springboot-backend:${VERSION}\`
|
||||||
|
|
||||||
|
## Details
|
||||||
|
- Build date: $(date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||||
|
- Commit: ${{ github.sha }}" \
|
||||||
|
--repo ${{ github.repository }}
|
||||||
|
|
||||||
|
# 上传 GOST binary
|
||||||
|
gh release upload "${VERSION}" ./artifacts/gost --clobber
|
||||||
|
|||||||
+2
-1
@@ -258,4 +258,5 @@ android-app/
|
|||||||
ios-app/
|
ios-app/
|
||||||
doraemon.jks
|
doraemon.jks
|
||||||
flux.ipa
|
flux.ipa
|
||||||
device.id
|
device.id
|
||||||
|
commit.sh
|
||||||
Reference in New Issue
Block a user