Skip to content

Commit

Permalink
feat: add selector immutability checks (#84)
Browse files Browse the repository at this point in the history
* feat: add selector immutability checks
  • Loading branch information
KodeyThomas authored Dec 6, 2024
1 parent 8433510 commit 13eee03
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
66 changes: 66 additions & 0 deletions .github/workflows/immutability-check.yml
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'
2 changes: 1 addition & 1 deletion selectors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,4 @@ selectors:
name: "ethereum-mainnet-worldchain-1"
21000000:
selector: 9043146809313071210
name: "corn-mainnet"
name: "corn-mainnet"

0 comments on commit 13eee03

Please sign in to comment.