name: Build and Push Images + GOST on: push: branches: - main workflow_dispatch: # 可以手动触发 jobs: build: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 - name: Set release version # 直接写这次更新的版本号,或者用 workflow_dispatch 输入 run: | RELEASE_VERSION="2.0.0" echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV echo "Release version: $RELEASE_VERSION" - name: Get latest Git tag id: get_tag run: | LATEST_TAG=$(git describe --tags --abbrev=0 || echo "") echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV echo "Latest tag: $LATEST_TAG" - name: Compare version with latest tag id: compare run: | if [ "v${RELEASE_VERSION}" = "$LATEST_TAG" ]; then echo "Version matches latest tag, skipping build" echo "SKIP_BUILD=true" >> $GITHUB_ENV else echo "New version detected, building" echo "SKIP_BUILD=false" >> $GITHUB_ENV - 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 if: env.SKIP_BUILD == 'false' env: GH_TOKEN: ${{ github.token }} run: | cd go-gost CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o gost upx --best --lzma gost cd .. if gh release view "v${RELEASE_VERSION}" 2>/dev/null; then echo "Release exists, updating GOST binary" else gh release create "v${RELEASE_VERSION}" go-gost/gost \ --title "GOST Binary v${RELEASE_VERSION}" \ --notes "GOST compiled from commit ${{ github.sha }}" fi gh release upload "v${RELEASE_VERSION}" ./go-gost/gost --clobber - name: Set up Docker Buildx if: env.SKIP_BUILD == 'false' uses: docker/setup-buildx-action@v2 - name: Docker login if: env.SKIP_BUILD == 'false' uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_TOKEN }} - name: Build and push Vite Docker if: env.SKIP_BUILD == 'false' run: | docker buildx build \ --platform linux/amd64 \ --push \ -t bqlpfy/vite-frontend:${RELEASE_VERSION} \ -t bqlpfy/vite-frontend:latest \ ./vite-frontend - name: Build and push Java Docker if: env.SKIP_BUILD == 'false' run: | cd springboot-backend mvn clean package -DskipTests cd .. docker buildx build \ --platform linux/amd64 \ --push \ -t bqlpfy/springboot-backend:${RELEASE_VERSION} \ -t bqlpfy/springboot-backend:latest \ ./springboot-backend