Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/support-maintenance-branches.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
75 changes: 75 additions & 0 deletions .github/actions/checks/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ inputs:
description: 'Ref the changeset check compares against. Leave empty to skip it, e.g. for a release.'
required: false
default: ''
target-branch:
description: 'Branch the checked change goes into. On "maintenance/<major>" major bumps are rejected.'
required: false
default: ''

runs:
using: 'composite'
Expand Down Expand Up @@ -41,6 +45,63 @@ runs:
# Rejects unparsable frontmatter, unknown package names and invalid bump types.
pnpm changeset status --since="$BASE_REF"

# A maintenance branch stays on its major; main moves on to higher majors (see
# "Check main release line"), so a major bump would collide with main's versions.
- name: Check maintenance release line
id: maintenance-check
if: ${{ startsWith(inputs.target-branch, 'maintenance/') }}
continue-on-error: ${{ inputs.perform-all-checks == 'true' }}
shell: bash
env:
TARGET_BRANCH: ${{ inputs.target-branch }}
run: |
BRANCH_MAJOR="${TARGET_BRANCH#maintenance/}"
VERSION=$(jq -r .version packages/ckeditor5-common/package.json)
if [ "${VERSION%%.*}" != "$BRANCH_MAJOR" ]; then
echo "::error::$TARGET_BRANCH only releases $BRANCH_MAJOR.x.y, but the packages have version $VERSION. A maintenance branch accepts neither major bumps nor changes based on another major."
exit 1
fi

MAJOR_CHANGESETS=$(node scripts/major-changesets.mjs)
if [ -n "$MAJOR_CHANGESETS" ]; then
echo "::error::Major changes are not allowed on $TARGET_BRANCH; use patch or minor:"
echo "$MAJOR_CHANGESETS"
exit 1
fi
echo "No major changesets on $TARGET_BRANCH."

# Counterpart on main: once maintenance/<major> exists (it may be created while main is
# still on that major), main must not release that major again. An unreleased version
# fails: the "Version Packages" PR and the release itself, but also main after a failed
# release. A released version only warns, so patch and minor pull requests learn early
# that they will not be released before the next major. A pending major changeset makes
# the next release major, so it passes; otherwise the pull request adding it could
# never be integrated.
- name: Check main release line
id: main-line-check
if: ${{ inputs.target-branch == 'main' }}
continue-on-error: ${{ inputs.perform-all-checks == 'true' }}
shell: bash
run: |
VERSION=$(jq -r .version packages/ckeditor5-common/package.json)
MAJOR="${VERSION%%.*}"
if ! git ls-remote --exit-code --heads origin "maintenance/$MAJOR" > /dev/null; then
echo "main may release $VERSION."
exit 0
fi
MAJOR_CHANGESETS=$(node scripts/major-changesets.mjs)
if [ -n "$MAJOR_CHANGESETS" ]; then
echo "maintenance/$MAJOR exists, but the next release is major:"
echo "$MAJOR_CHANGESETS"
exit 0
fi
if git rev-parse -q --verify "refs/tags/$VERSION" > /dev/null; then
echo "::warning::maintenance/$MAJOR exists, so main's next release must be major. Changes merged into main are not released until a 'major' changeset is added; fixes for $MAJOR.x.y go to maintenance/$MAJOR."
exit 0
fi
echo "::error::maintenance/$MAJOR exists, so main must not release $VERSION: its next release must be major. Add a 'major' changeset on main."
exit 1

- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
id: playwright-cache
with:
Expand Down Expand Up @@ -114,6 +175,20 @@ runs:
FAILED=true
fi

if [ "${{ steps.maintenance-check.outcome }}" == "failure" ]; then
echo "❌ Maintenance release line check failed" >> $GITHUB_STEP_SUMMARY
FAILED=true
elif [ "${{ steps.maintenance-check.outcome }}" == "success" ]; then
echo "✅ Maintenance release line check passed" >> $GITHUB_STEP_SUMMARY
fi

if [ "${{ steps.main-line-check.outcome }}" == "failure" ]; then
echo "❌ Main release line check failed" >> $GITHUB_STEP_SUMMARY
FAILED=true
elif [ "${{ steps.main-line-check.outcome }}" == "success" ]; then
echo "✅ Main release line check passed" >> $GITHUB_STEP_SUMMARY
fi

if [ "${{ steps.unit-tests.outcome }}" == "success" ]; then
echo "✅ Unit tests passed" >> $GITHUB_STEP_SUMMARY
else
Expand Down
131 changes: 131 additions & 0 deletions .github/workflows/create-maintenance-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
name: "Create Maintenance Branch"

# Creates maintenance/<major> for an older major, so it can receive patch and minor
# releases while main moves on. The branch is a release line of its own: changesets,
# "Version Packages" PR, QA gate and release work there just like on main.
on:
workflow_dispatch:
inputs:
major:
description: 'Major version to maintain, e.g. "28" creates maintenance/28 from the latest 28.x.y release'
required: true
type: string

permissions:
contents: read

run-name: |
Create maintenance/${{ inputs.major }}

jobs:
create:
name: Create maintenance/${{ inputs.major }}
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: main
fetch-depth: 0
# Pushes to maintenance/* are restricted by the ruleset; coremedia-ci bypasses it.
token: ${{ secrets.GH_PAT_PUSH_FROM_GHA }}

- name: Configure Git
run: |
git config user.name 'coremedia-ci'
git config user.email 'coremedia-ci@coremedia.com'

- name: Validate
id: validate
env:
MAJOR: ${{ inputs.major }}
run: |
fail() { echo "::error::$1"; exit 1; }

[[ "$MAJOR" =~ ^[1-9][0-9]*$ ]] || fail "\"$MAJOR\" is not a major version number."
BRANCH="maintenance/$MAJOR"

if git ls-remote --exit-code --heads origin "$BRANCH" > /dev/null; then
fail "$BRANCH already exists."
fi

# main may be on the same major (e.g. right before breaking changes): the checks
# action then rejects any further release of $MAJOR.x.y from main.
MAIN_VERSION=$(jq -r .version packages/ckeditor5-common/package.json)
MAIN_MAJOR="${MAIN_VERSION%%.*}"
[ "$MAIN_MAJOR" -ge "$MAJOR" ] \
|| fail "main is on major $MAIN_MAJOR; there is no release of major $MAJOR to maintain."

# An unreleased version on main (e.g. after a failed release) would be left out of
# the branch, and main could not release it anymore.
if [ "$MAIN_MAJOR" -eq "$MAJOR" ]; then
git rev-parse -q --verify "refs/tags/$MAIN_VERSION" > /dev/null \
|| fail "main holds the unreleased version $MAIN_VERSION; release it first."

# Changes merged into main but not yet released are not part of the branch.
# Empty changesets (no package bumps) release nothing, so they are ignored.
PENDING=""
for FILE in .changeset/*.md; do
[ "$FILE" = .changeset/README.md ] && continue
awk '/^---[[:space:]]*$/ { n++; next } n == 1 && !/^[[:space:]]*(#.*)?$/ { found = 1 } END { exit !found }' "$FILE" \
&& PENDING+="$FILE"$'\n'
done
if [ -n "$PENDING" ]; then
echo "::warning::main has unreleased changes that are not part of $BRANCH; cherry-pick them including their changesets if $MAJOR.x.y needs them:"
echo -n "$PENDING"
echo -n "$PENDING" > "$RUNNER_TEMP/pending-changesets.txt"
fi
fi

TAG=$(git tag --list "$MAJOR.*" | grep -E "^$MAJOR\.[0-9]+\.[0-9]+$" | sort -V | tail -n 1 || true)
[ -n "$TAG" ] || fail "No release $MAJOR.x.y found."

# Releases made with the old release process have neither Changesets nor these
# workflows, so a branch cut from them could not release.
git cat-file -e "$TAG:.github/workflows/create-maintenance-branch.yml" 2> /dev/null \
|| fail "Release $TAG predates the Changesets-based maintenance support; cut the branch manually or release $MAJOR.x.y from main first."

echo "Creating $BRANCH from $TAG (main is on major $MAIN_MAJOR)"
{
echo "branch=$BRANCH"
echo "tag=$TAG"
echo "main-major=$MAIN_MAJOR"
} >> "$GITHUB_OUTPUT"

- name: Create and push branch
env:
BRANCH: ${{ steps.validate.outputs.branch }}
TAG: ${{ steps.validate.outputs.tag }}
run: |
git switch -c "$BRANCH" "$TAG"

# Changesets compares against its base branch, e.g. in "changeset status".
jq --indent 2 --arg branch "$BRANCH" '.baseBranch = $branch' .changeset/config.json \
> "$RUNNER_TEMP/config.json"
mv "$RUNNER_TEMP/config.json" .changeset/config.json

git add .changeset/config.json
git commit -m "ci: Create $BRANCH from $TAG"
git push origin "$BRANCH"

- name: Summary
env:
BRANCH: ${{ steps.validate.outputs.branch }}
TAG: ${{ steps.validate.outputs.tag }}
MAJOR: ${{ inputs.major }}
MAIN_MAJOR: ${{ steps.validate.outputs.main-major }}
run: |
{
echo "## ✅ Created [$BRANCH](${{ github.server_url }}/${{ github.repository }}/tree/$BRANCH) from $TAG"
echo ""
echo "- Open pull requests against \`$BRANCH\`; they need a \`patch\` or \`minor\` changeset."
echo "- Releases are published with the npm dist-tag \`maintenance-$MAJOR\` and do not become \`latest\`."
if [ "$MAIN_MAJOR" = "$MAJOR" ]; then
echo "- main is still on major $MAJOR: its next release must be major. Its \"Version Packages\" pull request fails until a \`major\` changeset is pending on main."
fi
if [ -s "$RUNNER_TEMP/pending-changesets.txt" ]; then
echo "- ⚠️ main has unreleased changes that are not part of $BRANCH. Cherry-pick them, including their changesets, if $MAJOR.x.y needs them:"
sed 's/.*/ - `&`/' "$RUNNER_TEMP/pending-changesets.txt"
fi
echo "- Dependabot only updates main: add an entry with \`target-branch: $BRANCH\` to \`.github/dependabot.yml\` on main if this line should get action updates."
} >> "$GITHUB_STEP_SUMMARY"
6 changes: 5 additions & 1 deletion .github/workflows/create-or-update-release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- 'maintenance/*'

permissions:
contents: write
Expand Down Expand Up @@ -44,5 +45,8 @@ jobs:
uses: changesets/action@8488615a623b1b9c987934bb89eae8af6a946ac1 # v2.1.1
with:
version-script: pnpm ci:version
pr-base-branch: main
# One "Version Packages" PR per release line (branch changeset-release/<branch>).
pr-base-branch: ${{ github.ref_name }}
pr-title: Version Packages (${{ github.ref_name }})
commit-message: Version Packages (${{ github.ref_name }})
github-token: ${{ secrets.GH_PAT_PUSH_FROM_GHA }}
4 changes: 3 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ jobs:
uses: ./.github/actions/checks
with:
perform-all-checks: 'true'
base-ref: origin/main
# Manual runs have no base to compare against, so they skip the changeset check.
base-ref: ${{ github.event_name == 'pull_request' && format('origin/{0}', github.base_ref) || '' }}
target-branch: ${{ github.base_ref || github.ref_name }}

fork:
name: Fork Pull Request
Expand Down
44 changes: 26 additions & 18 deletions .github/workflows/qa-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ on:
types: [labeled, unlabeled]
branches:
- main
# Release lines created by create-maintenance-branch.yml. The legacy maintenance/<x>.0
# branches do not run this: pull_request_target uses the base branch's workflow files.
- 'maintenance/*'

permissions:
contents: write
pull-requests: write

env:
# Every release line has its own queue: main or maintenance/<major>.
BASE_BRANCH: ${{ github.event.pull_request.base.ref }}

concurrency:
group: qa-gate-main
group: qa-gate-${{ github.event.pull_request.base.ref }}
cancel-in-progress: false

run-name: |
Expand All @@ -37,10 +44,10 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}
run: |
# Get all open PRs into main with 'approved' label but without 'qa-failed', sorted by updated_at (oldest first)
# Get all open PRs into the base branch with 'approved' label but without 'qa-failed', sorted by updated_at (oldest first)
OLDEST_PR=$(gh api \
-H "Accept: application/vnd.github+json" \
"/repos/${{ github.repository }}/pulls?state=open&base=main&sort=updated&direction=asc" \
"/repos/${{ github.repository }}/pulls?state=open&base=${BASE_BRANCH}&sort=updated&direction=asc" \
--jq '[.[] | select((.labels | map(.name) | contains(["approved"])) and (.labels | map(.name) | contains(["qa-failed"]) | not))] | first | .number')

CURRENT_PR=${{ github.event.pull_request.number }}
Expand Down Expand Up @@ -79,10 +86,10 @@ jobs:
needs: check-queue
if: needs.check-queue.outputs.should-proceed == 'true'
steps:
- name: Checkout main
- name: Checkout base branch
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: main
ref: ${{ env.BASE_BRANCH }}
fetch-depth: 0
token: ${{ secrets.GH_PAT_PUSH_FROM_GHA }}

Expand All @@ -104,10 +111,10 @@ jobs:
# targets (git rebase -i --autosquash) before the PR can be integrated.
MARKER_COMMITS=$(git log --no-merges -E \
--grep='^(fixup|squash|amend)! ' \
--format='%h %s' "main..origin/$PR_BRANCH" || true)
--format='%h %s' "${BASE_BRANCH}..origin/$PR_BRANCH" || true)

if [ -n "$MARKER_COMMITS" ]; then
echo "::error::The PR contains fixup!/squash!/amend! commits. Run 'git rebase -i --autosquash main' and push before integration."
echo "::error::The PR contains fixup!/squash!/amend! commits. Run 'git rebase -i --autosquash ${BASE_BRANCH}' and push before integration."
{
echo "## ❌ Autosquash commits found"
echo ""
Expand All @@ -122,15 +129,15 @@ jobs:

echo "No fixup/squash commits found."

- name: Merge PR branch into main
- name: Merge PR branch into base branch
env:
PR_BRANCH: ${{ needs.check-queue.outputs.pr-branch }}
PR_NUMBER: ${{ needs.check-queue.outputs.pr-number }}
run: |
echo "Fetching PR branch: $PR_BRANCH"
git fetch origin "$PR_BRANCH"

echo "Merging $PR_BRANCH into main"
echo "Merging $PR_BRANCH into $BASE_BRANCH"
if ! git merge "origin/$PR_BRANCH" --no-edit -m "Merge PR #$PR_NUMBER"; then
echo "::error::Merge conflict detected. Please rebase your branch."
exit 1
Expand All @@ -148,25 +155,26 @@ jobs:
- name: Checks
uses: ./.github/actions/checks
with:
base-ref: origin/main
base-ref: origin/${{ env.BASE_BRANCH }}
target-branch: ${{ env.BASE_BRANCH }}

- name: Push to main
- name: Push to base branch
env:
PR_NUMBER: ${{ needs.check-queue.outputs.pr-number }}
run: |
echo "Pushing to main..."
git push origin main
echo "Pushing to $BASE_BRANCH..."
git push origin "$BASE_BRANCH"

# Update local tracking to match remote after push
git fetch origin main
git branch --set-upstream-to=origin/main main
git fetch origin "$BASE_BRANCH"
git branch --set-upstream-to="origin/$BASE_BRANCH" "$BASE_BRANCH"

echo "## ✅ PR #$PR_NUMBER successfully integrated" >> $GITHUB_STEP_SUMMARY
echo "## ✅ PR #$PR_NUMBER successfully integrated into $BASE_BRANCH" >> $GITHUB_STEP_SUMMARY

- name: Deploy Storybook for main
- name: Deploy Storybook for base branch
uses: ./.github/actions/deploy-storybook
with:
branch-name: main
branch-name: ${{ env.BASE_BRANCH }}
ckeditor-license: ${{ secrets.CKEDITOR_LICENSE }}

on-failure:
Expand Down
Loading
Loading