@@ -19,96 +19,100 @@ jobs:
1919
2020 - name : Setup Branch Protection Rules
2121 uses : actions/github-script@v7
22+ continue-on-error : true # Don't fail if permissions are insufficient
2223 with :
2324 github-token : ${{ secrets.GITHUB_TOKEN }}
24- continue-on-error : true # Don't fail if permissions are insufficient
25- script : |
26- const owner = context.repo.owner;
27- const repo = context.repo.repo;
28-
29- // Main branch protection rules
30- const mainProtection = {
31- required_status_checks: {
32- strict: true,
33- contexts: [
34- 'test (20.x)',
35- 'test (22.x)',
36- 'security',
37- 'code-quality',
38- 'compatibility (ubuntu-latest, 20.x)',
39- 'compatibility (windows-latest, 20.x)',
40- 'compatibility (macos-latest, 20.x)'
41- ]
42- },
43- enforce_admins: false, // Allow admins to bypass for emergency fixes
44- required_pull_request_reviews: {
45- required_approving_review_count: 1,
46- dismiss_stale_reviews: true,
47- require_code_owner_reviews: false,
48- require_last_push_approval: false
49- },
50- restrictions: null, // No user/team restrictions
51- allow_force_pushes: false,
52- allow_deletions: false,
53- block_creations: false,
54- required_conversation_resolution: true,
55- lock_branch: false,
56- allow_fork_syncing: true
57- };
58-
59- try {
60- await github.rest.repos.updateBranchProtection({
61- owner,
62- repo,
63- branch: 'main',
64- ...mainProtection
65- });
66- console.log('✅ Main branch protection rules updated successfully');
67- } catch (error) {
68- console.error('❌ Failed to update main branch protection:', error.message);
69- // Don't fail the workflow if branch protection can't be set
70- // This might happen due to permissions or repository settings
71- }
25+ script : |
26+ const owner = context.repo.owner;
27+ const repo = context.repo.repo;
7228
73- // Develop branch protection rules (if it exists)
74- try {
75- await github.rest.repos.getBranch({
76- owner,
77- repo,
78- branch: 'develop'
79- });
80-
81- const developProtection = {
29+ // Main branch protection rules
30+ const mainProtection = {
8231 required_status_checks: {
8332 strict: true,
8433 contexts: [
8534 'test (20.x)',
35+ 'test (22.x)',
8636 'security',
87- 'code-quality'
37+ 'code-quality',
38+ 'compatibility (ubuntu-latest, 20.x)',
39+ 'compatibility (windows-latest, 20.x)',
40+ 'compatibility (macos-latest, 20.x)',
41+ 'pr-validation',
42+ 'template-integrity',
43+ 'version-consistency',
44+ 'registry-validation'
8845 ]
8946 },
90- enforce_admins: false,
47+ enforce_admins: false, // Allow admins to bypass for emergency fixes
9148 required_pull_request_reviews: {
9249 required_approving_review_count: 1,
93- dismiss_stale_reviews: false,
94- require_code_owner_reviews: false
50+ dismiss_stale_reviews: true,
51+ require_code_owner_reviews: false,
52+ require_last_push_approval: false
9553 },
96- restrictions: null,
54+ restrictions: null, // No user/team restrictions
9755 allow_force_pushes: false,
98- allow_deletions: false
56+ allow_deletions: false,
57+ block_creations: false,
58+ required_conversation_resolution: true,
59+ lock_branch: false,
60+ allow_fork_syncing: true
9961 };
10062
101- await github.rest.repos.updateBranchProtection({
102- owner,
103- repo,
104- branch: 'develop',
105- ...developProtection
106- });
107- console.log('✅ Develop branch protection rules updated successfully');
108- } catch (error) {
109- if (error.status === 404) {
110- console.log('ℹ️ Develop branch does not exist, skipping protection setup');
111- } else {
112- console.error('❌ Failed to update develop branch protection:', error.message);
63+ try {
64+ await github.rest.repos.updateBranchProtection({
65+ owner,
66+ repo,
67+ branch: 'main',
68+ ...mainProtection
69+ });
70+ console.log('✅ Main branch protection rules updated successfully');
71+ } catch (error) {
72+ console.error('❌ Failed to update main branch protection:', error.message);
73+ // Don't fail the workflow if branch protection can't be set
74+ // This might happen due to permissions or repository settings
75+ }
76+
77+ // Develop branch protection rules (if it exists)
78+ try {
79+ await github.rest.repos.getBranch({
80+ owner,
81+ repo,
82+ branch: 'develop'
83+ });
84+
85+ const developProtection = {
86+ required_status_checks: {
87+ strict: true,
88+ contexts: [
89+ 'test (20.x)',
90+ 'security',
91+ 'code-quality'
92+ ]
93+ },
94+ enforce_admins: false,
95+ required_pull_request_reviews: {
96+ required_approving_review_count: 1,
97+ dismiss_stale_reviews: false,
98+ require_code_owner_reviews: false
99+ },
100+ restrictions: null,
101+ allow_force_pushes: false,
102+ allow_deletions: false
103+ };
104+
105+ await github.rest.repos.updateBranchProtection({
106+ owner,
107+ repo,
108+ branch: 'develop',
109+ ...developProtection
110+ });
111+ console.log('✅ Develop branch protection rules updated successfully');
112+ } catch (error) {
113+ if (error.status === 404) {
114+ console.log('ℹ️ Develop branch does not exist, skipping protection setup');
115+ } else {
116+ console.error('❌ Failed to update develop branch protection:', error.message);
117+ }
113118 }
114- }
0 commit comments