name: Build on: workflow_dispatch: push: branches: - 'main' paths: - 'VERSION' jobs: build: runs-on: ubuntu-latest strategy: matrix: goos: [linux] goarch: [amd64, arm64] env: OUTPUT_BINARY: ghproxy GO_VERSION: 1.23.2 steps: - uses: actions/checkout@v3 - name: Load VERSION run: | if [ -f VERSION ]; then echo "VERSION=$(cat VERSION)" >> $GITHUB_ENV else echo "VERSION file not found!" && exit 1 fi - name: Set up Go uses: actions/setup-go@v3 with: go-version: ${{ env.GO_VERSION }} - name: Install UPX run: | sudo apt-get update sudo apt-get install -y upx - name: Build env: GOOS: ${{ matrix.goos }} GOARCH: ${{ matrix.goarch }} run: | CGO_ENABLED=0 go build -ldflags="-s -w" -o ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} ./main.go upx -9 ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} - name: Package run: | tar -czvf ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}}.tar.gz ./${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} - name: Upload to GitHub Artifacts uses: actions/upload-artifact@v3 with: name: ${{ env.OUTPUT_BINARY }} path: | ./${{ env.OUTPUT_BINARY }}* - name: 上传至Release id: create_release uses: ncipollo/release-action@v1 with: name: ${{ env.VERSION }} artifacts: ./${{ env.OUTPUT_BINARY }}* token: ${{ secrets.GITHUB_TOKEN }} tag: ${{ env.VERSION }} allowUpdates: true env: export PATH: $PATH:/usr/local/go/bin docker: runs-on: ubuntu-latest needs: build # 确保这个作业在 build 作业完成后运行 env: IMAGE_NAME: wjqserver/ghproxy # 定义镜像名称变量 DOCKERFILE: docker/dockerfile/release/Dockerfile # 定义 Dockerfile 路径变量 steps: - name: Checkout uses: actions/checkout@v4 - name: Load VERSION run: | if [ -f VERSION ]; then echo "VERSION=$(cat VERSION)" >> $GITHUB_ENV else echo "VERSION file not found!" && exit 1 fi - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: 构建镜像 uses: docker/build-push-action@v6 with: file: ./${{ env.DOCKERFILE }} platforms: linux/amd64,linux/arm64 push: true tags: | ${{ env.IMAGE_NAME }}:${{ env.VERSION }} ${{ env.IMAGE_NAME }}:latest