From c6f3d1ce77976dd456c5654251025f9e1921f094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Hamburger=20Gr=C3=B8ngaard?= Date: Wed, 11 Nov 2026 13:34:52 +0000 Subject: [PATCH 1/4] ci: run the commit, format, lint, type and knip checks from the shared `Checks` workflow The five check workflows move into one `checks` job that calls `checks.yml` in `portabletext/.github`, so the required checks become `checks / commits`, `checks / format`, `checks / lint`, `checks / types` and `checks / knip`. The commit check gains one rule: a commit whose subject is not `fix:` or `feat:` fails when it adds a changeset. --- .github/workflows/check-commits.yml | 148 ---------------------------- .github/workflows/check-format.yml | 25 ----- .github/workflows/check-knip.yml | 23 ----- .github/workflows/check-lint.yml | 25 ----- .github/workflows/check-types.yml | 25 ----- .github/workflows/checks.yml | 18 ++++ 6 files changed, 18 insertions(+), 246 deletions(-) delete mode 100644 .github/workflows/check-commits.yml delete mode 100644 .github/workflows/check-format.yml delete mode 100644 .github/workflows/check-knip.yml delete mode 100644 .github/workflows/check-lint.yml delete mode 100644 .github/workflows/check-types.yml create mode 100644 .github/workflows/checks.yml diff --git a/.github/workflows/check-commits.yml b/.github/workflows/check-commits.yml deleted file mode 100644 index fe6d6fd..0000000 --- a/.github/workflows/check-commits.yml +++ /dev/null @@ -1,148 +0,0 @@ -name: check-commits - -on: - pull_request: - # `edited` covers base-branch retargets, which change the commit set - # without firing `synchronize`. - types: [opened, synchronize, reopened, edited] - -permissions: - contents: read - pull-requests: read - -jobs: - check-commits: - runs-on: ubuntu-latest - env: - GH_TOKEN: ${{ github.token }} - - steps: - - name: Check for unsquashed fixup/squash/amend commits - run: | - offenders=$(gh api "repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/commits" --paginate \ - --jq '.[] | select(.commit.message | split("\n")[0] | test("^(fixup|squash|amend)!")) | "\(.sha[0:7]) \(.commit.message | split("\n")[0])"') - - if [ -n "$offenders" ]; then - echo "Found unsquashed fixup/squash/amend commits:" - echo "$offenders" - echo "Squash them with 'git rebase -i --autosquash' before merge." - exit 1 - fi - - - name: Check that each added changeset opens with a commit subject - env: - REPO: ${{ github.repository }} - PR_NUMBER: ${{ github.event.pull_request.number }} - HEAD_SHA: ${{ github.event.pull_request.head.sha }} - run: | - changesets=$(gh api "repos/$REPO/pulls/$PR_NUMBER/files" --paginate \ - --jq '.[] | select(.status == "added") | .filename | select(test("^\\.changeset/[^/]+\\.md$")) | select(. != ".changeset/README.md")') - - if [ -z "$changesets" ]; then - echo "No changesets added." - exit 0 - fi - - subjects=$(gh api "repos/$REPO/pulls/$PR_NUMBER/commits" --paginate \ - --jq '.[] | .commit.message | split("\n")[0]') - - failed=0 - while IFS= read -r changeset; do - first_line=$(gh api "repos/$REPO/contents/$changeset?ref=$HEAD_SHA" \ - -H "Accept: application/vnd.github.raw" \ - | tr -d '\r' \ - | awk 'NR == 1 && $0 == "---" { in_frontmatter = 1; next } - in_frontmatter { if ($0 == "---") in_frontmatter = 0; next } - NF { print; exit }') - - if ! grep -qxF -- "$first_line" <<< "$subjects"; then - echo "$changeset opens with a line that is not a commit subject in this PR:" - echo " $first_line" - failed=1 - fi - done <<< "$changesets" - - if [ "$failed" -eq 1 ]; then - echo "Commit subjects in this PR:" - sed 's/^/ /' <<< "$subjects" - echo "The first line of a changeset repeats a commit subject verbatim." - exit 1 - fi - - - uses: actions/checkout@v7 - with: - ref: ${{ github.event.pull_request.head.sha }} - sparse-checkout: | - .changeset/config.json - /package.json - sparse-checkout-cone-mode: false - - - name: Check that each fix/feat commit ships a changeset - env: - REPO: ${{ github.repository }} - PR_NUMBER: ${{ github.event.pull_request.number }} - run: | - # Private packages do not release. - unreleased=$(jq -r 'select(.private == true) | .name | sub("^@portabletext/"; "")' package.json) - - commits=$(gh api "repos/$REPO/pulls/$PR_NUMBER/commits" --paginate | jq -s 'add') - - changed_files() { - gh api "repos/$REPO/commits/$1" --paginate --jq '.files[] | "\(.status) \(.filename)"' - } - - ships_changeset() { - grep -E '^(added|modified|renamed) \.changeset/[^/]+\.md$' <<< "$1" | grep -qv ' \.changeset/README\.md$' - } - - offenders="" - count=$(jq length <<< "$commits") - for ((i = 0; i < count; i++)); do - sha=$(jq -r ".[$i].sha" <<< "$commits") - subject=$(jq -r ".[$i].commit.message | split(\"\n\")[0]" <<< "$commits") - author=$(jq -r ".[$i].author.login // \"\"" <<< "$commits") - - if ! [[ "$subject" =~ ^(fix|feat)(\(([^\)]*)\))?!?: ]]; then - continue - fi - scope=${BASH_REMATCH[3]} - if [ -n "$scope" ] && grep -qxF -- "$scope" <<< "$unreleased"; then - continue - fi - - files=$(changed_files "$sha") - if ships_changeset "$files"; then - continue - fi - - # A new package's 1.0.0 is published by hand, so the commit that - # introduces it has no changeset. - if grep -qE '^added package\.json$' <<< "$files"; then - continue - fi - - # Renovate commits get their changeset from a follow-up bot commit. - if [ "$author" = "renovate[bot]" ]; then - followed=0 - for ((j = i + 1; j < count; j++)); do - if [ "$(jq -r ".[$j].author.login // \"\"" <<< "$commits")" = "ecoscript[bot]" ] && - ships_changeset "$(changed_files "$(jq -r ".[$j].sha" <<< "$commits")")"; then - followed=1 - break - fi - done - if [ "$followed" -eq 1 ]; then - continue - fi - fi - - offenders+=" ${sha:0:7} $subject"$'\n' - done - - if [ -n "$offenders" ]; then - echo "These fix/feat commits ship no changeset:" - printf '%s' "$offenders" - echo "Each fix/feat commit ships its own changeset in the same commit." - echo "Retype a commit without a releasable change as refactor:, chore:, test: or docs:." - exit 1 - fi diff --git a/.github/workflows/check-format.yml b/.github/workflows/check-format.yml deleted file mode 100644 index 5a2b570..0000000 --- a/.github/workflows/check-format.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: check-format - -on: - # Build on pushes branches that have a PR (including drafts) - pull_request: - # Build on commits pushed to branches without a PR if it's in the allowlist - push: - branches: [main] - -jobs: - check-format: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v7 - - uses: pnpm/action-setup@v6 - - uses: actions/setup-node@v6 - with: - node-version: lts/* - - - name: Install project dependencies - run: pnpm install - - - name: Check format - run: pnpm check:format diff --git a/.github/workflows/check-knip.yml b/.github/workflows/check-knip.yml deleted file mode 100644 index f13e275..0000000 --- a/.github/workflows/check-knip.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: check-knip - -on: - pull_request: - push: - branches: [main] - -jobs: - check-knip: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v7 - - uses: pnpm/action-setup@v6 - - uses: actions/setup-node@v6 - with: - node-version: lts/* - - - name: Install project dependencies - run: pnpm install - - - name: Check for unused code and dependencies - run: pnpm check:knip diff --git a/.github/workflows/check-lint.yml b/.github/workflows/check-lint.yml deleted file mode 100644 index 8549701..0000000 --- a/.github/workflows/check-lint.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: check-lint - -on: - # Build on pushes branches that have a PR (including drafts) - pull_request: - # Build on commits pushed to branches without a PR if it's in the allowlist - push: - branches: [main] - -jobs: - check-lint: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v7 - - uses: pnpm/action-setup@v6 - - uses: actions/setup-node@v6 - with: - node-version: lts/* - - - name: Install project dependencies - run: pnpm install - - - name: Check lint - run: pnpm check:lint diff --git a/.github/workflows/check-types.yml b/.github/workflows/check-types.yml deleted file mode 100644 index 67fdfec..0000000 --- a/.github/workflows/check-types.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: check-types - -on: - # Build on pushes branches that have a PR (including drafts) - pull_request: - # Build on commits pushed to branches without a PR if it's in the allowlist - push: - branches: [main] - -jobs: - check-types: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v7 - - uses: pnpm/action-setup@v6 - - uses: actions/setup-node@v6 - with: - node-version: lts/* - - - name: Install project dependencies - run: pnpm install - - - name: check:types - run: pnpm check:types diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 0000000..a7552aa --- /dev/null +++ b/.github/workflows/checks.yml @@ -0,0 +1,18 @@ +name: Checks + +on: + pull_request: + # `edited` covers base-branch retargets, which change the commit set + # without firing `synchronize`. + types: [opened, synchronize, reopened, edited] + push: + branches: [main] + +jobs: + checks: + # Base changes alter the commit set that needs checking. + if: github.event.action != 'edited' || github.event.changes.base + permissions: + contents: read + pull-requests: read + uses: portabletext/.github/.github/workflows/checks.yml@4cf8ce4545c55209143e2e1d23abaf781335568a From 3b5bc5654a3eeaddb1f2465b7965c07349d156c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Hamburger=20Gr=C3=B8ngaard?= Date: Wed, 11 Nov 2026 14:08:00 +0000 Subject: [PATCH 2/4] ci: pin shared checks to the fixed commit check --- .github/workflows/checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index a7552aa..284c9a1 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -15,4 +15,4 @@ jobs: permissions: contents: read pull-requests: read - uses: portabletext/.github/.github/workflows/checks.yml@4cf8ce4545c55209143e2e1d23abaf781335568a + uses: portabletext/.github/.github/workflows/checks.yml@dcedcfd4071dd55ad063156f267186473354d699 From a2ef229c4a97cc42bf0a5abf60cf66546c705db8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Hamburger=20Gr=C3=B8ngaard?= Date: Wed, 11 Nov 2026 14:46:31 +0000 Subject: [PATCH 3/4] ci: use shared checks from main --- .github/workflows/checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 284c9a1..27ce8d7 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -15,4 +15,4 @@ jobs: permissions: contents: read pull-requests: read - uses: portabletext/.github/.github/workflows/checks.yml@dcedcfd4071dd55ad063156f267186473354d699 + uses: portabletext/.github/.github/workflows/checks.yml@main From 7c213f4018a8cb3fe85def016f7843ccc9132f51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Hamburger=20Gr=C3=B8ngaard?= Date: Wed, 11 Nov 2026 14:57:00 +0000 Subject: [PATCH 4/4] ci: probe checks on edited (if) --- .probe-if | 1 + 1 file changed, 1 insertion(+) create mode 100644 .probe-if diff --git a/.probe-if b/.probe-if new file mode 100644 index 0000000..e5b0f69 --- /dev/null +++ b/.probe-if @@ -0,0 +1 @@ +probe if