|
| 1 | +name: Publish snapshot |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + packages: |
| 7 | + required: true |
| 8 | + description: "The packages to publish (e.g. @nylas/connect, @nylas/react)" |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - "@nylas/connect" |
| 12 | + - "@nylas/react" |
| 13 | + snapshot_tag: |
| 14 | + description: "Snapshot tag (e.g., alpha, beta, canary, dev)" |
| 15 | + required: true |
| 16 | + default: "canary" |
| 17 | + type: choice |
| 18 | + options: |
| 19 | + - "canary" |
| 20 | + - "alpha" |
| 21 | + - "beta" |
| 22 | + - "snapshot" |
| 23 | + - "dev" |
| 24 | + environment: |
| 25 | + required: true |
| 26 | + type: choice |
| 27 | + options: |
| 28 | + - "staging" |
| 29 | + - "production" |
| 30 | + default: "production" |
| 31 | + description: "The environment to publish to (staging or production)" |
| 32 | +run-name: "Publishing ${{ inputs.snapshot_tag }} for ${{ inputs.packages }} to ${{ inputs.environment }} by @${{ github.actor }}" |
| 33 | + |
| 34 | +env: |
| 35 | + NODE_VERSION: 22.12.0 |
| 36 | + PNPM_VERSION: 10.7.1 |
| 37 | + IS_CI: true |
| 38 | + |
| 39 | +permissions: |
| 40 | + contents: read |
| 41 | + id-token: write # needed for provenance data generation |
| 42 | + |
| 43 | +jobs: |
| 44 | + publish-snapshot: |
| 45 | + runs-on: blacksmith-2vcpu-ubuntu-2404 |
| 46 | + environment: ${{ inputs.environment }} |
| 47 | + steps: |
| 48 | + # Checkout the repo |
| 49 | + - name: Checkout |
| 50 | + uses: actions/checkout@v4 |
| 51 | + with: |
| 52 | + fetch-depth: 0 |
| 53 | + |
| 54 | + # Setup Node.js and pnpm |
| 55 | + - uses: pnpm/action-setup@v3 |
| 56 | + with: |
| 57 | + version: ${{ env.PNPM_VERSION }} |
| 58 | + run_install: false |
| 59 | + |
| 60 | + - name: Install Node.js |
| 61 | + uses: actions/setup-node@v4 |
| 62 | + with: |
| 63 | + node-version: ${{ env.NODE_VERSION }} |
| 64 | + cache: pnpm |
| 65 | + registry-url: "https://registry.npmjs.org" |
| 66 | + |
| 67 | + # Install dependencies |
| 68 | + - name: Install dependencies |
| 69 | + run: pnpm install --frozen-lockfile |
| 70 | + |
| 71 | + # Create snapshot version |
| 72 | + - name: Create snapshot version |
| 73 | + run: pnpm changeset version --snapshot ${{ inputs.snapshot_tag }} && git add --all |
| 74 | + env: |
| 75 | + GITHUB_TOKEN: ${{ secrets.BOT_PAT }} |
| 76 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 77 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 78 | + |
| 79 | + # Build packages |
| 80 | + - name: Build packages |
| 81 | + run: pnpm nx run-many -t build --parallel=3 --projects=${{ inputs.packages }} |
| 82 | + env: |
| 83 | + IMAGE_TAG: ${{ inputs.snapshot_tag }} |
| 84 | + |
| 85 | + # Publish snapshot to npm and output release tags to $GITHUB_STEP_SUMMARY |
| 86 | + - name: Publish snapshot |
| 87 | + run: | |
| 88 | + # Publish packages and capture output |
| 89 | + pnpm changeset publish --no-git-tag --snapshot --tag ${{ inputs.snapshot_tag }} | tee /tmp/changeset_publish.log |
| 90 | +
|
| 91 | + # Add formatted output to GitHub step summary |
| 92 | + echo '### 📦 Published Snapshot Packages' >> $GITHUB_STEP_SUMMARY |
| 93 | + echo '' >> $GITHUB_STEP_SUMMARY |
| 94 | +
|
| 95 | + # Extract and display only the published package versions |
| 96 | + grep -Eo '🦋[[:space:]]+(@nylas/(connect|react)@[0-9]+\.[0-9]+\.[0-9]+-[a-zA-Z0-9]+)' /tmp/changeset_publish.log | \ |
| 97 | + sed 's/🦋[[:space:]]\+/- /' >> $GITHUB_STEP_SUMMARY || echo '- No packages published' >> $GITHUB_STEP_SUMMARY |
| 98 | +
|
| 99 | + # Optionally add full log in a collapsible section |
| 100 | + echo '' >> $GITHUB_STEP_SUMMARY |
| 101 | + echo '<details><summary>📋 Full publish log</summary>' >> $GITHUB_STEP_SUMMARY |
| 102 | + echo '' >> $GITHUB_STEP_SUMMARY |
| 103 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 104 | + cat /tmp/changeset_publish.log >> $GITHUB_STEP_SUMMARY |
| 105 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 106 | + echo '</details>' >> $GITHUB_STEP_SUMMARY |
| 107 | + env: |
| 108 | + GITHUB_TOKEN: ${{ secrets.BOT_PAT }} |
| 109 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 110 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments