Skip to content
This repository was archived by the owner on Apr 7, 2025. It is now read-only.

Commit 50711c2

Browse files
authored
feat: add check for project tags (#622)
1 parent 2d4ec40 commit 50711c2

File tree

1 file changed

+81
-2
lines changed

1 file changed

+81
-2
lines changed

.github/workflows/pr.yml

+81-2
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,89 @@ jobs:
4545
exit 1
4646
fi
4747
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+
48127
job-eslint:
49128
name: eslint
50129
runs-on: ubuntu-latest
51-
needs: job-checkout-and-build
130+
needs: [job-checkout-and-build, job-check-project-tags]
52131
steps:
53132
- name: Checkout repo
54133
uses: actions/checkout@v2
@@ -94,7 +173,7 @@ jobs:
94173
job-test:
95174
name: Jest
96175
runs-on: ubuntu-latest
97-
needs: job-checkout-and-build
176+
needs: [job-checkout-and-build, job-check-project-tags]
98177
steps:
99178
- name: Checkout repo
100179
uses: actions/checkout@v2

0 commit comments

Comments
 (0)