Skip to content

Commit 6a0eea9

Browse files
Shared configs rulesets (#122)
* move branch protection rules to workflows * remove unnecessary config * update deps * start tests * add shared-configs as a valid branch prefix. * add permissions * rename plugins * fix typos * fix json * lint * lint * Update vitest.config.mts Co-authored-by: Copilot <[email protected]> * Update vitest.config.shared.mts Co-authored-by: Copilot <[email protected]> * lint --------- Co-authored-by: Copilot <[email protected]>
1 parent 7402bc9 commit 6a0eea9

29 files changed

+866
-138
lines changed

.github/policies/branch-naming.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Branch must start with:
2+
# - any folder under apps/
3+
# - any folder under packages/
4+
# - shared-configs/
5+
# - release/
6+
branch_name_regex: '^(apps|packages)\/[^\/]+[\/_.-].+|^(shared-configs|release)[\/_.-].+'

.github/rulesets/require-pr-main.json

Lines changed: 0 additions & 40 deletions
This file was deleted.

.github/rulesets/require-pr-package.json

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import yaml
2+
import sys
3+
4+
with open('.github/policies/branch-naming.yml') as f:
5+
print(yaml.safe_load(f)['branch_name_regex'])
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
import re
3+
import sys
4+
5+
branch = os.environ.get('BRANCH')
6+
pattern = os.environ.get('REGEX')
7+
8+
if not branch or not pattern:
9+
print('❌ Missing BRANCH or REGEX environment variable.')
10+
sys.exit(1)
11+
12+
if re.fullmatch(pattern, branch):
13+
print('✅ Branch name is valid.')
14+
else:
15+
print(f'❌ Branch name {branch} does not match policy:\n {pattern}')
16+
sys.exit(1)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Branch naming policy
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request:
8+
types: [opened, reopened, synchronize, edited, ready_for_review]
9+
10+
jobs:
11+
check-branch-name:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout (no submodules needed)
15+
uses: actions/checkout@v4
16+
17+
- name: Read policy
18+
id: policy
19+
run: |
20+
regex=$(python .github/scripts/read_branch_policy.py)
21+
echo "regex=$regex" >> $GITHUB_OUTPUT
22+
23+
- name: Validate branch name
24+
env:
25+
BRANCH: ${{ github.head_ref || github.ref_name }}
26+
REGEX: ${{ steps.policy.outputs.regex }}
27+
run: |
28+
echo "Branch: $BRANCH"
29+
echo "Regex : $REGEX"
30+
python .github/scripts/validate_branch_name.py

.github/workflows/validate-pr-prefixes.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,23 @@ jobs:
3333
fi
3434
echo "Package/app branches: ${PKGS[@]}"
3535
36-
# If base is main, allow only main-* or <packagename>-* branches
36+
# If base is main, allow only main-*, shared-configs-*, or <packagename>-* branches
3737
if [[ "$BASE" == "main" ]]; then
3838
for pkg in "${PKGS[@]}"; do
3939
if [[ "$HEAD" =~ ^"${pkg}-" ]]; then
4040
echo "✅ Allowed: PR from branch '$HEAD' (package prefix)"
4141
exit 0
4242
fi
4343
done
44+
if [[ "$HEAD" =~ ^"shared-configs-" ]]; then
45+
echo "✅ Allowed: PR from branch '$HEAD' (shared-configs prefix)"
46+
exit 0
47+
fi
4448
if [[ "$HEAD" =~ ^"main-" ]]; then
4549
echo "✅ Allowed: PR from branch '$HEAD' (main- prefix)"
4650
exit 0
4751
fi
48-
echo "❌ Only PRs from branches starting with 'main-' or '<package>-' may target main."
52+
echo "❌ Only PRs from branches starting with 'main-', 'shared-configs-', or '<package>-' may target main."
4953
exit 1
5054
fi
5155

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Logs
21
logs
32
*.log
43
npm-debug.log*
@@ -11,7 +10,8 @@ node_modules
1110
dist-ssr
1211
dist
1312
pub
14-
coverage
13+
coverage/*
14+
!coverage.yml
1515
*.local
1616

1717
.idea
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { describe, it, expect } from 'vitest';
2+
3+
describe('Package exists', () => {
4+
it('should return true', () => {
5+
expect(true).toBe(true);
6+
});
7+
});

.template/shared/vitest.config.mts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import baseConfig from "@instructure.ai/shared-configs/vitest";
2+
import { mergeConfig } from "vitest/config";
3+
4+
export default mergeConfig(baseConfig, {
5+
6+
});

0 commit comments

Comments
 (0)