chore: dynamic preview releases (#14114)

This commit is contained in:
Florian Lefebvre
2025-07-24 14:06:20 +02:00
committed by GitHub
parent 9cfccc7b9e
commit b49dab2a5b
3 changed files with 107 additions and 2 deletions

View File

@@ -4,7 +4,7 @@
"commit": false,
"linked": [],
"access": "public",
"baseBranch": "main",
"baseBranch": "origin/main",
"updateInternalDependencies": "patch",
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
"onlyUpdatePeerDependentsWhenOutOfRange": true

View File

@@ -0,0 +1,105 @@
name: Preview release test
on:
pull_request:
branches: [main]
types: [labeled]
concurrency:
group: ${{ github.workflow }}-${{ github.event.number }}
cancel-in-progress: true
permissions:
contents: read
actions: write
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
FORCE_COLOR: true
ASTRO_TELEMETRY_DISABLED: true
# 7 GiB by default on GitHub, setting to 6 GiB
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
NODE_OPTIONS: --max-old-space-size=6144
jobs:
preview:
if: ${{ github.repository_owner == 'withastro' && github.event.label.name == 'markdown' }}
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
issues: write
pull-requests: write
name: Publish preview release
timeout-minutes: 5
steps:
- name: Disable git crlf
run: git config --global core.autocrlf false
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
# Changeset needs access to the main branch to find pending changesets
- name: Checkout base ref
run: git fetch origin ${{ github.base_ref }} && git checkout ${{ github.base_ref }}
- name: Checkout head ref
run: git fetch origin ${{ github.head_ref }} && git checkout ${{ github.head_ref }}
- name: Setup PNPM
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
- name: Setup Node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: 22
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Build Packages
run: pnpm run build
- name: Get changeset status
id: changeset-status
run: |
pnpm changeset status --output changes.json
echo "changes-output=$(cat changes.json | jq -c .)" >> $GITHUB_OUTPUT
- name: Get pnpm packages
id: pnpm-packages
run: |
pnpm list --recursive --depth -1 --json >> pnpm.json
echo "packages-output=$(cat pnpm.json | jq -c .)" >> $GITHUB_OUTPUT
- name: Compute affected packages
id: compute-affected-packages
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
env:
CHANGES: ${{ steps.changeset-status.outputs.changes-output }}
PACKAGES: ${{ steps.pnpm-packages.outputs.packages-output }}
with:
script: |
const { relative } = require('node:path');
const changes = JSON.parse(process.env.CHANGES);
const packages = JSON.parse(process.env.PACKAGES);
const packagesMap = Object.fromEntries(packages.map(p => [p.name, relative(process.cwd(), p.path)]));
const affectedPackages = [...new Set(changes.changesets.map(c => c.releases.map(r=> packagesMap[r.name])).flat())]
core.setOutput('affected-packages', JSON.stringify(affectedPackages));
- name: Remove Preview Label
uses: actions-ecosystem/action-remove-labels@2ce5d41b4b6aa8503e285553f75ed56e0a40bae0 # v1.3.0
with:
labels: "markdown"
- name: Publish packages
env:
AFFECTED_PACKAGES: ${{ steps.compute-affected-packages.outputs.affected-packages }}
run: |
packages=$(echo $AFFECTED_PACKAGES | jq -r '.[]' | tr '\n' ' ')
if [ -n "$packages" ]; then
pnpm dlx pkg-pr-new publish --pnpm --compact --no-template $packages
else
echo "No affected packages to publish"
fi

View File

@@ -285,7 +285,7 @@ Assigning labels isn't always easy and many times the distinction between the di
### Preview releases
You can trigger a preview release **from a PR** anytime by using the label `pr preview`. Add this label, and a workflow will trigger, which at the end will add a comment with the instructions of how to install the preview release.
You can trigger a preview release **from a PR** anytime by using the label `pr preview`. Add this label, and a workflow will trigger, which at the end will add a comment with the instructions of how to install the preview release. A preview release will be created for each package that has a pending changeset.
If you're in need to trigger multiple preview releases from the same PR, remove the label and add it again.