Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add changie validation to lint action #57

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
56 changes: 56 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check failure on line 1 in .github/workflows/lint.yml

View workflow job for this annotation

GitHub Actions / Trunk Check

checkov(CKV_GHA_3)

[new] Suspicious use of curl with secrets
name: lint
on:
push:
Expand All @@ -17,3 +17,59 @@
lint:
uses: delineaxpm/github-workflows/.github/workflows/lint.yml@main
secrets: inherit

changie-validation:
runs-on: ubuntu-latest
steps:
- name: Check for .changes directory
id: check_changes_dir
run: |
if [ ! -d ".changes" ]; then
echo "No .changes directory found, skipping changie validation."
exit 0
fi

- name: Check for changie entry
id: check_changie_entry
run: |

Check failure on line 34 in .github/workflows/lint.yml

View workflow job for this annotation

GitHub Actions / Trunk Check

actionlint(deprecated-commands)

[new] workflow command "set-output" was deprecated. use `echo "{name}={value}" >> $GITHUB_OUTPUT` instead: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions
if [ -z "$(ls -A .changes/unreleased)" ]; then
echo "No changie entry found."
echo "::set-output name=changie_entry_exists::false"
else
echo "Changie entry found."
echo "::set-output name=changie_entry_exists::true"
fi

- name: Check for no-changie-required or dependencies label

Check failure on line 43 in .github/workflows/lint.yml

View workflow job for this annotation

GitHub Actions / Trunk Check

checkov(CKV_GHA_3)

[new] Suspicious use of curl with secrets
id: check_no_changie_label
run: |
labels=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels")
if echo "$labels" | grep -q "no-changie-required"; then
echo "no-changie-required label found, skipping changie validation."
exit 0
fi
if echo "$labels" | grep -q "dependencies"; then
echo "dependencies label found, skipping changie validation."
exit 0
fi

- name: Fail if no changie entry and no-changie-required or dependencies label not present
if: steps.check_changie_entry.outputs.changie_entry_exists == 'false'
run: |
echo "::error::A changie entry was not found and is required on pull requests unless bypassed."
exit 1

- name: Post comment on pull request if validation fails
if: failure()
run: |
comment="A changie entry was not found and is required on pull requests unless bypassed."
comments_url=$(jq -r .pull_request.comments_url "$GITHUB_EVENT_PATH")
existing_comments=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "$comments_url")
if echo "$existing_comments" | grep -q "$comment"; then
echo "Comment already exists, not posting again."
else
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-d "{\"body\": \"$comment\"}" \
"$comments_url"
fi
Loading