-
-
Notifications
You must be signed in to change notification settings - Fork 943
Add preview releases #3610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add preview releases #3610
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| name: Preview Release | ||
| permissions: {} | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [main] | ||
| types: [labeled] | ||
|
|
||
| # Automatically cancel in-progress actions on the same branch | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }} | ||
HiDeoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| preview: | ||
| name: Preview Release | ||
| if: ${{ github.repository_owner == 'withastro' && github.event.label.name == 'pr-preview' }} | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
delucis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| steps: | ||
| - name: Checkout Repo | ||
| uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Setup PNPM | ||
| uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0 | ||
|
|
||
| - name: Setup Node | ||
| uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 | ||
| with: | ||
| node-version: 24.10.0 | ||
| cache: 'pnpm' | ||
|
|
||
| - name: Install Dependencies | ||
| run: pnpm i | ||
|
|
||
| - name: Get changeset status | ||
| id: changeset | ||
| run: | | ||
| pnpm changeset status --output changeset-status.json | ||
| echo "status=$(cat changeset-status.json | jq -c .)" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Get pnpm packages | ||
| id: pnpm | ||
| run: echo "packages=$(pnpm list --recursive --depth -1 --json | jq -c .)" >> $GITHUB_OUTPUT | ||
HiDeoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - name: Get preview packages | ||
| id: preview | ||
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | ||
| env: | ||
| CHANGESET: ${{ steps.changeset.outputs.status }} | ||
| PACKAGES: ${{ steps.pnpm.outputs.packages }} | ||
| with: | ||
| script: | | ||
| const { relative } = require('node:path'); | ||
| const changeset = JSON.parse(process.env.CHANGESET); | ||
| const packages = JSON.parse(process.env.PACKAGES); | ||
| # A map of all packages name in the monorepo to their relative paths. | ||
| const packagePathsMap = Object.fromEntries(packages.map(pkg => [pkg.name, relative(process.cwd(), pkg.path)])); | ||
| # A list of all relative package paths to publish in this preview release. | ||
| const previewPackagePaths = [...new Set(changes.changesets.map(change => change.releases.map(release => packagePathsMap[release.name])).flat())] | ||
| # A space-separated string of all relative package paths to publish in this preview release (or an empty string if none). | ||
| core.setOutput('packages', previewPackagePaths.join(' ')); | ||
|
|
||
| # We remove the preview label before publishing so that the label is always removed even if | ||
| # publishing fails, so we can retry by only adding the label again. | ||
| - name: Remove Preview Label | ||
| uses: actions-ecosystem/action-remove-labels@2ce5d41b4b6aa8503e285553f75ed56e0a40bae0 # v1.3.0 | ||
delucis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| with: | ||
| labels: pr-preview | ||
|
|
||
| - name: Publish preview packages | ||
| env: | ||
| PACKAGES: ${{ steps.preview.outputs.packages }} | ||
| run: | | ||
| if [ -z "$PACKAGES" ]; then | ||
| echo "::error::No packages to publish in this preview release." | ||
| echo "::error::Make sure the pull request includes a changeset." | ||
| exit 1 | ||
| fi | ||
delucis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Note that `--compact` is used for shorter URLs but requires packages to be published on | ||
| # npm. This means that it's not possible to publish a preview for a new package that has | ||
| # not yet been published on npm. | ||
| pnpm dlx pkg-pr-new publish --pnpm --compact --packageManager=pnpm --no-template $packages | ||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.