Skip to content

release

release #960

Workflow file for this run

name: Pull Request
on:
pull_request:
branches:
- develop
- main
repository_dispatch:
types: [pull-request-develop, pull-request-main]
jobs:
job-check-project-tags:
name: Check Project Tags
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Cache node_modules
id: cache-node
uses: actions/cache@v3
env:
cache-name: node-modules
with:
path: '**/node_modules'
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Get Changed Files
id: getfile
run: |
PROJECT_FILES=$(git diff --name-only ${{ github.rest.event.pull_request.base.sha }} ${{ github.rest.event.pull_request.head.sha }} | grep "src/data/projects" || true)
if [ -z "$PROJECT_FILES" ]; then
echo "No project json files detected."
else
echo "PROJECT_FILES<<EOF" >> $GITHUB_ENV
echo $PROJECT_FILES >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
fi
- name: Run Project Tags Check
if: env.PROJECT_FILES != ''
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const projectTags = require(`${process.env.GITHUB_WORKSPACE}/src/data/project-tags/project-tags.json`).map(t => t.slug);
const modifiedProjectFiles = process.env.PROJECT_FILES ? process.env.PROJECT_FILES.split(' ') : null
console.log(`Detected Project Files: ${JSON.stringify(modifiedProjectFiles, null, 2)}`)
let errors = []
// Check all modified project json files
if (modifiedProjectFiles) {
modifiedProjectFiles.forEach(f => {
const fileName = `${process.env.GITHUB_WORKSPACE}/${f}`;
const exists = fs.existsSync(fileName)
if (!exists) {
console.log(`INFO:: File not found: ${fileName}`)
} else {
const projectJson = require(`${process.env.GITHUB_WORKSPACE}/${f}`)
console.log(projectJson)
// Check tags
let invalidTags = []
if ( projectJson.projectTags ) {
projectJson.projectTags.map(pt => {
if (!projectTags.includes(pt)) {
invalidTags.push(pt);
}
})
// Collect invalidTags into errors
if (invalidTags.length > 0) {
errors.push({file: f, invalidTags: invalidTags})
}
}
}
})
// Set Error Annotation for Results
if (errors.length > 0) {
core.setFailed(
`There are errors with the <projectTags> mapping. For more info, visit https://github.com/newrelic/opensource-website/wiki/Contributing-Project-Data#note-about-projectTags.
Errors: ${JSON.stringify(errors, null, 2)}`)
}
}
job-eslint:
name: eslint
runs-on: ubuntu-latest
needs: [job-check-project-tags]
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18
- name: Cache node_modules
id: cache-node
uses: actions/cache@v3
env:
cache-name: node-modules
with:
path: '**/node_modules'
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-
- name: Install Dependencies
run: yarn install --frozen-lockfile
- name: Run eslint-check and generate report
id: eslint-check
run: |
yarn run eslint-check -- --output-file eslint_report.json --format json
continue-on-error: true
- name: Annotate Lint Results
uses: ataylorme/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
report-json: eslint_report.json
continue-on-error: true
- name: Check eslint-check outcome
if: steps.eslint-check.outcome != 'success'
run: |
echo "::error::eslint-check failed. View output of _Run eslint-check and generate report_ step"
exit 1
job-test:
name: Jest
runs-on: ubuntu-latest
needs: [job-check-project-tags]
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Cache node_modules
id: cache-node
uses: actions/cache@v3
env:
cache-name: node-modules
with:
path: '**/node_modules'
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Run Jest
run: yarn run test