|
| 1 | +# Copyright 2026 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: NPM Publish Nightly |
| 16 | + |
| 17 | +on: |
| 18 | + workflow_dispatch: # Manual trigger |
| 19 | + inputs: |
| 20 | + npm_token: |
| 21 | + description: 'NPM Token for publishing (optional, falls back to secret)' |
| 22 | + required: false |
| 23 | + type: string |
| 24 | + workflow_run: |
| 25 | + workflows: ["Nightly Release"] |
| 26 | + types: [completed] |
| 27 | + |
| 28 | +permissions: |
| 29 | + contents: read |
| 30 | + |
| 31 | +jobs: |
| 32 | + publish-npm: |
| 33 | + if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} |
| 34 | + runs-on: ubuntu-latest |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6 |
| 37 | + |
| 38 | + - name: Setup Node.js |
| 39 | + uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f |
| 40 | + with: |
| 41 | + node-version: '24' |
| 42 | + registry-url: 'https://registry.npmjs.org' |
| 43 | + |
| 44 | + - name: Check NPM Token |
| 45 | + env: |
| 46 | + TOKEN: ${{ inputs.npm_token || secrets.NPM_TOKEN }} |
| 47 | + run: | |
| 48 | + if [ -z "$TOKEN" ]; then |
| 49 | + echo "Error: NPM_TOKEN is not set in inputs or secrets. Exiting." |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: Download Nightly Release Assets |
| 54 | + env: |
| 55 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 56 | + run: | |
| 57 | + mkdir -p artifacts |
| 58 | + gh release download nightly --pattern '*' --dir artifacts --repo ${{ github.repository }} |
| 59 | +
|
| 60 | + - name: List downloaded files |
| 61 | + run: ls -R artifacts |
| 62 | + |
| 63 | + - name: Extract Binaries |
| 64 | + run: | |
| 65 | + mkdir -p cicd-mcp-server/npm/cicd-mcp-linux-amd64/bin |
| 66 | + mkdir -p cicd-mcp-server/npm/cicd-mcp-darwin-arm64/bin |
| 67 | + mkdir -p cicd-mcp-server/npm/cicd-mcp-windows-amd64/bin |
| 68 | +
|
| 69 | + # Extract Linux |
| 70 | + tar -xzvf artifacts/linux.x64.cicd.tar.gz -C cicd-mcp-server/npm/cicd-mcp-linux-amd64/bin cicd-mcp-server |
| 71 | +
|
| 72 | + # Extract Darwin |
| 73 | + tar -xzvf artifacts/darwin.arm64.cicd.tar.gz -C cicd-mcp-server/npm/cicd-mcp-darwin-arm64/bin cicd-mcp-server |
| 74 | +
|
| 75 | + # Extract Windows |
| 76 | + unzip artifacts/win32.x64.cicd.zip -d cicd-mcp-server/npm/cicd-mcp-windows-amd64/bin cicd-mcp-server.exe |
| 77 | +
|
| 78 | + - name: Set Nightly Version |
| 79 | + id: version |
| 80 | + run: | |
| 81 | + # Get current version from meta package |
| 82 | + cd cicd-mcp-server/npm/cicd-mcp |
| 83 | + PACKAGE_VERSION=$(node -p "require('./package.json').version") |
| 84 | + |
| 85 | + # Create nightly version |
| 86 | + NIGHTLY_VERSION="${PACKAGE_VERSION}-nightly.$(date +%Y%m%d%H%M)" |
| 87 | + echo "NIGHTLY_VERSION=$NIGHTLY_VERSION" >> $GITHUB_OUTPUT |
| 88 | + |
| 89 | + cd ../../.. |
| 90 | +
|
| 91 | + # Update sub-packages |
| 92 | + for dir in cicd-mcp-linux-amd64 cicd-mcp-darwin-arm64 cicd-mcp-windows-amd64; do |
| 93 | + cd cicd-mcp-server/npm/$dir |
| 94 | + npm version $NIGHTLY_VERSION --no-git-tag-version |
| 95 | + cd ../../.. |
| 96 | + done |
| 97 | +
|
| 98 | + # Update meta package |
| 99 | + cd cicd-mcp-server/npm/cicd-mcp |
| 100 | + npm version $NIGHTLY_VERSION --no-git-tag-version |
| 101 | + |
| 102 | + # Update optionalDependencies in meta package |
| 103 | + jq ".optionalDependencies[\"@google-cloud/cicd-mcp-linux-amd64\"] = \"$NIGHTLY_VERSION\" | .optionalDependencies[\"@google-cloud/cicd-mcp-darwin-arm64\"] = \"$NIGHTLY_VERSION\" | .optionalDependencies[\"@google-cloud/cicd-mcp-windows-amd64\"] = \"$NIGHTLY_VERSION\"" package.json > package.json.tmp && mv package.json.tmp package.json |
| 104 | + |
| 105 | + cd ../../.. |
| 106 | +
|
| 107 | + - name: Publish Sub-packages |
| 108 | + env: |
| 109 | + NODE_AUTH_TOKEN: ${{ inputs.npm_token || secrets.NPM_TOKEN }} |
| 110 | + run: | |
| 111 | + for dir in cicd-mcp-linux-amd64 cicd-mcp-darwin-arm64 cicd-mcp-windows-amd64; do |
| 112 | + cd cicd-mcp-server/npm/$dir |
| 113 | + npm publish --tag nightly --access public |
| 114 | + cd ../../.. |
| 115 | + done |
| 116 | +
|
| 117 | + - name: Publish Meta Package |
| 118 | + env: |
| 119 | + NODE_AUTH_TOKEN: ${{ inputs.npm_token || secrets.NPM_TOKEN }} |
| 120 | + run: | |
| 121 | + cd cicd-mcp-server/npm/cicd-mcp |
| 122 | + npm publish --tag nightly --access public |
0 commit comments