-
Notifications
You must be signed in to change notification settings - Fork 886
[Changelogs] Add check_changelogs bash script #9249
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
Merged
weronikaolejniczak
merged 13 commits into
elastic:main
from
weronikaolejniczak:feat/update-changelog-check
Dec 3, 2025
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0d481fb
chore: add check changelogs bash script
weronikaolejniczak 7cb87f9
chore: remove summary, too verbose
weronikaolejniczak d6c1d0f
chore: add comma to impacted packages for clarity
weronikaolejniczak e558aed
chore: add a list of changed files
weronikaolejniczak 99df676
Update scripts/check_changelogs.sh
weronikaolejniczak 18caf09
Merge branch 'main' into feat/update-changelog-check
weronikaolejniczak 14e9bb8
chore: bump to actions/checkout@v5
weronikaolejniczak 7153598
chore: use ubuntu-slim
weronikaolejniczak a4664ff
chore: use yarn workspaces to simplify the script
weronikaolejniczak 352b966
chore: compare HEAD to parent only
weronikaolejniczak 52b3a41
chore: use fetch depth 2
weronikaolejniczak 94fba70
Merge branch 'main' into feat/update-changelog-check
weronikaolejniczak 97167c5
Merge branch 'main' into feat/update-changelog-check
weronikaolejniczak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,46 +1,20 @@ | ||
| name: "Changelog required" | ||
| name: 'Changelog required' | ||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled] | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| # Check for changes in all public packages, needed in the `changelog` job | ||
| detect-changes: | ||
| changelog: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| changed-packages: ${{ steps.changes.outputs.changed-packages }} | ||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Detect package changes | ||
| id: changes | ||
| uses: ./.github/actions/detect-package-changes | ||
|
|
||
| # Enforces the update of a changelog file on every pull request for all public packages | ||
| # unless the PR contains the `skip-changelog` label | ||
| changelog-checks: | ||
| needs: detect-changes | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| package: ${{ fromJson(needs.detect-changes.outputs.changed-packages) }} | ||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| - name: Check changelog for ${{ matrix.package }} | ||
| # TODO specific "package" labels could be checked here? | ||
| if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip-changelog') }} | ||
| uses: ./.github/actions/check-changelog | ||
| with: | ||
| pr-number: ${{ github.event.pull_request.number }} | ||
| package-path: packages/${{ matrix.package }} | ||
|
|
||
| # This job will always run and succeed, ensuring the overall check completes. | ||
| changelog: | ||
| needs: changelog-checks | ||
| runs-on: ubuntu-latest | ||
| if: always() | ||
| steps: | ||
| - name: Finish changelog checks | ||
| run: echo "Changelog checks finished." | ||
| - name: Check changelogs | ||
| run: | | ||
| ./scripts/check_changelogs.sh \ | ||
| "${{ github.event.pull_request.number }}" \ | ||
| "${{ join(github.event.pull_request.labels.*.name, '|') }}" | ||
| env: | ||
| GITHUB_BASE_REF: ${{ github.base_ref }} | ||
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,119 @@ | ||
| #!/bin/bash | ||
|
|
||
| # This script checks that a changelog entry exists for every changed public package in a PR. | ||
| # | ||
| # Skip logic: | ||
| # | ||
| # - if a package is private, changelog check for that specific package is skipped, | ||
| # - if "skip-changelog" label is present, all changelog checks are skipped, | ||
| # - if "skip-changelog-<package-name>" is present, changelog check for that specific package is skipped. | ||
|
|
||
| set -e | ||
|
|
||
| # The Pull Request ID | ||
| PR_NUMBER="$1" | ||
| # Pipe-separated list of labels applied to the PR | ||
| LABELS="$2" | ||
| # Base ref to compare against (defaults to `origin/main`) | ||
| BASE_REF="origin/${GITHUB_BASE_REF:-main}" | ||
|
|
||
| if [ -z "$PR_NUMBER" ]; then | ||
| echo "Error: PR_NUMBER argument is missing." | ||
| echo "Usage: $0 <pr_number> [labels]" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check if a label exists in the list | ||
| has_label() { | ||
| local label="$1" | ||
| local labels_piped="|$LABELS|" | ||
| [[ "$labels_piped" == *"|$label|"* ]] | ||
| } | ||
|
|
||
| # Check for global skip | ||
| if has_label "skip-changelog"; then | ||
| echo "⏩ \`skip-changelog\` label detected. Skipping all changelog checks." | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Ensure we have `origin/main` for diffing | ||
| # This check prevents "ambiguous argument 'origin/main...HEAD'" errors | ||
| # if shallow clone missed the ref | ||
| if ! git rev-parse --verify "$BASE_REF" >/dev/null 2>&1; then | ||
| echo "⚠️ \`$BASE_REF\` reference not found. Attempting to fetch..." | ||
| git fetch origin "${GITHUB_BASE_REF:-main}:$BASE_REF" --depth=1 || echo "Warning: Fetch failed, git diff might fail." | ||
| fi | ||
|
weronikaolejniczak marked this conversation as resolved.
Outdated
|
||
|
|
||
| echo "🔍 Detecting changed public packages..." | ||
|
|
||
| # Get list of changed files | ||
| CHANGED_FILES=$(git diff --name-only "$BASE_REF...HEAD") | ||
|
|
||
| CHANGED_PACKAGES=() | ||
| MISSING_CHANGELOGS=() | ||
|
|
||
| # Iterate over all directories in `packages/` | ||
| # Assumption: `packages/<package_name>/` | ||
|
weronikaolejniczak marked this conversation as resolved.
Outdated
|
||
| for pkg_dir in packages/*/; do | ||
|
weronikaolejniczak marked this conversation as resolved.
Outdated
|
||
| [ -d "$pkg_dir" ] || continue | ||
|
|
||
| # Remove trailing slash | ||
| pkg_path="${pkg_dir%/}" | ||
| pkg_name=$(basename "$pkg_path") | ||
| package_json="$pkg_path/package.json" | ||
|
|
||
| # Check if `package.json` exists | ||
| if [ ! -f "$package_json" ]; then | ||
| continue | ||
| fi | ||
|
|
||
| # Skip private packages | ||
| is_private=$(node -p "try { require('./$package_json').private } catch(e) { false }" 2>/dev/null) | ||
| if [ "$is_private" == "true" ]; then | ||
| continue | ||
| fi | ||
|
weronikaolejniczak marked this conversation as resolved.
Outdated
|
||
|
|
||
| # We look for "packages/<pkg_name>/" prefix in the changed files list | ||
| if echo "$CHANGED_FILES" | grep -Fq "packages/$pkg_name/"; then | ||
| CHANGED_PACKAGES+=("$pkg_name") | ||
| fi | ||
| done | ||
|
|
||
| if [ ${#CHANGED_PACKAGES[@]} -eq 0 ]; then | ||
| echo "✅ No public package changes detected." | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "Impacted packages: ${CHANGED_PACKAGES[*]}" | ||
|
|
||
| for pkg_name in "${CHANGED_PACKAGES[@]}"; do | ||
| # Check for package-specific skip label | ||
| if has_label "skip-changelog-$pkg_name"; then | ||
| echo "⏩ Skipping changelog check for \`$pkg_name\` (label \`skip-changelog-$pkg_name\` present)." | ||
| continue | ||
| fi | ||
|
|
||
| CHANGELOG_FILE="packages/$pkg_name/changelogs/upcoming/$PR_NUMBER.md" | ||
|
|
||
| if [ -f "$CHANGELOG_FILE" ]; then | ||
| echo "✅ \`$pkg_name\`: Changelog entry found ($CHANGELOG_FILE)." | ||
| else | ||
| echo "🚫 \`$pkg_name\`: Changelog entry missing." | ||
| MISSING_CHANGELOGS+=("$pkg_name") | ||
| fi | ||
| done | ||
|
|
||
| # Report failures | ||
| if [ ${#MISSING_CHANGELOGS[@]} -gt 0 ]; then | ||
| echo "🚫 The following packages are modified but miss a changelog entry:" | ||
| for pkg in "${MISSING_CHANGELOGS[@]}"; do | ||
| echo " - $pkg" | ||
| done | ||
| echo "Please add an \`.md\` file named \`${PR_NUMBER}.md\` to the \`changelogs/upcoming/\` directory of the respective packages." | ||
| echo "Example: \`packages/${MISSING_CHANGELOGS[0]}/changelogs/upcoming/${PR_NUMBER}.md\`" | ||
| echo "You can read more about changelogs here: https://github.com/elastic/eui/blob/main/wiki/contributing-to-eui/documenting/changelogs.md" | ||
| exit 1 | ||
| else | ||
| echo "🎉 All changelog requirements satisfied." | ||
| exit 0 | ||
| fi | ||
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.