|
| 1 | +name: Publish Package |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + package: |
| 7 | + description: 'Package to publish' |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - all |
| 12 | + - events |
| 13 | + - agent |
| 14 | + - memory |
| 15 | + default: 'all' |
| 16 | + version: |
| 17 | + description: 'Version bump type' |
| 18 | + required: true |
| 19 | + type: choice |
| 20 | + options: [patch, minor, major, prepatch, preminor, premajor, prerelease] |
| 21 | + custom_version: |
| 22 | + description: 'Custom version (optional, overrides version type)' |
| 23 | + required: false |
| 24 | + type: string |
| 25 | + preid: |
| 26 | + description: 'Prerelease identifier' |
| 27 | + required: false |
| 28 | + type: choice |
| 29 | + options: [beta, alpha, rc, next] |
| 30 | + default: 'beta' |
| 31 | + dry_run: |
| 32 | + description: 'Dry run (do not actually publish)' |
| 33 | + required: false |
| 34 | + type: boolean |
| 35 | + default: false |
| 36 | + tag: |
| 37 | + description: 'NPM dist-tag' |
| 38 | + required: false |
| 39 | + type: choice |
| 40 | + options: [latest, next, beta, alpha] |
| 41 | + default: 'latest' |
| 42 | + |
| 43 | +concurrency: |
| 44 | + group: publish-package |
| 45 | + cancel-in-progress: false |
| 46 | + |
| 47 | +permissions: |
| 48 | + contents: write |
| 49 | + id-token: write |
| 50 | + |
| 51 | +env: |
| 52 | + NPM_CONFIG_FUND: false |
| 53 | + |
| 54 | +jobs: |
| 55 | + build: |
| 56 | + name: Build & Version |
| 57 | + runs-on: ubuntu-latest |
| 58 | + outputs: |
| 59 | + new_version: ${{ steps.bump.outputs.new_version }} |
| 60 | + is_prerelease: ${{ steps.bump.outputs.is_prerelease }} |
| 61 | + |
| 62 | + steps: |
| 63 | + - name: Checkout code |
| 64 | + uses: actions/checkout@v4 |
| 65 | + with: |
| 66 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + |
| 68 | + - name: Setup Node.js |
| 69 | + uses: actions/setup-node@v4 |
| 70 | + with: |
| 71 | + node-version: '22.14.0' |
| 72 | + cache: 'npm' |
| 73 | + registry-url: 'https://registry.npmjs.org' |
| 74 | + |
| 75 | + - name: Install dependencies |
| 76 | + run: npm ci |
| 77 | + |
| 78 | + - name: Version all packages |
| 79 | + id: bump |
| 80 | + run: | |
| 81 | + CUSTOM_VERSION="${{ github.event.inputs.custom_version }}" |
| 82 | + VERSION_TYPE="${{ github.event.inputs.version }}" |
| 83 | + PREID="${{ github.event.inputs.preid }}" |
| 84 | + CURRENT_VERSION=$(node -p "require('./package.json').version") |
| 85 | + echo "Current version: $CURRENT_VERSION" |
| 86 | +
|
| 87 | + if [ -n "$CUSTOM_VERSION" ]; then |
| 88 | + echo "Setting version to custom value: $CUSTOM_VERSION" |
| 89 | + npm version "$CUSTOM_VERSION" --no-git-tag-version --allow-same-version |
| 90 | + else |
| 91 | + echo "Bumping version: $VERSION_TYPE (preid=$PREID)" |
| 92 | + npm version "$VERSION_TYPE" --no-git-tag-version --preid="$PREID" |
| 93 | + fi |
| 94 | +
|
| 95 | + NEW_VERSION=$(node -p "require('./package.json').version") |
| 96 | + echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" |
| 97 | + echo "New version: $NEW_VERSION" |
| 98 | +
|
| 99 | + if [[ "$NEW_VERSION" == *"-"* ]]; then |
| 100 | + echo "is_prerelease=true" >> "$GITHUB_OUTPUT" |
| 101 | + else |
| 102 | + echo "is_prerelease=false" >> "$GITHUB_OUTPUT" |
| 103 | + fi |
| 104 | +
|
| 105 | + # Sync all package versions and @agent-relay/* internal deps to the new version. |
| 106 | + node -e " |
| 107 | + const fs = require('fs'); |
| 108 | + const version = '$NEW_VERSION'; |
| 109 | +
|
| 110 | + const packagePaths = [ |
| 111 | + 'packages/events/package.json', |
| 112 | + 'packages/agent/package.json', |
| 113 | + 'packages/memory/package.json', |
| 114 | + ]; |
| 115 | +
|
| 116 | + for (const pkgPath of packagePaths) { |
| 117 | + if (fs.existsSync(pkgPath)) { |
| 118 | + const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')); |
| 119 | + pkg.version = version; |
| 120 | + console.log(pkg.name + ' -> v' + version); |
| 121 | + for (const depType of ['dependencies', 'devDependencies']) { |
| 122 | + for (const dep of Object.keys(pkg[depType] || {})) { |
| 123 | + if (dep.startsWith('@agent-relay/events') || dep.startsWith('@agent-relay/agent') || dep.startsWith('@agent-relay/memory')) { |
| 124 | + pkg[depType][dep] = version; |
| 125 | + } |
| 126 | + } |
| 127 | + } |
| 128 | + fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n'); |
| 129 | + } |
| 130 | + } |
| 131 | + " |
| 132 | +
|
| 133 | + - name: Build packages |
| 134 | + run: | |
| 135 | + npm run build --workspace=packages/events |
| 136 | + npm run build --workspace=packages/agent |
| 137 | + npm run build --workspace=packages/memory |
| 138 | +
|
| 139 | + - name: Upload build artifacts |
| 140 | + uses: actions/upload-artifact@v4 |
| 141 | + with: |
| 142 | + name: build-output |
| 143 | + path: | |
| 144 | + package.json |
| 145 | + packages/events/package.json |
| 146 | + packages/events/dist/ |
| 147 | + packages/agent/package.json |
| 148 | + packages/agent/dist/ |
| 149 | + packages/memory/package.json |
| 150 | + packages/memory/dist/ |
| 151 | + retention-days: 1 |
| 152 | + |
| 153 | + publish-packages: |
| 154 | + name: Publish ${{ matrix.package }} |
| 155 | + needs: build |
| 156 | + runs-on: ubuntu-latest |
| 157 | + if: github.event.inputs.package == 'all' |
| 158 | + strategy: |
| 159 | + fail-fast: false |
| 160 | + max-parallel: 4 |
| 161 | + matrix: |
| 162 | + include: |
| 163 | + - package: events |
| 164 | + path: packages/events |
| 165 | + - package: agent |
| 166 | + path: packages/agent |
| 167 | + - package: memory |
| 168 | + path: packages/memory |
| 169 | + |
| 170 | + steps: |
| 171 | + - name: Checkout code |
| 172 | + uses: actions/checkout@v4 |
| 173 | + |
| 174 | + - name: Setup Node.js |
| 175 | + uses: actions/setup-node@v4 |
| 176 | + with: |
| 177 | + node-version: '22.14.0' |
| 178 | + registry-url: 'https://registry.npmjs.org' |
| 179 | + |
| 180 | + - name: Download build artifacts |
| 181 | + uses: actions/download-artifact@v4 |
| 182 | + with: |
| 183 | + name: build-output |
| 184 | + path: . |
| 185 | + |
| 186 | + - name: Update npm for OIDC support |
| 187 | + run: npm install -g npm@latest |
| 188 | + |
| 189 | + - name: Dry run check |
| 190 | + if: github.event.inputs.dry_run == 'true' |
| 191 | + working-directory: ${{ matrix.path }} |
| 192 | + run: | |
| 193 | + PACKAGE_NAME=$(node -p "require('./package.json').name") |
| 194 | + echo "Dry run - would publish ${PACKAGE_NAME}" |
| 195 | + npm publish --dry-run --access public --tag ${{ github.event.inputs.tag }} --ignore-scripts |
| 196 | +
|
| 197 | + - name: Publish to NPM |
| 198 | + if: github.event.inputs.dry_run != 'true' |
| 199 | + working-directory: ${{ matrix.path }} |
| 200 | + run: npm publish --access public --provenance --tag ${{ github.event.inputs.tag }} --ignore-scripts |
| 201 | + env: |
| 202 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 203 | + |
| 204 | + publish-single: |
| 205 | + name: Publish single package |
| 206 | + needs: build |
| 207 | + runs-on: ubuntu-latest |
| 208 | + if: github.event.inputs.package != 'all' |
| 209 | + |
| 210 | + steps: |
| 211 | + - name: Checkout code |
| 212 | + uses: actions/checkout@v4 |
| 213 | + |
| 214 | + - name: Setup Node.js |
| 215 | + uses: actions/setup-node@v4 |
| 216 | + with: |
| 217 | + node-version: '22.14.0' |
| 218 | + registry-url: 'https://registry.npmjs.org' |
| 219 | + |
| 220 | + - name: Download build artifacts |
| 221 | + uses: actions/download-artifact@v4 |
| 222 | + with: |
| 223 | + name: build-output |
| 224 | + path: . |
| 225 | + |
| 226 | + - name: Update npm for OIDC support |
| 227 | + run: npm install -g npm@latest |
| 228 | + |
| 229 | + - name: Resolve package path |
| 230 | + id: resolve-package |
| 231 | + run: | |
| 232 | + case "${{ github.event.inputs.package }}" in |
| 233 | + events) echo "path=packages/events" >> "$GITHUB_OUTPUT" ;; |
| 234 | + agent) echo "path=packages/agent" >> "$GITHUB_OUTPUT" ;; |
| 235 | + memory) echo "path=packages/memory" >> "$GITHUB_OUTPUT" ;; |
| 236 | + *) |
| 237 | + echo "Unsupported package: ${{ github.event.inputs.package }}" >&2 |
| 238 | + exit 1 |
| 239 | + ;; |
| 240 | + esac |
| 241 | +
|
| 242 | + - name: Dry run check |
| 243 | + if: github.event.inputs.dry_run == 'true' |
| 244 | + working-directory: ${{ steps.resolve-package.outputs.path }} |
| 245 | + run: | |
| 246 | + PACKAGE_NAME=$(node -p "require('./package.json').name") |
| 247 | + echo "Dry run - would publish ${PACKAGE_NAME}" |
| 248 | + npm publish --dry-run --access public --tag ${{ github.event.inputs.tag }} --ignore-scripts |
| 249 | +
|
| 250 | + - name: Publish to NPM |
| 251 | + if: github.event.inputs.dry_run != 'true' |
| 252 | + working-directory: ${{ steps.resolve-package.outputs.path }} |
| 253 | + run: npm publish --access public --provenance --tag ${{ github.event.inputs.tag }} --ignore-scripts |
| 254 | + env: |
| 255 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 256 | + |
| 257 | + create-release: |
| 258 | + name: Create Release |
| 259 | + needs: [build, publish-packages, publish-single] |
| 260 | + runs-on: ubuntu-latest |
| 261 | + if: | |
| 262 | + always() && |
| 263 | + github.event.inputs.dry_run != 'true' && |
| 264 | + (needs.publish-packages.result == 'success' || needs.publish-single.result == 'success') |
| 265 | +
|
| 266 | + steps: |
| 267 | + - name: Checkout code |
| 268 | + uses: actions/checkout@v4 |
| 269 | + with: |
| 270 | + fetch-depth: 0 |
| 271 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 272 | + |
| 273 | + - name: Download build artifacts |
| 274 | + uses: actions/download-artifact@v4 |
| 275 | + with: |
| 276 | + name: build-output |
| 277 | + path: . |
| 278 | + |
| 279 | + - name: Commit version bump and create tag |
| 280 | + env: |
| 281 | + NEW_VERSION: ${{ needs.build.outputs.new_version }} |
| 282 | + run: | |
| 283 | + git config user.name "GitHub Actions" |
| 284 | + git config user.email "actions@github.com" |
| 285 | +
|
| 286 | + git add \ |
| 287 | + package.json \ |
| 288 | + packages/events/package.json \ |
| 289 | + packages/agent/package.json \ |
| 290 | + packages/memory/package.json |
| 291 | +
|
| 292 | + if ! git diff --staged --quiet; then |
| 293 | + git commit -m "chore(release): v${NEW_VERSION}" |
| 294 | + git push |
| 295 | + fi |
| 296 | +
|
| 297 | + git tag -a "v${NEW_VERSION}" -m "Release v${NEW_VERSION}" |
| 298 | + git push origin "v${NEW_VERSION}" |
| 299 | +
|
| 300 | + - name: Create GitHub Release |
| 301 | + uses: softprops/action-gh-release@v2 |
| 302 | + with: |
| 303 | + tag_name: v${{ needs.build.outputs.new_version }} |
| 304 | + name: v${{ needs.build.outputs.new_version }} |
| 305 | + body: | |
| 306 | + ## proactive v${{ needs.build.outputs.new_version }} |
| 307 | +
|
| 308 | + ### Packages |
| 309 | + - `@agent-relay/events@${{ needs.build.outputs.new_version }}` |
| 310 | + - `@agent-relay/agent@${{ needs.build.outputs.new_version }}` |
| 311 | + - `@agent-relay/memory@${{ needs.build.outputs.new_version }}` |
| 312 | +
|
| 313 | + ### Install |
| 314 | + ```bash |
| 315 | + npm install @agent-relay/events@${{ needs.build.outputs.new_version }} |
| 316 | + npm install @agent-relay/agent@${{ needs.build.outputs.new_version }} |
| 317 | + npm install @agent-relay/memory@${{ needs.build.outputs.new_version }} |
| 318 | + ``` |
| 319 | +
|
| 320 | + ### Publish Details |
| 321 | + - Dist-tag: `${{ github.event.inputs.tag }}` |
| 322 | + - Provenance: enabled via `npm publish --provenance` |
| 323 | + - Registry: `https://registry.npmjs.org` |
| 324 | + generate_release_notes: true |
| 325 | + env: |
| 326 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 327 | + |
| 328 | + summary: |
| 329 | + name: Summary |
| 330 | + needs: [build, publish-packages, publish-single, create-release] |
| 331 | + runs-on: ubuntu-latest |
| 332 | + if: always() |
| 333 | + |
| 334 | + steps: |
| 335 | + - name: Summary |
| 336 | + run: | |
| 337 | + echo "## Publish Summary" >> "$GITHUB_STEP_SUMMARY" |
| 338 | + echo "" >> "$GITHUB_STEP_SUMMARY" |
| 339 | + echo "**Package**: \`${{ github.event.inputs.package }}\`" >> "$GITHUB_STEP_SUMMARY" |
| 340 | + echo "**Version**: \`${{ needs.build.outputs.new_version }}\`" >> "$GITHUB_STEP_SUMMARY" |
| 341 | + echo "**NPM Tag**: \`${{ github.event.inputs.tag }}\`" >> "$GITHUB_STEP_SUMMARY" |
| 342 | + echo "**Prerelease**: \`${{ needs.build.outputs.is_prerelease }}\`" >> "$GITHUB_STEP_SUMMARY" |
| 343 | + echo "**Dry Run**: \`${{ github.event.inputs.dry_run }}\`" >> "$GITHUB_STEP_SUMMARY" |
| 344 | + echo "**Provenance**: \`enabled\`" >> "$GITHUB_STEP_SUMMARY" |
| 345 | + echo "" >> "$GITHUB_STEP_SUMMARY" |
| 346 | + echo "### Results" >> "$GITHUB_STEP_SUMMARY" |
| 347 | + echo "| Stage | Status |" >> "$GITHUB_STEP_SUMMARY" |
| 348 | + echo "|-------|--------|" >> "$GITHUB_STEP_SUMMARY" |
| 349 | + echo "| Build & Version | ${{ needs.build.result }} |" >> "$GITHUB_STEP_SUMMARY" |
| 350 | + echo "| Publish All | ${{ needs.publish-packages.result }} |" >> "$GITHUB_STEP_SUMMARY" |
| 351 | + echo "| Publish Single | ${{ needs.publish-single.result }} |" >> "$GITHUB_STEP_SUMMARY" |
| 352 | + echo "| Create Release | ${{ needs.create-release.result }} |" >> "$GITHUB_STEP_SUMMARY" |
0 commit comments