Skip to content

Commit 365d372

Browse files
committed
feat: add changie validation to lint action
Fixes #56 Add changie validation job to lint action in `.github/workflows/lint.yml`. * **Add changie-validation job:** - Check for `.changes` directory and skip validation if not found. - Check for changie entry in `.changes/unreleased`. - Check for `no-changie-required` or `dependencies` label and skip validation if present. - Fail if no changie entry and no relevant label found, and post a comment on the pull request if validation fails. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/DelineaXPM/dsv-github-action/issues/56?shareId=XXXX-XXXX-XXXX-XXXX).
1 parent 058fc72 commit 365d372

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

.github/workflows/lint.yml

+56
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,59 @@ jobs:
1717
lint:
1818
uses: delineaxpm/github-workflows/.github/workflows/lint.yml@main
1919
secrets: inherit
20+
21+
changie-validation:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Check for .changes directory
25+
id: check_changes_dir
26+
run: |
27+
if [ ! -d ".changes" ]; then
28+
echo "No .changes directory found, skipping changie validation."
29+
exit 0
30+
fi
31+
32+
- name: Check for changie entry
33+
id: check_changie_entry
34+
run: |
35+
if [ -z "$(ls -A .changes/unreleased)" ]; then
36+
echo "No changie entry found."
37+
echo "::set-output name=changie_entry_exists::false"
38+
else
39+
echo "Changie entry found."
40+
echo "::set-output name=changie_entry_exists::true"
41+
fi
42+
43+
- name: Check for no-changie-required or dependencies label
44+
id: check_no_changie_label
45+
run: |
46+
labels=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
47+
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels")
48+
if echo "$labels" | grep -q "no-changie-required"; then
49+
echo "no-changie-required label found, skipping changie validation."
50+
exit 0
51+
fi
52+
if echo "$labels" | grep -q "dependencies"; then
53+
echo "dependencies label found, skipping changie validation."
54+
exit 0
55+
fi
56+
57+
- name: Fail if no changie entry and no-changie-required or dependencies label not present
58+
if: steps.check_changie_entry.outputs.changie_entry_exists == 'false'
59+
run: |
60+
echo "::error::A changie entry was not found and is required on pull requests unless bypassed."
61+
exit 1
62+
63+
- name: Post comment on pull request if validation fails
64+
if: failure()
65+
run: |
66+
comment="A changie entry was not found and is required on pull requests unless bypassed."
67+
comments_url=$(jq -r .pull_request.comments_url "$GITHUB_EVENT_PATH")
68+
existing_comments=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "$comments_url")
69+
if echo "$existing_comments" | grep -q "$comment"; then
70+
echo "Comment already exists, not posting again."
71+
else
72+
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
73+
-d "{\"body\": \"$comment\"}" \
74+
"$comments_url"
75+
fi

0 commit comments

Comments
 (0)