File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Block .env Changes
2+
3+ on :
4+ push :
5+ branches :
6+ - quekshuy/block-env-updates-workflow/1
7+ pull_request :
8+ types :
9+ - opened
10+ - synchronize
11+ - reopened
12+ - ready_for_review
13+
14+ jobs :
15+ block-env-updates :
16+ name : Ensure .env is untouched
17+ runs-on : ubuntu-latest
18+ steps :
19+ - name : Fail when .env is added, modified, or renamed to
20+ uses : actions/github-script@v7
21+ with :
22+ script : |
23+ const pr = context.payload.pull_request;
24+ if (!pr) {
25+ core.info('No pull request context; exiting successfully.');
26+ return;
27+ }
28+
29+ const files = await github.paginate(github.rest.pulls.listFiles, {
30+ owner: context.repo.owner,
31+ repo: context.repo.repo,
32+ pull_number: pr.number,
33+ per_page: 100
34+ });
35+
36+ const violatingFiles = files.filter(file => {
37+ if (file.filename === '.env' && (file.status === 'added' || file.status === 'modified')) {
38+ return true;
39+ }
40+
41+ if (file.status === 'renamed' && file.filename === '.env') {
42+ return true;
43+ }
44+
45+ return false;
46+ });
47+
48+ if (violatingFiles.length > 0) {
49+ const details = violatingFiles.map(file => `${file.status}: ${file.filename}`).join(', ');
50+ core.setFailed(`Blocking pull request because .env file was changed (${details}).`);
51+ } else {
52+ core.info('No blocked .env changes detected.');
53+ }
You can’t perform that action at this time.
0 commit comments