Merge pull request #4 from knktc/feature-supports-filter-by-path #12
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release Binaries and Docker Image | |
| on: | |
| push: | |
| tags: | |
| - "v*" # 当推送以v开头的标签时触发,例如V20260612.0 | |
| permissions: | |
| contents: write # 需要这个权限来创建release和上传文件 | |
| jobs: | |
| build: | |
| name: Build and Release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.23' | |
| check-latest: true | |
| - name: Get tag name | |
| id: get_tag | |
| run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | |
| - name: Build macOS and Windows binaries | |
| run: | | |
| # 创建build目录存放二进制文件 | |
| mkdir -p builds | |
| # linux (amd64) | |
| CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-extldflags "-static"' -o builds/tiny-requestbin-${{ env.TAG }}-linux-amd64 . | |
| # Linux (arm64) | |
| CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -ldflags '-extldflags "-static"' -o builds/tiny-requestbin-${{ env.TAG }}-linux-arm64 . | |
| # macOS (Intel) | |
| GOOS=darwin GOARCH=amd64 go build -o builds/tiny-requestbin-${{ env.TAG }}-darwin-amd64 . | |
| # macOS (Apple Silicon) | |
| GOOS=darwin GOARCH=arm64 go build -o builds/tiny-requestbin-${{ env.TAG }}-darwin-arm64 . | |
| # Windows (x86_64) | |
| GOOS=windows GOARCH=amd64 go build -o builds/tiny-requestbin-${{ env.TAG }}-windows-amd64.exe . | |
| - name: Compress Binaries | |
| run: | | |
| # 创建压缩文件 | |
| cd builds | |
| # 压缩Linux二进制文件 | |
| tar -czf tiny-requestbin-${{ env.TAG }}-linux-amd64.tar.gz tiny-requestbin-${{ env.TAG }}-linux-amd64 | |
| tar -czf tiny-requestbin-${{ env.TAG }}-linux-arm64.tar.gz tiny-requestbin-${{ env.TAG }}-linux-arm64 | |
| # 压缩Mac二进制文件 | |
| tar -czf tiny-requestbin-${{ env.TAG }}-darwin-amd64.tar.gz tiny-requestbin-${{ env.TAG }}-darwin-amd64 | |
| tar -czf tiny-requestbin-${{ env.TAG }}-darwin-arm64.tar.gz tiny-requestbin-${{ env.TAG }}-darwin-arm64 | |
| # 压缩Windows二进制文件 | |
| zip tiny-requestbin-${{ env.TAG }}-windows-amd64.zip tiny-requestbin-${{ env.TAG }}-windows-amd64.exe | |
| - name: Create Release | |
| id: create_release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| name: Release ${{ env.TAG }} | |
| draft: false | |
| prerelease: false | |
| files: | | |
| builds/tiny-requestbin-${{ env.TAG }}-darwin-amd64.tar.gz | |
| builds/tiny-requestbin-${{ env.TAG }}-darwin-arm64.tar.gz | |
| builds/tiny-requestbin-${{ env.TAG }}-linux-amd64.tar.gz | |
| builds/tiny-requestbin-${{ env.TAG }}-linux-arm64.tar.gz | |
| builds/tiny-requestbin-${{ env.TAG }}-windows-amd64.zip | |
| docker: | |
| name: Build and Push Docker Image | |
| runs-on: ubuntu-latest | |
| needs: build # 等待 build job 完成 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: knktc | |
| password: ${{ secrets.DOCKERHUB_KEY }} | |
| - name: Get tag name | |
| id: get_tag | |
| run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: knktc/tiny-requestbin | |
| tags: | | |
| type=ref,event=tag | |
| type=raw,value=latest | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |