Skip to content

Astro 7 support

Astro 7 support #59

Workflow file for this run

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' && github.head_ref || github.ref }}
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
steps:
- name: Checkout Repo
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
# While releasing with changesets works with a shallow clone, this is not the case of
# running `changeset status` which does not extend a shallow clone.
fetch-depth: 0
persist-credentials: false
- name: Setup PNPM
uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6.0.8
- name: Setup Node
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 24.16.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
- name: Get preview packages
id: preview
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.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(changeset.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
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
# 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