diff --git a/.github/actions/check-changelog/action.yml b/.github/actions/check-changelog/action.yml index bc8df51f45e..732cf2804bf 100644 --- a/.github/actions/check-changelog/action.yml +++ b/.github/actions/check-changelog/action.yml @@ -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: @@ -12,4 +15,5 @@ runs: run: .github/actions/check-changelog/entrypoint.sh env: PR_NUMBER: ${{ inputs.pr-number }} + PACKAGE_PATH: ${{ inputs.package-path }} diff --git a/.github/actions/check-changelog/entrypoint.sh b/.github/actions/check-changelog/entrypoint.sh index be4c0c20f9b..91ccb9cd1ad 100755 --- a/.github/actions/check-changelog/entrypoint.sh +++ b/.github/actions/check-changelog/entrypoint.sh @@ -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 diff --git a/.github/actions/detect-package-changes/action.yml b/.github/actions/detect-package-changes/action.yml new file mode 100644 index 00000000000..d2932ccd60a --- /dev/null +++ b/.github/actions/detect-package-changes/action.yml @@ -0,0 +1,13 @@ +name: Detect package changes +description: 'Detects which public packages have changed based on git diff' +outputs: + changed-packages: + description: 'A JSON array of changed public package names' + value: ${{ steps.changes.outputs.changed-packages }} +runs: + using: 'composite' + steps: + - name: Detect package changes + id: changes + shell: bash + run: ${{ github.action_path }}/entrypoint.sh diff --git a/.github/actions/detect-package-changes/entrypoint.sh b/.github/actions/detect-package-changes/entrypoint.sh new file mode 100755 index 00000000000..93a1597bfc8 --- /dev/null +++ b/.github/actions/detect-package-changes/entrypoint.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Exit on error +set -e + +# 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 diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 839b86ac165..a0a094e3cc6 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -5,12 +5,32 @@ 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 + 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: - 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 }}