-
Notifications
You must be signed in to change notification settings - Fork 1
67 lines (58 loc) · 2.62 KB
/
changelog.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
name: Changelog and Version Bump Check
on:
pull_request:
branches:
- main
- development
jobs:
check-changelog-version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get list of changed files
id: changed-files
run: |
git fetch origin ${{ github.event.pull_request.base.ref }}
echo "::set-output name=files::$(git diff --name-only origin/${{ github.event.pull_request.base.ref }} ${{ 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."