Files
video.js-mirror/.github/workflows/release-pr.yml

176 lines
6.4 KiB
YAML

name: Release PR
on:
push:
branches:
- 'release-please--branches--main'
# release-please force-pushes the release branch on every merge to main, and each
# push starts a fresh run here that rewrites the changelog for the branch as it
# now stands. Each run regenerates everything from scratch, so only the run for
# the newest push can produce the right changelog: cancel any run still going
# when a new push arrives, rather than letting a run for an older branch state
# finish after it and commit a stale changelog.
concurrency:
group: release-pr
cancel-in-progress: true
jobs:
changelog:
runs-on: blacksmith-2vcpu-ubuntu-2404
permissions:
contents: write
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Read version from manifest
id: version
run: |
VERSION=$(jq -r '."packages/core"' .github/release-please/.release-please-manifest.json)
echo "tag=@videojs/core@${VERSION}" >> "$GITHUB_OUTPUT"
- uses: actions/setup-node@v5
with:
node-version-file: '.nvmrc'
package-manager-cache: false
# Generates Video.js 10 from main, excluding the merged Video.js 8 history
# (history/v8-tip), and Video.js 8 and earlier from origin/8.x. fetch-depth: 0
# fetches that branch and the release tags. Runs git-cliff via npx.
- name: Update root changelog
run: node build/scripts/generate-changelog.mjs --tag "$TAG"
env:
TAG: ${{ steps.version.outputs.tag }}
GITHUB_TOKEN: ${{ github.token }}
- name: Extract changelog for site
run: |
# Find first versioned release heading (skip [Unreleased])
HEADING=$(grep -n '^## \[@videojs/core@' CHANGELOG.md | head -1) || true
if [ -z "$HEADING" ]; then
echo "::warning::No versioned release heading found in CHANGELOG.md — skipping site extraction"
exit 0
fi
LINE_NUM=$(echo "$HEADING" | cut -d: -f1)
HEADING_TEXT=$(echo "$HEADING" | cut -d: -f2-)
# Parse version and date from heading: ## [@videojs/core@VERSION] - DATE
VERSION=$(echo "$HEADING_TEXT" | sed -n 's/.*@videojs\/core@\([^]]*\)\].*/\1/p')
DATE=$(echo "$HEADING_TEXT" | sed -n 's/.*- \(.*\)/\1/p')
if [ -z "$VERSION" ] || [ -z "$DATE" ]; then
echo "::warning::Could not parse version or date from heading — skipping site extraction"
exit 0
fi
# Find the next ## [ heading to delimit the body
NEXT_LINE=$(tail -n +"$((LINE_NUM + 1))" CHANGELOG.md | grep -n '^## \[' | head -1 | cut -d: -f1) || true
if [ -n "$NEXT_LINE" ]; then
END_LINE=$((LINE_NUM + NEXT_LINE - 1))
BODY=$(sed -n "$((LINE_NUM + 1)),$((END_LINE))p" CHANGELOG.md | sed '/^$/N;/^\n$/d')
else
BODY=$(tail -n +"$((LINE_NUM + 1))" CHANGELOG.md)
fi
# Commit titles are untrusted MDX input. Escape JSX/expression
# delimiters outside inline code spans while preserving their output.
BODY=$(printf '%s\n' "$BODY" | perl -pe 's{(`[^`]*`)(*SKIP)(*F)|([<>{}])}{\\$2}g')
# Determine prerelease and breaking
PRERELEASE=false
if echo "$VERSION" | grep -q '-'; then
PRERELEASE=true
fi
BREAKING=false
if echo "$BODY" | grep -qiF '**breaking**'; then
BREAKING=true
fi
# Extract compare URL from CHANGELOG footer
COMPARE_URL=$(grep -Fm1 "[@videojs/core@${VERSION}]: " CHANGELOG.md | sed 's/.*]: //' || true)
# Write the site changelog file
OUTFILE="site/src/content/changelog/${VERSION}.mdx"
mkdir -p "$(dirname "$OUTFILE")"
cat > "$OUTFILE" <<EOF
---
description: ""
date: ${DATE}
version: "${VERSION}"
prerelease: ${PRERELEASE}
breaking: ${BREAKING}
compareUrl: "${COMPARE_URL}"
---
${BODY}
EOF
echo "Wrote $OUTFILE (version=$VERSION, date=$DATE, prerelease=$PRERELEASE, breaking=$BREAKING)"
- name: Commit root changelog
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md site/src/content/changelog/
git diff --cached --quiet || git commit -m "chore(release): update root changelog"
git pull --rebase
git push
# cd.yml publishes through npm trusted publishing, which npm only lets a
# maintainer configure on a package that already exists. Flag the release PR
# while any public package isn't on npm yet, so `pnpm release:trust` runs
# before merge instead of the publish failing after the release is tagged.
# Reading trust configurations needs npm 2FA, so this can't verify them.
trusted-publishing:
needs: changelog
runs-on: blacksmith-2vcpu-ubuntu-2404
permissions:
contents: read
statuses: write
steps:
# The changelog job's commit is the pull request head, and a push made with
# GITHUB_TOKEN starts no workflow that could check it, so check out the
# branch tip and report on it with a commit status.
- uses: actions/checkout@v5
with:
ref: ${{ github.ref_name }}
- name: Setup pnpm
uses: pnpm/action-setup@v6.1.0
- uses: actions/setup-node@v5
with:
node-version-file: '.nvmrc'
package-manager-cache: false
- name: Check every public package is on npm
id: check
run: node build/scripts/setup-trusted-publishing.mjs --check
- name: Report status on the release PR
if: ${{ !cancelled() }}
env:
GH_TOKEN: ${{ github.token }}
OUTCOME: ${{ steps.check.outcome }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
if [ "$OUTCOME" = 'success' ]; then
state=success
description='Every public package is on npm'
else
state=failure
description='A new package needs pnpm release:trust before merging; see details'
fi
gh api "repos/$GITHUB_REPOSITORY/statuses/$(git rev-parse HEAD)" \
-f state="$state" \
-f context='npm trusted publishing' \
-f description="$description" \
-f target_url="$RUN_URL"