|
| 1 | +name: Build and Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + tags: [ 'v*' ] |
| 7 | + paths: |
| 8 | + - 'cmd/**' |
| 9 | + - 'internal/**' |
| 10 | + - 'pkg/**' |
| 11 | + - 'go.mod' |
| 12 | + - 'go.sum' |
| 13 | + pull_request: |
| 14 | + branches: [ main ] |
| 15 | + paths: |
| 16 | + - 'cmd/**' |
| 17 | + - 'internal/**' |
| 18 | + - 'pkg/**' |
| 19 | + - 'go.mod' |
| 20 | + - 'go.sum' |
| 21 | + |
| 22 | +env: |
| 23 | + BINARY_NAME: gitlab-cli |
| 24 | + |
| 25 | +jobs: |
| 26 | + build: |
| 27 | + name: Build Binary |
| 28 | + runs-on: ${{ matrix.os }} |
| 29 | + strategy: |
| 30 | + matrix: |
| 31 | + include: |
| 32 | + # Linux |
| 33 | + - os: ubuntu-latest |
| 34 | + goos: linux |
| 35 | + goarch: amd64 |
| 36 | + artifact_name: gitlab-cli-linux-amd64 |
| 37 | + - os: ubuntu-latest |
| 38 | + goos: linux |
| 39 | + goarch: arm64 |
| 40 | + artifact_name: gitlab-cli-linux-arm64 |
| 41 | + # macOS |
| 42 | + - os: macos-latest |
| 43 | + goos: darwin |
| 44 | + goarch: amd64 |
| 45 | + artifact_name: gitlab-cli-darwin-amd64 |
| 46 | + - os: macos-latest |
| 47 | + goos: darwin |
| 48 | + goarch: arm64 |
| 49 | + artifact_name: gitlab-cli-darwin-arm64 |
| 50 | + # Windows |
| 51 | + - os: ubuntu-latest |
| 52 | + goos: windows |
| 53 | + goarch: amd64 |
| 54 | + artifact_name: gitlab-cli-windows-amd64.exe |
| 55 | + |
| 56 | + permissions: |
| 57 | + contents: read |
| 58 | + |
| 59 | + steps: |
| 60 | + - name: Checkout code |
| 61 | + uses: actions/checkout@v4 |
| 62 | + |
| 63 | + - name: Set up Go |
| 64 | + uses: actions/setup-go@v5 |
| 65 | + with: |
| 66 | + go-version: '1.23' |
| 67 | + cache: true |
| 68 | + |
| 69 | + - name: Get version info |
| 70 | + id: version |
| 71 | + run: | |
| 72 | + if [[ "${{ github.ref }}" == refs/tags/* ]]; then |
| 73 | + echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 74 | + else |
| 75 | + echo "version=dev-${GITHUB_SHA::8}" >> $GITHUB_OUTPUT |
| 76 | + fi |
| 77 | + echo "commit=${GITHUB_SHA::8}" >> $GITHUB_OUTPUT |
| 78 | + echo "date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT |
| 79 | +
|
| 80 | + - name: Build binary |
| 81 | + env: |
| 82 | + GOOS: ${{ matrix.goos }} |
| 83 | + GOARCH: ${{ matrix.goarch }} |
| 84 | + CGO_ENABLED: 0 |
| 85 | + run: | |
| 86 | + go build \ |
| 87 | + -ldflags="-s -w -X main.Version=${{ steps.version.outputs.version }}" \ |
| 88 | + -o "${{ matrix.artifact_name }}" \ |
| 89 | + ./cmd/gitlab-cli |
| 90 | +
|
| 91 | + - name: Generate checksum |
| 92 | + run: | |
| 93 | + if [[ "${{ matrix.os }}" == "macos-latest" ]]; then |
| 94 | + shasum -a 256 "${{ matrix.artifact_name }}" > "${{ matrix.artifact_name }}.sha256" |
| 95 | + else |
| 96 | + sha256sum "${{ matrix.artifact_name }}" > "${{ matrix.artifact_name }}.sha256" |
| 97 | + fi |
| 98 | +
|
| 99 | + - name: Upload artifact |
| 100 | + uses: actions/upload-artifact@v4 |
| 101 | + with: |
| 102 | + name: ${{ matrix.artifact_name }} |
| 103 | + path: | |
| 104 | + ${{ matrix.artifact_name }} |
| 105 | + ${{ matrix.artifact_name }}.sha256 |
| 106 | + retention-days: 30 |
| 107 | + |
| 108 | + release: |
| 109 | + name: Create Release |
| 110 | + runs-on: ubuntu-latest |
| 111 | + needs: build |
| 112 | + if: startsWith(github.ref, 'refs/tags/') |
| 113 | + |
| 114 | + permissions: |
| 115 | + contents: write |
| 116 | + |
| 117 | + steps: |
| 118 | + - name: Checkout code |
| 119 | + uses: actions/checkout@v4 |
| 120 | + |
| 121 | + - name: Download all artifacts |
| 122 | + uses: actions/download-artifact@v4 |
| 123 | + with: |
| 124 | + path: dist/ |
| 125 | + |
| 126 | + - name: Prepare release assets |
| 127 | + run: | |
| 128 | + mkdir -p release |
| 129 | + find dist/ -type f -exec cp {} release/ \; |
| 130 | + ls -lah release/ |
| 131 | +
|
| 132 | + - name: Create Release |
| 133 | + uses: softprops/action-gh-release@v2 |
| 134 | + with: |
| 135 | + files: release/* |
| 136 | + draft: false |
| 137 | + prerelease: false |
| 138 | + generate_release_notes: true |
| 139 | + body: | |
| 140 | + ## GitLab CLI ${{ github.ref_name }} |
| 141 | +
|
| 142 | + GitLab 用户和项目自动化管理工具 |
| 143 | +
|
| 144 | + ### 安装 |
| 145 | +
|
| 146 | + 下载对应平台的二进制文件,解压后即可使用: |
| 147 | +
|
| 148 | + ```bash |
| 149 | + # Linux (amd64) |
| 150 | + wget https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/gitlab-cli-linux-amd64 |
| 151 | + chmod +x gitlab-cli-linux-amd64 |
| 152 | + sudo mv gitlab-cli-linux-amd64 /usr/local/bin/gitlab-cli |
| 153 | +
|
| 154 | + # macOS (arm64, Apple Silicon) |
| 155 | + wget https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/gitlab-cli-darwin-arm64 |
| 156 | + chmod +x gitlab-cli-darwin-arm64 |
| 157 | + sudo mv gitlab-cli-darwin-arm64 /usr/local/bin/gitlab-cli |
| 158 | + ``` |
| 159 | +
|
| 160 | + ### 验证安装 |
| 161 | +
|
| 162 | + ```bash |
| 163 | + gitlab-cli --version |
| 164 | + ``` |
| 165 | +
|
| 166 | + ### 文档 |
| 167 | +
|
| 168 | + - [快速开始](https://github.com/${{ github.repository }}/blob/main/docs/QUICKSTART.md) |
| 169 | + - [完整文档](https://github.com/${{ github.repository }}/blob/main/docs/README.md) |
| 170 | + - [架构设计](https://github.com/${{ github.repository }}/blob/main/docs/ARCHITECTURE.md) |
0 commit comments