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(lint): add changie validation job to lint action #83

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f3f4d34
Add changie validation job to lint action
sheldonhull Aug 12, 2024
a6495b6
Add GH_TOKEN environment variable to changie-validation job
sheldonhull Aug 12, 2024
32e4020
Add `changie-validation` job to lint workflow
sheldonhull Aug 13, 2024
b664e26
Update `lint.yml` to fix environment variable mapping for `GH_TOKEN`
sheldonhull Aug 13, 2024
c3102fa
Add checkout step to changie-validation job in lint workflow
sheldonhull Aug 13, 2024
8821f7c
sheldonhull Aug 13, 2024
6ad0a71
sheldonhull Aug 13, 2024
7595945
sheldonhull Aug 13, 2024
195299c
sheldonhull Aug 13, 2024
206aa3e
sheldonhull Aug 13, 2024
e1f34c3
sheldonhull Aug 13, 2024
3d76c9b
sheldonhull Aug 13, 2024
1b44e49
sheldonhull Aug 13, 2024
5430d08
sheldonhull Aug 13, 2024
2600bd8
sheldonhull Aug 13, 2024
c1529b3
sheldonhull Aug 13, 2024
503343b
sheldonhull Aug 13, 2024
c90b3e5
sheldonhull Aug 13, 2024
9fa7a93
Add changie-validation job to lint workflow
sheldonhull Aug 13, 2024
e49b306
Add changie validation job to lint action
sheldonhull Aug 13, 2024
1b50ffb
sheldonhull Aug 13, 2024
c8d126d
sheldonhull Aug 13, 2024
a3a61e4
sheldonhull Aug 13, 2024
f9bcac2
sheldonhull Aug 13, 2024
3aebd24
Add changie-validation job to lint workflow
sheldonhull Aug 13, 2024
e7e416b
sheldonhull Aug 13, 2024
eb662bd
sheldonhull Aug 13, 2024
28066e4
sheldonhull Aug 13, 2024
eb3caf4
sheldonhull Aug 13, 2024
f240114
sheldonhull Aug 13, 2024
a0b42e1
sheldonhull Aug 13, 2024
56343d2
sheldonhull Aug 13, 2024
ae30e3f
sheldonhull Aug 13, 2024
90db738
sheldonhull Aug 13, 2024
6595eed
sheldonhull Aug 13, 2024
24b85e1
sheldonhull Aug 13, 2024
910fde7
sheldonhull Aug 13, 2024
5b430be
sheldonhull Aug 13, 2024
d33c302
sheldonhull Aug 13, 2024
f55f0d8
sheldonhull Aug 13, 2024
b923d16
sheldonhull Aug 13, 2024
781b052
sheldonhull Aug 13, 2024
9c08d19
tweak to echo and add more context detail
sheldonhull Aug 13, 2024
1d36869
sheldonhull Aug 13, 2024
fe51349
sheldonhull Aug 13, 2024
85e29f8
make it work
sheldonhull Aug 13, 2024
96d70c9
sheldonhull Aug 13, 2024
78a2853
sheldonhull Aug 13, 2024
e4fc0b4
remove readme changes
sheldonhull Aug 13, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: new-product-feature
body: Improve linting with additional job that validates changie entry exists when it should be included. Certain exclusions are added such as labels for `dependencies` by Renovate, and `no-changie-required` label for exceptions. This will use PR comment type so automatic changes required will show up.
time: 2024-08-13T01:35:11.383368408Z
94 changes: 92 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
contents: read # For repo checkout
steps:
- name: checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
uses: actions/checkout@v4
- name: set-aqua-policy-if-file-exists
run: |
if [ -f aqua-policy.yaml ]; then
if [[ -f aqua-policy.yaml ]]; then
echo "AQUA_POLICY_CONFIG=${GITHUB_WORKSPACE}/aqua-policy.yaml:${AQUA_POLICY_CONFIG}" >> $GITHUB_ENV
else
echo "👉 No aqua-policy.yaml file found, skipping setting AQUA_POLICY_CONFIG"
Expand All @@ -44,3 +44,93 @@ jobs:
uses: trunk-io/trunk-action@86b68ffae610a05105e90b1f52ad8c549ef482c2 # v1.1.16
with:
arguments: --github-annotate-new-only=true

changie-validation:
name: changie-validation
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
checks: write
env:
GH_TOKEN: ${{ github.token }}
GITHUB_REF_BRANCH: ${{ github.ref }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ env.GITHUB_REF_BRANCH }}

- name: Set up default branch name
id: default_branch
run: echo "DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef -q '.defaultBranchRef.name')" >> $GITHUB_ENV
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check for .changes directory
id: check_changes_dir
run: |
if [[ -d ".changes" ]]; then
echo "changes_dir_exists=true" >> $GITHUB_OUTPUT
else
echo "changes_dir_exists=false" >> $GITHUB_OUTPUT
echo "⏩ no changie entry required on this"
fi

- name: Fetch default branch
id: fetch_branches
run: |
git fetch origin ${{ env.DEFAULT_BRANCH }}
git fetch origin ${{ env.GITHUB_REF_BRANCH }}

- name: Check for labels
id: check_labels
run: |
echo "no_changie_required=false" >> $GITHUB_OUTPUT
echo "dependencies=false" >> $GITHUB_OUTPUT
for label in $(gh pr view ${{ github.event.pull_request.number }} --json labels --jq '.labels[].name'); do
if [[ "$label" == "no-changie-required" ]]; then
echo "no_changie_required=true" >> $GITHUB_OUTPUT
echo "❎ bypass on changie noted due to label"
elif [[ "$label" == "dependencies" ]]; then
echo "dependencies=true" >> $GITHUB_OUTPUT
fi
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Validate changie entry
id: validate_changie_entry
if: steps.check_changes_dir.outputs.changes_dir_exists == 'true' && steps.check_labels.outputs.no_changie_required == 'false' && steps.check_labels.outputs.dependencies == 'false'
run: |
# Fetch existing comments
existing_comments=$(gh pr view ${{ github.event.pull_request.number }} --json comments --jq '.comments[].body')

changes=$(git diff --name-only origin/${{ env.DEFAULT_BRANCH }}...HEAD -- .changes/)

if [[ -n "$changes" ]]; then
echo "Changie entry found"
comment="✅ changie entry was found"
if ! echo "$existing_comments" | grep -q "✅ changie entry was found"; then
gh pr review ${{ github.event.pull_request.number }} --approve
gh pr comment ${{ github.event.pull_request.number }} --body "$comment"
fi
else
echo "No changie entry found in .changes"
comment="❌ A changie entry is required in .changes/"
if ! echo "$existing_comments" | grep -q "❌ A changie entry is required in .changes/unreleased"; then
echo "adding review comment saying required, since not seeing prior comment before"
gh pr review ${{ github.event.pull_request.number }} --request-changes --body "$comment"
fi
fi

# Update or post the review comment
if [[ -n "$comment" ]]; then
if echo "$existing_comments" | grep -q "$comment"; then
echo "Review comment already posted"
else
echo "adding review comment since not seeing prior comment before"
gh pr comment ${{ github.event.pull_request.number }} --body "$comment"
fi
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# github-workflow

Check failure on line 1 in README.md

View workflow job for this annotation

GitHub Actions / Trunk Check

prettier

Incorrect formatting, autoformat by running 'trunk fmt'

> **_Warning_**

Expand Down Expand Up @@ -37,3 +37,8 @@

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

## Lint Action

The lint action now performs a second job of validating that a changie entry was added. This ensures that all pull requests, except those with specific labels, include a changie entry in the `.changes/unreleased` directory.

Check notice on line 43 in README.md

View workflow job for this annotation

GitHub Actions / Trunk Check

markdownlint(MD013)

[new] Line length

Loading