1
+ name : Check unallowed file changes
2
+
3
+ # **What it does**: If someone changes some files in the open repo, we prevent the pull request from merging.
4
+ # **Why we have it**: Some files can only be changed in the internal repository for security and workflow reasons.
5
+ # **Who does it impact**: Open source contributors.
6
+
7
+ on :
8
+ pull_request_target :
9
+ paths :
10
+ - ' .github/**'
11
+ - ' _plugins/**'
12
+ - ' analytics/**'
13
+ - ' js/**'
14
+ - ' scripts/**'
15
+ - ' vale-styles/**'
16
+ - ' _config.yml'
17
+ - ' gemfile'
18
+ - ' yarn.lock'
19
+ - ' .vale.ini'
20
+ - ' netlify.toml'
21
+ - ' package.json'
22
+
23
+ jobs :
24
+ triage :
25
+ if : github.repository == 'github/docs' && github.event.pull_request.user.login != ['markzegarelli','stayseesong', 'pwseg']
26
+ runs-on : ubuntu-latest
27
+ steps :
28
+ - name : Get files changed
29
+ uses : dorny/paths-filter@eb75a1edc117d3756a18ef89958ee59f9500ba58
30
+ id : filter
31
+ with :
32
+ # Base branch used to get changed files
33
+ base : ' develop'
34
+
35
+ # Enables setting an output in the format in `${FILTER_NAME}_files
36
+ # with the names of the matching files formatted as JSON array
37
+ list-files : json
38
+
39
+ # Returns list of changed files matching each filter
40
+ filters : |
41
+ notAllowed:
42
+ - '.github/**'
43
+ - '_plugins/**'
44
+ - 'analytics/**'
45
+ - 'js/**'
46
+ - 'scripts/**'
47
+ - 'vale-styles/**'
48
+ - '_config.yml'
49
+ - 'gemfile'
50
+ - 'yarn.lock'
51
+ - '.vale.ini'
52
+ - 'netlify.toml'
53
+ - 'package.json'
54
+
55
+ # When there are changes to files we can't accept, leave a comment
56
+ # explaining this to the PR author
57
+ - name : " Comment about changes we can't accept"
58
+ if : ${{ steps.filter.outputs.notAllowed }}
59
+ uses : actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
60
+ with :
61
+ github-token : ${{secrets.GITHUB_TOKEN}}
62
+ script : |
63
+ const badFilesArr = [
64
+ '.github/**',
65
+ '_plugins/**',
66
+ 'analytics/**',
67
+ 'js/**',
68
+ 'scripts/**',
69
+ 'vale-styles/**',
70
+ '_config.yml',
71
+ 'gemfile',
72
+ 'yarn.lock',
73
+ '.vale.ini',
74
+ 'netlify.toml',
75
+ 'package.json'
76
+ ]
77
+
78
+ const badFiles = badFilesArr.join('\n')
79
+
80
+ let reviewMessage = `👋 Hello. It looks like you've modified some files that we can't accept as contributions. The complete list of files we can't accept are:\n${badFiles}\n\nPlease revert all files in this list and resubmit your pull request.`
81
+ let workflowFailMessage = "It looks like you've modified some files that we can't accept as contributions."
82
+
83
+ try {
84
+ createdComment = await github.issues.createComment ({
85
+ owner: context.repo.owner,
86
+ repo: context.repo.repo,
87
+ issue_number: context.payload.number,
88
+ body: reviewMessage,
89
+ })
90
+
91
+ workflowFailMessage = `${workflowFailMessage} Please see ${createdComment.data.html_url} for details.`
92
+ } catch(err) {
93
+ console.log("Error creating comment.", err)
94
+ }
95
+
96
+ core.setFailed(workflowFailMessage)
0 commit comments