|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +name: Release |
| 16 | + |
| 17 | +on: |
| 18 | + release: |
| 19 | + types: [created] |
| 20 | + workflow_dispatch: |
| 21 | + inputs: |
| 22 | + tag_name: |
| 23 | + description: 'The tag of the release to upload assets to (e.g. v0.1.0)' |
| 24 | + required: true |
| 25 | + type: string |
| 26 | + |
| 27 | +permissions: |
| 28 | + contents: write |
| 29 | + |
| 30 | +jobs: |
| 31 | + prep-release: |
| 32 | + uses: ./.github/workflows/prep-release.yaml |
| 33 | + with: |
| 34 | + release: ${{ github.event.release.tag_name || inputs.tag_name }} |
| 35 | + |
| 36 | + build-release: |
| 37 | + needs: prep-release |
| 38 | + runs-on: ubuntu-latest |
| 39 | + defaults: |
| 40 | + run: |
| 41 | + working-directory: devops-mcp-server |
| 42 | + env: |
| 43 | + RELEASE_DIR: "${{ github.workspace }}/release" |
| 44 | + DIST_DIR: "${{ github.workspace }}/dist" |
| 45 | + strategy: |
| 46 | + matrix: |
| 47 | + platform: |
| 48 | + - { |
| 49 | + goos: "linux", |
| 50 | + goarch: "amd64", |
| 51 | + bin_file: "devops-mcp-server", |
| 52 | + archive: "linux.x64.devops.tar.gz", |
| 53 | + archive_cmd: 'tar -czvf "${ARCHIVE_PATH}" -C "${RELEASE_DIR}" .', |
| 54 | + } |
| 55 | + - { |
| 56 | + goos: "darwin", |
| 57 | + goarch: "arm64", |
| 58 | + bin_file: "devops-mcp-server", |
| 59 | + archive: "darwin.arm64.devops.tar.gz", |
| 60 | + archive_cmd: 'tar -czvf "${ARCHIVE_PATH}" -C "${RELEASE_DIR}" .', |
| 61 | + } |
| 62 | + |
| 63 | + - { |
| 64 | + goos: "windows", |
| 65 | + goarch: "amd64", |
| 66 | + bin_file: "devops-mcp-server.exe", |
| 67 | + archive: "win32.x64.devops.zip", |
| 68 | + archive_cmd: 'zip -j "${ARCHIVE_PATH}" "${RELEASE_DIR}"/*', |
| 69 | + } |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v4 |
| 72 | + with: |
| 73 | + # Do not checkout 'main'. Checkout the exact SHA prep-release used. |
| 74 | + ref: ${{ needs.prep-release.outputs.release_sha }} |
| 75 | + - name: prep-release |
| 76 | + env: |
| 77 | + BIN_FILE: "${{ matrix.platform.bin_file }}" |
| 78 | + TAG_NAME: ${{ github.event.release.tag_name || inputs.tag_name }} |
| 79 | + run: | |
| 80 | + mkdir -p "${RELEASE_DIR}" |
| 81 | +
|
| 82 | + # Extract version from tag (v1.2.3 -> 1.2.3) |
| 83 | + VERSION="${TAG_NAME#v}" |
| 84 | + |
| 85 | + command_exp='.mcpServers."devops-mcp".command = "${extensionPath}${/}' |
| 86 | + command_exp="${command_exp}${BIN_FILE}\"" |
| 87 | + command_exp="${command_exp} | .version = \"${VERSION}\"" |
| 88 | + |
| 89 | + jq "${command_exp}" < ../gemini-extension.json >"${RELEASE_DIR}/gemini-extension.json" |
| 90 | +
|
| 91 | + cp ../README.md "${RELEASE_DIR}/" |
| 92 | + cp -r ../commands "${RELEASE_DIR}/" |
| 93 | +
|
| 94 | + - name: Set up Go |
| 95 | + uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 |
| 96 | + with: |
| 97 | + go-version: "1.24.8" |
| 98 | + |
| 99 | + - name: Download Dependencies |
| 100 | + run: go mod tidy |
| 101 | + |
| 102 | + - name: Build |
| 103 | + run: | |
| 104 | + export GOOS=${{ matrix.platform.goos }} |
| 105 | + export GOARCH=${{ matrix.platform.goarch }} |
| 106 | +
|
| 107 | + output_path="${RELEASE_DIR}/${{ matrix.platform.bin_file }}" |
| 108 | + go build -o "${output_path}" |
| 109 | +
|
| 110 | + - name: Create release assets |
| 111 | + id: archive |
| 112 | + run: | |
| 113 | + mkdir -p "${DIST_DIR}" |
| 114 | + echo "Creating ${{ matrix.platform.archive }}" |
| 115 | + export ARCHIVE_PATH="${DIST_DIR}/${{ matrix.platform.archive }}" |
| 116 | + sh -c "${{ matrix.platform.archive_cmd }}" |
| 117 | + echo "Created ${ARCHIVE_PATH}" |
| 118 | + echo "ARCHIVE_NAME=${{ matrix.platform.archive }}" >> "$GITHUB_OUTPUT" |
| 119 | +
|
| 120 | + - name: Upload archive as artifact |
| 121 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 |
| 122 | + with: |
| 123 | + name: ${{ steps.archive.outputs.ARCHIVE_NAME }} |
| 124 | + path: ${{ github.workspace }}/dist/* |
| 125 | + |
| 126 | + upload-assets: |
| 127 | + needs: [build-release] |
| 128 | + runs-on: ubuntu-latest |
| 129 | + steps: |
| 130 | + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 |
| 131 | + |
| 132 | + - name: Download all archives from artifacts |
| 133 | + uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5 |
| 134 | + with: |
| 135 | + path: artifacts |
| 136 | + |
| 137 | + - name: List downloaded files |
| 138 | + run: | |
| 139 | + echo "--- Downloaded files ---" |
| 140 | + ls -Rlrt artifacts/* |
| 141 | + echo "------------------------" |
| 142 | + - name: Upload release assets |
| 143 | + id: upload-assets |
| 144 | + env: |
| 145 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 146 | + TAG_NAME: ${{ github.event.release.tag_name || inputs.tag_name }} |
| 147 | + run: | |
| 148 | + gh release upload --clobber \ |
| 149 | + ${TAG_NAME} \ |
| 150 | + artifacts/*/* |
0 commit comments