|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + # 第一步:跨平台集成测试 |
| 13 | + integration-test: |
| 14 | + name: Integration Test on ${{ matrix.os }} |
| 15 | + runs-on: ${{ matrix.os }} |
| 16 | + strategy: |
| 17 | + fail-fast: true |
| 18 | + matrix: |
| 19 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 20 | + go-version: ['1.25'] |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout code |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Set up Go |
| 27 | + uses: actions/setup-go@v5 |
| 28 | + with: |
| 29 | + go-version: ${{ matrix.go-version }} |
| 30 | + |
| 31 | + - name: Cache Go modules |
| 32 | + uses: actions/cache@v4 |
| 33 | + with: |
| 34 | + path: | |
| 35 | + ~/go/pkg/mod |
| 36 | + ~/.cache/go-build |
| 37 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 38 | + restore-keys: | |
| 39 | + ${{ runner.os }}-go- |
| 40 | +
|
| 41 | + - name: Download dependencies |
| 42 | + run: go mod download |
| 43 | + |
| 44 | + - name: Run unit tests |
| 45 | + run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... |
| 46 | + |
| 47 | + - name: Build binary |
| 48 | + run: make build |
| 49 | + |
| 50 | + - name: Integration Test - Version |
| 51 | + shell: bash |
| 52 | + run: | |
| 53 | + if [[ "${{ runner.os }}" == "Windows" ]]; then |
| 54 | + ./killport.exe --version |
| 55 | + else |
| 56 | + ./killport --version |
| 57 | + fi |
| 58 | +
|
| 59 | + - name: Integration Test - Help |
| 60 | + shell: bash |
| 61 | + run: | |
| 62 | + if [[ "${{ runner.os }}" == "Windows" ]]; then |
| 63 | + ./killport.exe --help |
| 64 | + else |
| 65 | + ./killport --help |
| 66 | + fi |
| 67 | +
|
| 68 | + - name: Integration Test - List (dry run) |
| 69 | + shell: bash |
| 70 | + run: | |
| 71 | + if [[ "${{ runner.os }}" == "Windows" ]]; then |
| 72 | + ./killport.exe list || echo "List command executed" |
| 73 | + else |
| 74 | + ./killport list || echo "List command executed" |
| 75 | + fi |
| 76 | +
|
| 77 | + - name: Integration Test - Init config |
| 78 | + shell: bash |
| 79 | + run: | |
| 80 | + if [[ "${{ runner.os }}" == "Windows" ]]; then |
| 81 | + ./killport.exe init --yes |
| 82 | + else |
| 83 | + ./killport init --yes |
| 84 | + fi |
| 85 | +
|
| 86 | + - name: Integration Test - Verify config created |
| 87 | + shell: bash |
| 88 | + run: | |
| 89 | + if [[ "${{ runner.os }}" == "Windows" ]]; then |
| 90 | + test -f "$HOME/.killport.yaml" && echo "✅ Config file created" || echo "❌ Config file not found" |
| 91 | + else |
| 92 | + test -f "$HOME/.killport.yaml" && echo "✅ Config file created" || echo "❌ Config file not found" |
| 93 | + fi |
| 94 | +
|
| 95 | + - name: Upload coverage to Codecov (Ubuntu only) |
| 96 | + if: matrix.os == 'ubuntu-latest' |
| 97 | + uses: codecov/codecov-action@v4 |
| 98 | + with: |
| 99 | + file: ./coverage.txt |
| 100 | + flags: unittests |
| 101 | + name: codecov-umbrella |
| 102 | + |
| 103 | + # 第二步:构建和发布(依赖测试通过) |
| 104 | + release: |
| 105 | + name: Build and Release |
| 106 | + needs: integration-test |
| 107 | + runs-on: ubuntu-latest |
| 108 | + outputs: |
| 109 | + version: ${{ steps.get_version.outputs.version }} |
| 110 | + |
| 111 | + steps: |
| 112 | + - name: Checkout code |
| 113 | + uses: actions/checkout@v4 |
| 114 | + with: |
| 115 | + fetch-depth: 0 |
| 116 | + |
| 117 | + - name: Set up Go |
| 118 | + uses: actions/setup-go@v5 |
| 119 | + with: |
| 120 | + go-version: '1.25' |
| 121 | + |
| 122 | + - name: Get version |
| 123 | + id: get_version |
| 124 | + run: echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 125 | + |
| 126 | + - name: Run GoReleaser |
| 127 | + uses: goreleaser/goreleaser-action@v5 |
| 128 | + with: |
| 129 | + distribution: goreleaser |
| 130 | + version: latest |
| 131 | + args: release --clean |
| 132 | + env: |
| 133 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 134 | + |
| 135 | + # 第三步:发布到包管理器(暂时禁用) |
| 136 | + # publish-homebrew: |
| 137 | + # name: Publish to Homebrew |
| 138 | + # needs: release |
| 139 | + # runs-on: ubuntu-latest |
| 140 | + # if: github.repository == 'TNT-Likely/killport' |
| 141 | + # |
| 142 | + # steps: |
| 143 | + # - name: Checkout code |
| 144 | + # uses: actions/checkout@v4 |
| 145 | + # |
| 146 | + # - name: Update Homebrew tap |
| 147 | + # env: |
| 148 | + # HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }} |
| 149 | + # run: | |
| 150 | + # if [[ -z "$HOMEBREW_TAP_TOKEN" ]]; then |
| 151 | + # echo "⚠️ HOMEBREW_TAP_GITHUB_TOKEN not set, skipping Homebrew publish" |
| 152 | + # exit 0 |
| 153 | + # fi |
| 154 | + # |
| 155 | + # echo "✅ Homebrew Formula will be updated by GoReleaser" |
| 156 | + # echo "📦 Version: ${{ needs.release.outputs.version }}" |
| 157 | + |
| 158 | + # publish-scoop: |
| 159 | + # name: Publish to Scoop |
| 160 | + # needs: release |
| 161 | + # runs-on: ubuntu-latest |
| 162 | + # if: github.repository == 'TNT-Likely/killport' |
| 163 | + # |
| 164 | + # steps: |
| 165 | + # - name: Checkout code |
| 166 | + # uses: actions/checkout@v4 |
| 167 | + # |
| 168 | + # - name: Update Scoop bucket |
| 169 | + # env: |
| 170 | + # SCOOP_BUCKET_TOKEN: ${{ secrets.SCOOP_BUCKET_GITHUB_TOKEN }} |
| 171 | + # run: | |
| 172 | + # if [[ -z "$SCOOP_BUCKET_TOKEN" ]]; then |
| 173 | + # echo "⚠️ SCOOP_BUCKET_GITHUB_TOKEN not set, skipping Scoop publish" |
| 174 | + # exit 0 |
| 175 | + # fi |
| 176 | + # |
| 177 | + # VERSION="${{ needs.release.outputs.version }}" |
| 178 | + # echo "📦 Preparing Scoop manifest for $VERSION" |
| 179 | + # echo "ℹ️ Manual step: Update scoop-bucket repository with new manifest" |
| 180 | + |
| 181 | + # 第三步:发布通知 |
| 182 | + notify: |
| 183 | + name: Notify Release |
| 184 | + needs: [release] |
| 185 | + runs-on: ubuntu-latest |
| 186 | + if: always() |
| 187 | + |
| 188 | + steps: |
| 189 | + - name: Release Summary |
| 190 | + run: | |
| 191 | + echo "🎉 Release ${{ needs.release.outputs.version }} completed!" |
| 192 | + echo "" |
| 193 | + echo "✅ Integration tests: Passed" |
| 194 | + echo "✅ Build and release: Completed" |
| 195 | + echo "📦 Artifacts published to GitHub Releases" |
| 196 | + echo "" |
| 197 | + echo "📍 Download: https://github.com/${{ github.repository }}/releases/tag/${{ needs.release.outputs.version }}" |
0 commit comments