-
Notifications
You must be signed in to change notification settings - Fork 7
Reconcile enterprise/cloud doc divergence + add bump-last-updated tooling #1547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
justinegeffen
wants to merge
22
commits into
master
Choose a base branch
from
enterprise-cloud-divergence-audit
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
bcc7cf6
Reconcile enterprise/cloud doc divergence + add bump-last-updated too…
justinegeffen 08ba49d
[automated] Fix code formatting
197a870
Merge branch 'master' into enterprise-cloud-divergence-audit
justinegeffen 5555c16
Update platform-enterprise_docs/pipelines/versioning.md
justinegeffen 4c77658
Update platform-enterprise_docs/secrets/overview.md
justinegeffen a22a275
Merge branch 'master' into enterprise-cloud-divergence-audit
justinegeffen 0c4aa11
[automated] Fix code formatting
996a93b
Switch bump-last-updated to checker pattern with invocable fix command
justinegeffen 3c19717
Merge branch 'master' into enterprise-cloud-divergence-audit
justinegeffen b222e26
[automated] Fix code formatting
ebc1b01
Merge branch 'master' into enterprise-cloud-divergence-audit
justinegeffen 893eb61
Merge branch 'master' into enterprise-cloud-divergence-audit
justinegeffen 339c264
[automated] Fix code formatting
58e9989
Merge branch 'master' into enterprise-cloud-divergence-audit
justinegeffen 3c09ebb
[automated] Fix code formatting
995eb4e
Merge branch 'master' into enterprise-cloud-divergence-audit
justinegeffen 0d1dbc0
[automated] Fix code formatting
6b624b1
Merge branch 'master' into enterprise-cloud-divergence-audit
justinegeffen f1d55b9
[automated] Fix code formatting
770b0c0
Merge branch 'master' into enterprise-cloud-divergence-audit
justinegeffen c43dc31
[automated] Fix code formatting
fbb3492
[automated] Fix code formatting
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| #!/usr/bin/env python3 | ||
| """Check (or bump) frontmatter `last updated:` on changed Markdown files. | ||
|
|
||
| Two modes: | ||
|
|
||
| - **Check mode** (`--check`): used by the `bump-last-updated` pre-commit hook. | ||
| Reads each file path passed in, reports any whose `last updated:` is not | ||
| today (or that lack the field entirely), prints the exact command to fix, | ||
| and exits 1. No files modified. | ||
| - **Fix mode** (default): rewrites the file in place. For each file: | ||
| - If frontmatter has `last updated:`, set its value to today (YYYY-MM-DD). | ||
| - If frontmatter has `date created:` but no `last updated:`, insert | ||
| `last updated:` immediately after `date created:` with today's date. | ||
| Files without `date created:` are skipped (changelog entries, partials). | ||
| Exits non-zero if any file was modified, zero otherwise — per the standard | ||
| pre-commit fixer convention. | ||
|
|
||
| Why two modes: hook runs in check mode so the contributor sees an explicit | ||
| failure with an invocable command (matches the `check-doc-tags` pattern in | ||
| this repo). The CI workflow runs the script directly in fix mode and commits | ||
| the bump back, so fork contributors and skipped local hooks still get a | ||
| correct `last updated:` on merge. | ||
| """ | ||
| from __future__ import annotations | ||
|
|
||
| import re | ||
| import sys | ||
| from datetime import date | ||
| from pathlib import Path | ||
|
|
||
| TODAY = date.today().strftime("%Y-%m-%d") | ||
|
|
||
| FRONTMATTER_RE = re.compile(r"^---[ \t]*\n(.*?\n)---[ \t]*\n", re.DOTALL) | ||
| LAST_UPDATED_RE = re.compile(r"^(last updated:\s*).*$", re.MULTILINE) | ||
| DATE_CREATED_LINE_RE = re.compile(r"^date created:\s*") | ||
|
|
||
|
|
||
| def compute_new_frontmatter(fm: str) -> str | None: | ||
| """Return the new frontmatter body if a bump is needed, else None. | ||
|
|
||
| Returns the same string the fixer would write so check mode and fix mode | ||
| stay in lockstep — no chance of one saying "stale" while the other says | ||
| "no-op". | ||
| """ | ||
| if not any(DATE_CREATED_LINE_RE.match(line) for line in fm.splitlines()): | ||
| return None # file doesn't follow the convention; skip | ||
|
|
||
| if LAST_UPDATED_RE.search(fm): | ||
| new_fm = LAST_UPDATED_RE.sub(rf'\1"{TODAY}"', fm, count=1) | ||
| else: | ||
| # Insert `last updated:` right after the `date created:` line. | ||
| out: list[str] = [] | ||
| inserted = False | ||
| for line in fm.splitlines(): | ||
| out.append(line) | ||
| if not inserted and DATE_CREATED_LINE_RE.match(line): | ||
| out.append(f'last updated: "{TODAY}"') | ||
| inserted = True | ||
| new_fm = "\n".join(out) + "\n" | ||
|
|
||
| return new_fm if new_fm != fm else None | ||
|
|
||
|
|
||
| def needs_bump(path: Path) -> bool: | ||
| """True if `last updated:` is stale or missing on a file that has `date created:`.""" | ||
| try: | ||
| content = path.read_text(encoding="utf-8") | ||
| except (OSError, UnicodeDecodeError): | ||
| return False | ||
| m = FRONTMATTER_RE.match(content) | ||
| if not m: | ||
| return False | ||
| return compute_new_frontmatter(m.group(1)) is not None | ||
|
|
||
|
|
||
| def apply_bump(path: Path) -> bool: | ||
| """Write the bump. Return True if file was modified.""" | ||
| try: | ||
| content = path.read_text(encoding="utf-8") | ||
| except (OSError, UnicodeDecodeError): | ||
| return False | ||
| m = FRONTMATTER_RE.match(content) | ||
| if not m: | ||
| return False | ||
| new_fm = compute_new_frontmatter(m.group(1)) | ||
| if new_fm is None: | ||
| return False | ||
| rest = content[m.end():] | ||
| path.write_text(f"---\n{new_fm}---\n{rest}", encoding="utf-8") | ||
| return True | ||
|
|
||
|
|
||
| def main(argv: list[str]) -> int: | ||
| check_only = "--check" in argv | ||
| paths = [ | ||
| Path(a) for a in argv | ||
| if a != "--check" and Path(a).is_file() and Path(a).suffix in (".md", ".mdx") | ||
| ] | ||
|
|
||
| if check_only: | ||
| stale = [p for p in paths if needs_bump(p)] | ||
| if not stale: | ||
| return 0 | ||
| print(f"ERROR: {len(stale)} file(s) have stale `last updated:` (expected {TODAY}):") | ||
| for p in stale: | ||
| print(f" {p}") | ||
| print() | ||
| print("Fix locally by running:") | ||
| print(f" python3 .github/scripts/bump-last-updated.py {' '.join(str(p) for p in stale)}") | ||
| print() | ||
| print("Or comment `fix formatting` on your PR to let CI bump these for you.") | ||
| return 1 | ||
|
|
||
| modified = [p for p in paths if apply_bump(p)] | ||
| if not modified: | ||
| return 0 | ||
| print(f"Bumped `last updated:` to {TODAY} in:") | ||
| for p in modified: | ||
| print(f" {p}") | ||
| return 1 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main(sys.argv[1:])) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,26 @@ | ||
| name: Run pre-commit when requested via comment | ||
| name: Run pre-commit on PRs or via comment | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should add an |
||
| on: | ||
| issue_comment: | ||
| types: [created] | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
|
|
||
| jobs: | ||
| pre_commit_fix: | ||
| runs-on: ubuntu-latest | ||
| # Only run if comment is on a PR with the main repo, and if it contains the magic keywords | ||
| # Run when: | ||
| # - An "fix formatting" comment is posted on any PR (works for fork PRs too). | ||
| # - A PR is opened/updated from a same-repo branch (skip forks — they have | ||
| # read-only tokens that can't push; fork contributors can still trigger | ||
| # the fix via the comment route above). | ||
| if: > | ||
| github.event.issue.pull_request && | ||
| startsWith(github.event.comment.body, 'fix formatting') | ||
| (github.event_name == 'issue_comment' && | ||
| github.event.issue.pull_request && | ||
| startsWith(github.event.comment.body, 'fix formatting')) | ||
| || | ||
| (github.event_name == 'pull_request' && | ||
| github.event.pull_request.head.repo.full_name == github.repository && | ||
| github.event.pull_request.user.login != 'seqera-docs-bot') | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
@@ -18,17 +29,50 @@ jobs: | |
| steps: | ||
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # ratchet:actions/checkout@v6.0.3 | ||
|
|
||
| # Action runs on the issue comment, so we don't get the PR by default. | ||
| # Use the GitHub CLI to check out the PR. | ||
| - name: Checkout Pull Request | ||
| # issue_comment events don't give us the PR ref, so use gh CLI to switch. | ||
| - name: Checkout PR branch (comment trigger) | ||
| if: github.event_name == 'issue_comment' | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: gh pr checkout ${{ github.event.issue.number }} | ||
|
|
||
| # pull_request events already supply head ref — use it directly so the | ||
| # subsequent push lands on the contributor's branch. | ||
| - name: Checkout PR branch (pull_request trigger) | ||
| if: github.event_name == 'pull_request' | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # ratchet:actions/checkout@v6.0.2 | ||
| with: | ||
| ref: ${{ github.event.pull_request.head.ref }} | ||
| fetch-depth: 0 | ||
|
|
||
| - uses: j178/prek-action@bdca6f102f98e2b4c7029491a53dfd366469e33d # ratchet:j178/prek-action@v2.0.4 | ||
| id: pre-commit | ||
| continue-on-error: true | ||
|
|
||
| # bump-last-updated is a checker locally (fails with an invocable | ||
| # command, doesn't modify files). For PR / comment-triggered CI runs we | ||
| # explicitly invoke the script in fix mode against the PR's changed | ||
| # files, so fork contributors and skipped local hooks still get a | ||
| # current `last updated:` on merge. | ||
| - name: Bump stale last_updated dates | ||
| run: | | ||
| set -e | ||
| BASE_REF="${{ github.event.pull_request.base.ref || github.event.repository.default_branch }}" | ||
| git fetch --no-tags --depth=1 origin "$BASE_REF" || true | ||
| BASE_SHA=$(git merge-base "origin/$BASE_REF" HEAD 2>/dev/null || git rev-parse "origin/$BASE_REF" 2>/dev/null || echo "") | ||
| if [ -z "$BASE_SHA" ]; then | ||
| echo "No base ref to diff against; skipping." | ||
| exit 0 | ||
| fi | ||
| CHANGED=$(git diff --name-only --diff-filter=ACMR "$BASE_SHA" HEAD -- '*.md' '*.mdx' \ | ||
| | grep -vE '^(platform-enterprise_versioned_docs|changelog)/' || true) | ||
| if [ -z "$CHANGED" ]; then | ||
| echo "No changed .md/.mdx files; nothing to bump." | ||
| exit 0 | ||
| fi | ||
| # shellcheck disable=SC2086 | ||
| python3 .github/scripts/bump-last-updated.py $CHANGED || true | ||
|
|
||
| - name: Check if any files changed | ||
| run: | | ||
| git diff --exit-code || echo "changed=YES" >> $GITHUB_ENV | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.