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