docs: deploy Cookbook site #230
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| pull_request: | |
| push: | |
| branches: [main] | |
| concurrency: | |
| group: release-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| id-token: write | |
| jobs: | |
| snapshot: | |
| name: Build & snapshot release | |
| if: github.event_name == 'pull_request' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| environment: release | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v6 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| registry-url: https://registry.npmjs.org | |
| package-manager-cache: false | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Build | |
| run: pnpm build | |
| - name: Set snapshot version | |
| id: version | |
| run: | | |
| SHORT_SHA=$(git rev-parse --short HEAD) | |
| SNAPSHOT_VERSION="0.0.0-snapshot.${SHORT_SHA}" | |
| npm pkg set version="${SNAPSHOT_VERSION}" | |
| echo "version=${SNAPSHOT_VERSION}" >> $GITHUB_OUTPUT | |
| - name: Publish snapshot | |
| run: npm publish --tag pr_${{ github.event.number }} --access public | |
| - name: Comment on PR | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const setMessage = (await import('${{ github.workspace }}/scripts/ci/set-message.mjs')).default; | |
| await setMessage({ | |
| header: '## 📦 Snapshot release', | |
| body: `Published [\`${{ steps.version.outputs.version }}\`](https://www.npmjs.com/package/@tenphi/glaze/v/${{ steps.version.outputs.version }}).\n\n\`\`\`\npnpm add @tenphi/glaze@${{ steps.version.outputs.version }}\n\`\`\``, | |
| github, | |
| repo: context.repo, | |
| prNumber: ${{ github.event.number }}, | |
| }); | |
| release: | |
| if: github.event_name == 'push' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| environment: release | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v6 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| registry-url: https://registry.npmjs.org | |
| package-manager-cache: false | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Build | |
| run: pnpm build | |
| - name: Create Release Pull Request or Publish | |
| id: changesets | |
| uses: changesets/action@v1 | |
| with: | |
| publish: pnpm release | |
| title: 'chore: version packages' | |
| commit: 'chore: version packages' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| NPM_CONFIG_PROVENANCE: true | |
| - name: Create GitHub Release | |
| if: steps.changesets.outputs.published == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const publishedPackages = JSON.parse('${{ steps.changesets.outputs.publishedPackages }}'); | |
| for (const pkg of publishedPackages) { | |
| const tag = `v${pkg.version}`; | |
| try { | |
| const { data: existing } = await github.rest.repos.getReleaseByTag({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag, | |
| }); | |
| await github.rest.repos.updateRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| release_id: existing.id, | |
| name: tag, | |
| generate_release_notes: true, | |
| }); | |
| core.info(`Updated existing release for ${tag}`); | |
| } catch (e) { | |
| if (e.status === 404) { | |
| await github.rest.repos.createRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag_name: tag, | |
| name: tag, | |
| generate_release_notes: true, | |
| }); | |
| core.info(`Created release for ${tag}`); | |
| } else { | |
| throw e; | |
| } | |
| } | |
| } | |
| - name: Trigger website redeploy | |
| if: steps.changesets.outputs.published == 'true' | |
| uses: peter-evans/repository-dispatch@v3 | |
| with: | |
| token: ${{ secrets.DISPATCH_TOKEN }} | |
| repository: tenphi/tasty.style | |
| event-type: glaze-release | |
| client-payload: '{"version": "${{ fromJSON(steps.changesets.outputs.publishedPackages)[0].version }}"}' |