Skip to content
Open
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
4 changes: 4 additions & 0 deletions .github/actions/check-changelog/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ inputs:
pr-number:
required: true
description: PR number used as the changelog filename
package-path:
required: false
description: The base path of the package to check for a changelog. If not provided, it will check all packages.
runs:
using: 'composite'
steps:
Expand All @@ -12,4 +15,5 @@ runs:
run: .github/actions/check-changelog/entrypoint.sh
env:
PR_NUMBER: ${{ inputs.pr-number }}
PACKAGE_PATH: ${{ inputs.package-path }}

33 changes: 24 additions & 9 deletions .github/actions/check-changelog/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,32 @@
# Exit on error
set -e

# The PR number provided as input
# The PR number and package path provided as input
PR_NUMBER="${PR_NUMBER}"
PACKAGE_PATH="${PACKAGE_PATH}"

# Search for the changelog file across all packages
changelog_files=$(find packages/*/changelogs/upcoming/ -type f -name "${PR_NUMBER}.md")
# Search for the changelog file
if [ -n "$PACKAGE_PATH" ]; then
# Check specific package
changelog_files=$(find "${PACKAGE_PATH}/changelogs/upcoming/" -type f -name "${PR_NUMBER}.md" 2>/dev/null || true)
package_name=$(basename "$PACKAGE_PATH")

# If no changelog file is found, fail the step with an error message
if [ -z "$changelog_files" ]; then
echo "❌ Changelog file for PR #${PR_NUMBER} is missing."
echo "You need to add a changelog to this PR before it can be merged. See https://github.com/elastic/eui/blob/main/wiki/contributing-to-eui/documenting/changelogs.md."
exit 1
if [ -z "$changelog_files" ]; then
echo "❌ Changelog file for PR #${PR_NUMBER} is missing in package '${package_name}'."
echo "You need to add a changelog to this PR before it can be merged. See https://github.com/elastic/eui/blob/main/wiki/contributing-to-eui/documenting/changelogs.md."
exit 1
else
echo "✅ Changelog file for PR #${PR_NUMBER} found in package '${package_name}': $changelog_files"
fi
else
echo "✅ Changelog file for PR #${PR_NUMBER} found: $changelog_files"
# Search for the changelog file across all packages
changelog_files=$(find packages/*/changelogs/upcoming/ -type f -name "${PR_NUMBER}.md")

if [ -z "$changelog_files" ]; then
echo "❌ Changelog file for PR #${PR_NUMBER} is missing."
echo "You need to add a changelog to this PR before it can be merged. See https://github.com/elastic/eui/blob/main/wiki/contributing-to-eui/documenting/changelogs.md."
exit 1
else
echo "✅ Changelog file for PR #${PR_NUMBER} found: $changelog_files"
fi
fi
53 changes: 47 additions & 6 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,53 @@ on:
branches: [main]

jobs:
# Enforces the update of a changelog file on every pull request
# Check for changes in all public packages, needed in the `changelog` job
detect-changes:
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
run: |
# Get the list of changed files
changed_files=$(git diff --name-only origin/main...HEAD)

# Find all public packages and check for changes
public_packages=()
for dir in packages/*/; do
if [ -f "${dir}package.json" ] && ! grep -q '"private": true' "${dir}package.json"; then
package_name=$(basename "$dir")
if echo "$changed_files" | grep -q "^packages/$package_name/"; then
public_packages+=("\"$package_name\"")
fi
fi
done

# Output a JSON array of changed package names
if [ ${#public_packages[@]} -gt 0 ]; then
changed_list=$(IFS=,; echo "[${public_packages[*]}]")
echo "changed-packages=$changed_list" >> $GITHUB_OUTPUT
else
echo "changed-packages=[]" >> $GITHUB_OUTPUT
fi

# Enforces the update of a changelog file on every pull request for all public packages
# unless the PR contains the `skip-changelog` label
changelog:
if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip-changelog') }}
needs: detect-changes
if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip-changelog') && fromJson(needs.detect-changes.outputs.changed-packages)[0] }}
runs-on: ubuntu-latest
strategy:
matrix:
package: ${{ fromJson(needs.detect-changes.outputs.changed-packages) }}
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/check-changelog
with:
pr-number: ${{ github.event.pull_request.number }}
- uses: actions/checkout@v2
- name: Check changelog for ${{ matrix.package }}
uses: ./.github/actions/check-changelog
with:
pr-number: ${{ github.event.pull_request.number }}
package-path: packages/${{ matrix.package }}