-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add selector immutability checks (#84)
* feat: add selector immutability checks
- Loading branch information
1 parent
8433510
commit 13eee03
Showing
2 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# In order to prevent accidental changes to selectors, we're ensuring their immutability | ||
# This action will fail if the immutability is violated | ||
name: Ensure Selector Immutability | ||
|
||
on: [ pull_request ] | ||
|
||
jobs: | ||
immutability-check: | ||
name: Check Selector Immutability | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
pull-requests: write | ||
steps: | ||
- name: Checkout Changes | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
- name: Checkout Previous Ref | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
with: | ||
ref: ${{ github.event.pull_request.base.ref }} | ||
path: old | ||
|
||
- name: Extract Immutability Violations | ||
id: immutability-check | ||
uses: mikefarah/yq@bc5b54cb1d1f720db16c9f75c5b45384d00e5cbf # v4.44.5 | ||
with: | ||
# Checks if any selector that is present in the previous ref has been modified in the current ref | ||
cmd: yq e '.selectors as $old | load("selectors.yml") | .selectors as $new | $new | with_entries(select(.key as $key | $old | has($key))) | with_entries(select(.key as $key | $old[$key].selector != $new[$key].selector))' old/selectors.yml | ||
|
||
- name: Extract Removed Selectors | ||
id: removed-selectors-check | ||
uses: mikefarah/yq@bc5b54cb1d1f720db16c9f75c5b45384d00e5cbf # v4.44.5 | ||
with: | ||
# Checks if any selector that previously existed has been removed | ||
cmd: yq e '.selectors as $old | load("selectors.yml").selectors as $new | $old | with_entries(select(.key as $key | $new | has($key) == false))' old/selectors.yml | ||
|
||
- name: Check Immutability Violations | ||
id: check-violations | ||
run: | | ||
violations=$(echo '${{ steps.immutability-check.outputs.result }}') | ||
removed=$(echo '${{ steps.removed-selectors-check.outputs.result }}') | ||
if [[ ! $violations == "{}" ]]; then | ||
echo "Selector immutability has been violated. Please ensure that exisiting selectors are not modified." | ||
exit 1 | ||
fi | ||
if [[ ! $removed == "{}" ]]; then | ||
echo "Selector immutability has been violated. Please ensure that exisiting selectors are not removed." | ||
exit 1 | ||
fi | ||
- name: Create comment | ||
if: failure() | ||
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 | ||
with: | ||
issue-number: ${{ github.event.pull_request.number }} | ||
body: | | ||
**Selector Immutability has been violated ❌** | ||
Existing `chain-selectors` are immutable. Please ensure you have not modified or removed an existing selector | ||
```yaml | ||
${{ (steps.immutability-check.outputs.result != '{}') && steps.immutability-check.outputs.result || steps.removed-selectors-check.outputs.result }} | ||
``` | ||
reactions: '+1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters