@@ -45,10 +45,89 @@ jobs:
45
45
exit 1
46
46
fi
47
47
48
+ job-check-project-tags :
49
+ name : Check Project Tags
50
+ runs-on : ubuntu-latest
51
+ steps :
52
+ - name : Checkout repo
53
+ uses : actions/checkout@v2
54
+ with :
55
+ fetch-depth : 0
56
+
57
+ - name : Setup Node.js
58
+ uses : actions/setup-node@v1
59
+ with :
60
+ node-version : 12
61
+
62
+ - name : Cache node_modules
63
+ id : cache-node
64
+ uses : actions/cache@v2
65
+ env :
66
+ cache-name : node-modules
67
+ with :
68
+ path : ~/.npm
69
+ key : ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
70
+ restore-keys : |
71
+ ${{ runner.os }}-${{ env.cache-name }}-
72
+
73
+ - name : Install dependencies
74
+ run : npm ci
75
+
76
+ - name : Get Changed Files
77
+ id : getfile
78
+ run : |
79
+ PROJECT_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep "src/data/projects" || true)
80
+
81
+ if [ -z "$PROJECT_FILES" ]; then
82
+ echo "No project json files detected."
83
+ else
84
+ echo ::set-env name=PROJECT_FILES::$PROJECT_FILES
85
+ fi
86
+
87
+ - name : Run Project Tags Check
88
+ if : env.PROJECT_FILES != ''
89
+ uses : actions/github-script@v2
90
+ with :
91
+ script : |
92
+ const projectTags = require(`${process.env.GITHUB_WORKSPACE}/src/data/project-tags/project-tags.json`).map(t => t.slug);
93
+
94
+ const modifiedProjectFiles = process.env.PROJECT_FILES ? process.env.PROJECT_FILES.split(' ') : null
95
+ let errors = []
96
+
97
+ // Check all modified project json files
98
+ if (modifiedProjectFiles) {
99
+ modifiedProjectFiles.map(f => {
100
+ const projectJson = require(`${process.env.GITHUB_WORKSPACE}/${f}`)
101
+ console.log(projectJson)
102
+
103
+ // Check tags
104
+ let invalidTags = []
105
+ if ( projectJson.projectTags ) {
106
+ projectJson.projectTags.map(pt => {
107
+ if (!projectTags.includes(pt)) {
108
+ invalidTags.push(pt);
109
+ }
110
+ })
111
+
112
+ // Collect invalidTags into errors
113
+ if (invalidTags.length > 0) {
114
+ errors.push({file: f, invalidTags: invalidTags})
115
+ }
116
+ }
117
+ })
118
+
119
+ // Set Error Annotation for Results
120
+ if (errors.length > 0) {
121
+ core.setFailed(
122
+ `There are errors with the <projectTags> mapping. For more info, visit https://github.com/newrelic/opensource-website/wiki/Contributing-Project-Data#note-about-projectTags.
123
+ Errors: ${JSON.stringify(errors, null, 2)}`)
124
+ }
125
+ }
126
+
48
127
job-eslint :
49
128
name : eslint
50
129
runs-on : ubuntu-latest
51
- needs : job-checkout-and-build
130
+ needs : [ job-checkout-and-build, job-check-project-tags]
52
131
steps :
53
132
- name : Checkout repo
54
133
uses : actions/checkout@v2
94
173
job-test :
95
174
name : Jest
96
175
runs-on : ubuntu-latest
97
- needs : job-checkout-and-build
176
+ needs : [ job-checkout-and-build, job-check-project-tags]
98
177
steps :
99
178
- name : Checkout repo
100
179
uses : actions/checkout@v2
0 commit comments