name: Build and Push Images Based on Version # 在这里定义统一版本号 env: VERSION: "2.0.0-beta" on: push: branches: - main - beta jobs: 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 steps: - uses: actions/checkout@v3 - name: Set up Go uses: actions/setup-go@v4 with: go-version: '1.21' - name: Cache Go modules uses: actions/cache@v3 with: path: | ~/.cache/go-build ~/go/pkg/mod key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | ${{ runner.os }}-go- - name: Install UPX run: | wget https://github.com/upx/upx/releases/download/v4.2.1/upx-4.2.1-amd64_linux.tar.xz tar -xf upx-4.2.1-amd64_linux.tar.xz sudo mv upx-4.2.1-amd64_linux/upx /usr/local/bin/ rm -rf upx-4.2.1-amd64_linux* - name: Build GOST binary working-directory: ./go-gost run: | 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 - name: Upload GOST artifact uses: actions/upload-artifact@v4 with: name: gost-binary path: ./go-gost/gost build-vite: name: Build & Push Vite Frontend 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 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 Vite Docker images run: | VERSION="${{ needs.check-version.outputs.version }}" docker buildx build \ --platform linux/amd64 \ --push \ -t bqlpfy/vite-frontend:latest \ -t bqlpfy/vite-frontend:${VERSION} \ ./vite-frontend build-java: 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: | VERSION="${{ needs.check-version.outputs.version }}" docker buildx build \ --platform linux/amd64 \ --push \ -t bqlpfy/springboot-backend:latest \ -t bqlpfy/springboot-backend:${VERSION} \ ./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@v4 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}\` / \`bqlpfy/vite-frontend:latest\` - **Spring Boot Backend** Docker Image: \`bqlpfy/springboot-backend:${VERSION}\` / \`bqlpfy/springboot-backend:latest\` ## Installation Files - \`install.sh\` - GOST 客户端安装脚本 - \`panel_install.sh\` - 面板安装脚本 - \`gost.sql\` - 数据库初始化文件 - \`docker-compose-v4.yml\` - Docker Compose 配置 (IPv4) - \`docker-compose-v6.yml\` - Docker Compose 配置 (IPv6) ## Details - Build date: $(date -u +%Y-%m-%dT%H:%M:%SZ) - Commit: ${{ github.sha }}" \ --repo ${{ github.repository }} # 上传所有文件到 release echo "📤 上传 GOST 二进制..." gh release upload "${VERSION}" ./artifacts/gost --clobber echo "📤 上传安装脚本..." gh release upload "${VERSION}" ./install.sh --clobber gh release upload "${VERSION}" ./panel_install.sh --clobber echo "📤 上传配置文件..." gh release upload "${VERSION}" ./docker-compose-v4.yml --clobber gh release upload "${VERSION}" ./docker-compose-v6.yml --clobber echo "✅ 所有文件已上传到 Release ${VERSION}"