Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 0 additions & 19 deletions .github/actions/check-changelog/action.yml

This file was deleted.

37 changes: 0 additions & 37 deletions .github/actions/check-changelog/entrypoint.sh

This file was deleted.

13 changes: 0 additions & 13 deletions .github/actions/detect-package-changes/action.yml

This file was deleted.

26 changes: 0 additions & 26 deletions .github/actions/detect-package-changes/entrypoint.sh

This file was deleted.

44 changes: 9 additions & 35 deletions .github/workflows/changelog.yml
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
Comment thread
weronikaolejniczak marked this conversation as resolved.
Outdated
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 }}
119 changes: 119 additions & 0 deletions scripts/check_changelogs.sh
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
Comment thread
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>/`
Comment thread
weronikaolejniczak marked this conversation as resolved.
Outdated
for pkg_dir in packages/*/; do
Comment thread
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
Comment thread
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