|
| 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: Package and Upload Release Assets |
| 16 | + |
| 17 | +# Global variables |
| 18 | +env: |
| 19 | + PACKAGE_NAME: "postgres" |
| 20 | + FILES_TO_PACKAGE: "gemini-extension.json POSTGRESQL.md LICENSE" |
| 21 | + GCS_BUCKET_URL: "https://storage.googleapis.com/genai-toolbox/geminicli" |
| 22 | + |
| 23 | +on: |
| 24 | + release: |
| 25 | + types: [created] |
| 26 | + |
| 27 | +jobs: |
| 28 | + package: |
| 29 | + name: Package for ${{ matrix.platform.os }}-${{ matrix.platform.arch }} |
| 30 | + runs-on: ubuntu-latest |
| 31 | + |
| 32 | + strategy: |
| 33 | + matrix: |
| 34 | + platform: |
| 35 | + - { os: "linux", arch: "x64", download_path_segment: "linux/amd64", binary_suffix: "", archive_extension: "tar.gz", archive_command: 'tar -czvf "${ARCHIVE_NAME}" -C staging .' } |
| 36 | + - { os: "darwin", arch: "arm64", download_path_segment: "darwin/arm64", binary_suffix: "", archive_extension: "tar.gz", archive_command: 'tar -czvf "${ARCHIVE_NAME}" -C staging .' } |
| 37 | + - { os: "darwin", arch: "x64", download_path_segment: "darwin/amd64", binary_suffix: "", archive_extension: "tar.gz", archive_command: 'tar -czvf "${ARCHIVE_NAME}" -C staging .' } |
| 38 | + - { os: "win32", arch: "x64", download_path_segment: "windows/amd64", binary_suffix: ".exe", archive_extension: "zip", archive_command: '(cd staging && zip ../"${ARCHIVE_NAME}" *)' } |
| 39 | + |
| 40 | + steps: |
| 41 | + - name: Checkout code at the new tag |
| 42 | + uses: actions/checkout@v4 |
| 43 | + with: |
| 44 | + ref: ${{ github.event.release.tag_name }} |
| 45 | + |
| 46 | + - name: Set Dynamic Environment Variables |
| 47 | + id: vars |
| 48 | + run: | |
| 49 | + echo "archive_name=${{ matrix.platform.os }}.${{ matrix.platform.arch }}.${{ env.PACKAGE_NAME }}.${{ matrix.platform.archive_extension }}" >> $GITHUB_OUTPUT |
| 50 | + echo "source_binary=toolbox${{ matrix.platform.binary_suffix }}" >> $GITHUB_OUTPUT |
| 51 | +
|
| 52 | + - name: Get Toolbox Version |
| 53 | + id: get_toolbox_version |
| 54 | + run: | |
| 55 | + TOOLBOX_VERSION=$(cat toolbox_version.txt) |
| 56 | + echo "Found toolbox version: ${TOOLBOX_VERSION}" |
| 57 | + echo "TOOLBOX_VERSION=${TOOLBOX_VERSION}" >> $GITHUB_OUTPUT |
| 58 | +
|
| 59 | + - name: Download Source Binary |
| 60 | + env: |
| 61 | + TOOLBOX_VERSION: ${{ steps.get_toolbox_version.outputs.TOOLBOX_VERSION }} |
| 62 | + DOWNLOAD_PATH_SEGMENT: ${{ matrix.platform.download_path_segment }} |
| 63 | + SOURCE_BINARY: ${{ steps.vars.outputs.source_binary }} |
| 64 | + run: | |
| 65 | + DOWNLOAD_URL="${GCS_BUCKET_URL}/v${TOOLBOX_VERSION}/${DOWNLOAD_PATH_SEGMENT}/${SOURCE_BINARY}" |
| 66 | + |
| 67 | + echo "Downloading binary from: ${DOWNLOAD_URL}" |
| 68 | + curl -L --fail -o "${SOURCE_BINARY}" "${DOWNLOAD_URL}" |
| 69 | + |
| 70 | + echo "Binary downloaded and prepared." |
| 71 | + ls -l |
| 72 | +
|
| 73 | + - name: Create release archive |
| 74 | + id: create_archive |
| 75 | + env: |
| 76 | + ARCHIVE_COMMAND: ${{ matrix.platform.archive_command }} |
| 77 | + ARCHIVE_NAME: ${{ steps.vars.outputs.archive_name }} |
| 78 | + SOURCE_BINARY: ${{ steps.vars.outputs.source_binary }} |
| 79 | + run: | |
| 80 | + ARCHIVE_NAME="${{ matrix.platform.os }}.${{ matrix.platform.arch }}.${PACKAGE_NAME}.${{ matrix.platform.archive_extension }}" |
| 81 | + SOURCE_BINARY="toolbox${{ matrix.platform.binary_suffix }}" |
| 82 | +
|
| 83 | + echo "Packaging ${SOURCE_BINARY} into ${ARCHIVE_NAME}" |
| 84 | +
|
| 85 | + mkdir staging |
| 86 | + cp "${SOURCE_BINARY}" "staging/${SOURCE_BINARY}" |
| 87 | + cp ${FILES_TO_PACKAGE} staging/ |
| 88 | +
|
| 89 | + if [[ "${{ matrix.platform.os }}" == "win32" ]]; then |
| 90 | + echo "Modifying gemini-extension.json for Windows..." |
| 91 | + jq '(.mcpServers[].command) |= sub("toolbox$"; "toolbox.exe")' gemini-extension.json > staging/gemini-extension.json |
| 92 | + echo "Modification complete." |
| 93 | + fi |
| 94 | +
|
| 95 | + echo "All assets staged." |
| 96 | + ls -l staging |
| 97 | +
|
| 98 | + # Create archive |
| 99 | + eval "${ARCHIVE_COMMAND}" |
| 100 | + echo "Created archive: ${ARCHIVE_NAME}" |
| 101 | + echo "ARCHIVE_PATH=${ARCHIVE_NAME}" >> $GITHUB_OUTPUT |
| 102 | +
|
| 103 | + - name: Upload archive as workflow artifact |
| 104 | + uses: actions/upload-artifact@v4 |
| 105 | + with: |
| 106 | + name: ${{ steps.vars.outputs.archive_name }} |
| 107 | + path: ${{ steps.create_archive.outputs.ARCHIVE_PATH }} |
| 108 | + |
| 109 | + # This job gathers all archives and uploads them to the GitHub Release. |
| 110 | + upload: |
| 111 | + name: Upload all assets to release |
| 112 | + runs-on: ubuntu-latest |
| 113 | + needs: package |
| 114 | + permissions: |
| 115 | + contents: write |
| 116 | + steps: |
| 117 | + - name: Checkout code |
| 118 | + uses: actions/checkout@v4 |
| 119 | + |
| 120 | + - name: Download all archives from workflow artifacts |
| 121 | + uses: actions/download-artifact@v4 |
| 122 | + with: |
| 123 | + path: release-archives |
| 124 | + |
| 125 | + - name: List downloaded files |
| 126 | + run: | |
| 127 | + echo "--- Downloaded files ---" |
| 128 | + ls -R release-archives |
| 129 | + echo "------------------------" |
| 130 | +
|
| 131 | + - name: Upload all assets to GitHub Release |
| 132 | + env: |
| 133 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 134 | + run: | |
| 135 | + gh release upload \ |
| 136 | + ${{ github.event.release.tag_name }} \ |
| 137 | + release-archives/*/* |
0 commit comments