|
| 1 | +# 参考 https://github.com/soulteary/stargate |
| 2 | +# 推送 tag v*.*.* 时自动构建多架构 Docker 镜像并发布到 GHCR,同时创建 GitHub Release |
| 3 | +name: Release |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + tags: |
| 8 | + - 'v*.*.*' |
| 9 | + |
| 10 | +env: |
| 11 | + GO_VERSION: "1.26.0" |
| 12 | + REGISTRY: ghcr.io |
| 13 | + IMAGE_NAME: ${{ github.repository }} |
| 14 | + |
| 15 | +jobs: |
| 16 | + release: |
| 17 | + name: Release |
| 18 | + runs-on: ubuntu-latest |
| 19 | + permissions: |
| 20 | + contents: write |
| 21 | + packages: write |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout code |
| 25 | + uses: actions/checkout@v6 |
| 26 | + with: |
| 27 | + fetch-depth: 0 |
| 28 | + |
| 29 | + - name: Set up Go |
| 30 | + uses: actions/setup-go@v6 |
| 31 | + with: |
| 32 | + go-version: ${{ env.GO_VERSION }} |
| 33 | + cache-dependency-path: go.sum |
| 34 | + |
| 35 | + - name: Run tests |
| 36 | + run: go test -v ./... |
| 37 | + |
| 38 | + - name: Extract version from tag |
| 39 | + id: version |
| 40 | + run: | |
| 41 | + VERSION=${GITHUB_REF#refs/tags/} |
| 42 | + VERSION=${VERSION#v} |
| 43 | + COMMIT=$(git rev-parse --short HEAD) |
| 44 | + BUILD_DATE=$(date -u +%FT%T%z) |
| 45 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 46 | + echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 47 | + echo "commit=$COMMIT" >> $GITHUB_OUTPUT |
| 48 | + echo "build_date=$BUILD_DATE" >> $GITHUB_OUTPUT |
| 49 | +
|
| 50 | + - name: Build binaries |
| 51 | + run: | |
| 52 | + mkdir -p dist |
| 53 | + VERSION=${{ steps.version.outputs.version }} |
| 54 | + COMMIT=${{ github.sha }} |
| 55 | + LDFLAGS="-s -w -X main.Version=v${VERSION}" |
| 56 | + GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "${LDFLAGS}" -o dist/runner-manager-linux-amd64 . |
| 57 | + GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "${LDFLAGS}" -o dist/runner-manager-linux-arm64 . |
| 58 | + GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "${LDFLAGS}" -o dist/runner-manager-darwin-amd64 . |
| 59 | + GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -ldflags "${LDFLAGS}" -o dist/runner-manager-darwin-arm64 . |
| 60 | +
|
| 61 | + - name: Generate checksums |
| 62 | + run: | |
| 63 | + cd dist |
| 64 | + sha256sum * > checksums.txt |
| 65 | +
|
| 66 | + - name: Prepare config for image |
| 67 | + run: cp config.yaml.example config.yaml |
| 68 | + |
| 69 | + - name: Set up Docker Buildx |
| 70 | + uses: docker/setup-buildx-action@v3 |
| 71 | + |
| 72 | + - name: Log in to Container Registry |
| 73 | + uses: docker/login-action@v3 |
| 74 | + with: |
| 75 | + registry: ${{ env.REGISTRY }} |
| 76 | + username: ${{ github.actor }} |
| 77 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 78 | + |
| 79 | + - name: Extract metadata |
| 80 | + id: meta |
| 81 | + uses: docker/metadata-action@v5 |
| 82 | + with: |
| 83 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 84 | + tags: | |
| 85 | + type=ref,event=tag |
| 86 | + type=semver,pattern={{version}} |
| 87 | + type=semver,pattern={{major}}.{{minor}} |
| 88 | + type=semver,pattern={{major}} |
| 89 | + type=raw,value=latest,enable=true |
| 90 | +
|
| 91 | + - name: Build and push Docker image |
| 92 | + uses: docker/build-push-action@v6 |
| 93 | + with: |
| 94 | + context: . |
| 95 | + file: ./Dockerfile |
| 96 | + push: true |
| 97 | + tags: ${{ steps.meta.outputs.tags }} |
| 98 | + labels: ${{ steps.meta.outputs.labels }} |
| 99 | + build-args: | |
| 100 | + VERSION=${{ steps.version.outputs.tag }} |
| 101 | + cache-from: type=gha |
| 102 | + cache-to: type=gha,mode=max |
| 103 | + platforms: linux/amd64,linux/arm64 |
| 104 | + |
| 105 | + - name: Create Release |
| 106 | + uses: softprops/action-gh-release@v2 |
| 107 | + with: |
| 108 | + files: dist/* |
| 109 | + name: Release ${{ steps.version.outputs.tag }} |
| 110 | + body: | |
| 111 | + ## Changes |
| 112 | +
|
| 113 | + 详见提交历史与变更说明。 |
| 114 | +
|
| 115 | + ## 使用方式 |
| 116 | +
|
| 117 | + ### Docker 镜像 (GHCR) |
| 118 | +
|
| 119 | + ```bash |
| 120 | + docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.tag }} |
| 121 | + ``` |
| 122 | +
|
| 123 | + ### 二进制 |
| 124 | +
|
| 125 | + - Linux AMD64: `runner-manager-linux-amd64` |
| 126 | + - Linux ARM64: `runner-manager-linux-arm64` |
| 127 | + - macOS AMD64: `runner-manager-darwin-amd64` |
| 128 | + - macOS ARM64: `runner-manager-darwin-arm64` |
| 129 | +
|
| 130 | + ### 校验和 |
| 131 | +
|
| 132 | + 见 `checksums.txt` 中的 SHA256。 |
| 133 | + draft: false |
| 134 | + prerelease: false |
0 commit comments