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 #84

Merged
merged 13 commits into from
Aug 13, 2024
Merged
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
4 changes: 3 additions & 1 deletion .changes/v0.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
- New template to simplify maintenance by workflow dispatch adding required changelog entries to create a pull request that bumps the version and runs changie commands to generate a new release.

This is done to help the development effort to bump a release based on dependency updates without having to clone and run cli tools locally.

- New template to trigger a changie based release from just CI. Will create PR for release to be reviewed and approved.

### ⬆️ Dependencies

- Maintenance release due to updated dependencies.
- Maintenance release due to updated dependencies.
85 changes: 83 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,84 @@ 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
changes=$(git diff --name-only --diff-filter=A origin/${{ env.DEFAULT_BRANCH }}...HEAD -- .changes/)

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

# Update or post the review comment
if [[ -n "$comment" ]]; then
echo "adding review comment since not seeing prior comment before"
gh pr comment ${{ github.event.pull_request.number }} --body "$comment" --edit-last || gh pr comment ${{ github.event.pull_request.number }} --body "$comment"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 0 additions & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ jobs:
ignore-pr-updates: true # else renovate prs will never age out
labels-to-remove-when-unstale: stale, stale-issue, stale-closed
enable-statistics: true

7 changes: 3 additions & 4 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
#https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md#md002
comment: my-markdown-linting-rules
# comment: my-markdown-linting-rules

# enable all default tagged rules
default: true
Expand Down Expand Up @@ -43,13 +43,12 @@ MD025: true
# This is for maintainability and code diffs.
# Try applying semantic line break concept for breaking up longer phrases
# https://sembr.org/
MD013:
line_length: 200
MD013: false

# MD024/no-duplicate-heading/no-duplicate-header - Multiple headings with the same content
# This tweaks to allow nested items to have duplicate headers.
MD024:
# Only check sibling headings
allow_different_nesting: true

# Only check sibling headings
siblings_only: true
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# github-workflow

> **_Warning_**

This is a collection of github workflow automation for managing workflows for this GitHub organization.
This is not a published marketplace set of actions for external use, and customized for workflows on public repos managed here.

These are subject to breaking changes and managed by the DevOps Secrets Vault team primarily.
> **warning**
> This is a collection of github workflow automation for managing workflows for this GitHub organization.
> This is not a published marketplace set of actions for external use, and customized for workflows on public repos managed here.
> These are subject to breaking changes and managed by the DevOps Secrets Vault team primarily.

## Contributors

Expand Down
Loading