Skip to content

Commit

Permalink
update changelog action
Browse files Browse the repository at this point in the history
  • Loading branch information
SlayerAnsh committed May 22, 2024
1 parent d73640c commit 4ac37a3
Showing 1 changed file with 58 additions and 9 deletions.
67 changes: 58 additions & 9 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,67 @@
name: "Documentation"
name: Changelog and Version Bump Check
on:
push:
branches:
- development
- main
pull_request:
# The specific activity types are listed here to include "labeled" and "unlabeled"
# (which are not included by default for the "pull_request" trigger).
# This is needed to allow skipping enforcement of the changelog in PRs with specific labels,
# as defined in the (optional) "skipLabels" property.
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]
branches:
- development
- main

jobs:
# Enforces the update of a changelog file on every pull request
changelog:
check-changelog-version:
runs-on: ubuntu-latest
steps:
- uses: dangoslen/changelog-enforcer@v3
- name: Checkout repository
uses: actions/checkout@v2

- name: Get list of changed files
id: changed-files
run: |
echo "::set-output name=files::$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | tr '\n' ' ')"
- name: Determine changed packages
id: determine-packages
run: |
CHANGED_FILES="${{ steps.changed-files.outputs.files }}"
CHANGED_PACKAGES=()
for file in $CHANGED_FILES; do
if [[ "$file" == packages/*/src/* ]]; then
package=$(echo $file | cut -d'/' -f2)
if [[ ! " ${CHANGED_PACKAGES[@]} " =~ " ${package} " ]]; then
CHANGED_PACKAGES+=($package)
fi
fi
done
echo "Changed packages: ${CHANGED_PACKAGES[@]}"
echo "::set-output name=packages::$(IFS=,; echo "${CHANGED_PACKAGES[*]}")"
- name: Check changelog and version bump in each changed package
run: |
CHANGED_PACKAGES="${{ steps.determine-packages.outputs.packages }}"
IFS=',' read -r -a packages <<< "$CHANGED_PACKAGES"
for package in "${packages[@]}"; do
echo "Checking package: packages/$package"
if [ ! -f "packages/$package/CHANGELOG.md" ]; then
echo "Warning: CHANGELOG.md not found in packages/$package. Skipping changelog check."
continue
fi
if [ -z "$(grep -E "^## \[[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+\.[0-9]+)?\]" packages/$package/CHANGELOG.md)" ]; then
echo "Error: No version bump found in packages/$package/CHANGELOG.md"
exit 1
fi
current_version=$(cat packages/$package/package.json | jq -r .version)
changelog_version=$(grep -E "^## \[[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+\.[0-9]+)?\]" packages/$package/CHANGELOG.md | head -n 1 | sed -E "s/^## \[([0-9]+\.[0-9]+\.[0-9]+(-[a-z]+\.[0-9]+)?)\].*$/\1/")
if [ "$current_version" != "$changelog_version" ]; then
echo "Error: Version mismatch in packages/$package (package.json: $current_version, CHANGELOG.md: $changelog_version)"
exit 1
fi
done
- name: Success message
if: success()
run: echo "Changelog and version bump check passed for all changed packages."

0 comments on commit 4ac37a3

Please sign in to comment.