replace rollup-plugin-postcss-modules #1655
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# We split our workflow onto two parts: non-privileged (this one) and privileged (another one). | |
# Here is the explanation why: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ | |
# | |
name: quality_gate | |
on: | |
pull_request: | |
branches: | |
- develop | |
- main | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.base_ref }}-${{ github.head_ref }} | |
cancel-in-progress: true | |
env: | |
REPORT_1_ARTIFACT: qualityGateReports_file1 | |
REPORT_2_ARTIFACT: qualityGateReports_file2 | |
PR_NUM_ARTIFACT: qualityGateReports_pr | |
ERROR_STATUS_TAG: 'CI Status: error' | |
# | |
TARGET_BRANCH_DIR: ./target-branch | |
MERGE_COMMIT_BRANCH_DIR: ./merge-commit-branch | |
PREV_DOCS_GEN_STATS_REPORT_PATH: ../target-branch/public/docs/docsGenOutput/docsGenStats.json # Pay attention it should be relative to the "merge commit branch" dir. | |
REPORT_1_PATH: ./merge-commit-branch/.reports/trackBundleSize.md | |
REPORT_2_PATH: ./merge-commit-branch/.reports/generateComponentsApiStats.md | |
jobs: | |
quality_gate: | |
runs-on: ubuntu-latest | |
steps: | |
# By default, it checks out the "merge-commit" for "pull_request" events (https://github.com/actions/checkout) | |
# I.e. the result of merging source branch to the target branch will be checked out. | |
- name: 'Checkout the "merge commit" branch' | |
uses: actions/checkout@v4 | |
with: | |
path: ${{ env.MERGE_COMMIT_BRANCH_DIR }} | |
# Checkout the TARGET branch. | |
- name: 'Checkout "target" branch' | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.base.ref }} | |
repository: ${{ github.event.pull_request.base.repo.full_name }} | |
path: ${{ env.TARGET_BRANCH_DIR }} | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: '18.x' | |
cache: 'yarn' | |
cache-dependency-path: | | |
${{ env.TARGET_BRANCH_DIR }}/yarn.lock | |
${{ env.TARGET_BRANCH_DIR }}/*/yarn.lock | |
${{ env.MERGE_COMMIT_BRANCH_DIR }}/yarn.lock | |
${{ env.MERGE_COMMIT_BRANCH_DIR }}/*/yarn.lock | |
- name: 'Install dependencies & Run "generate-components-api" (target branch)' | |
working-directory: ${{ env.TARGET_BRANCH_DIR }} | |
run: | | |
yarn | |
yarn generate-components-api | |
- name: 'Install dependencies & Run quality checks (merge commit branch)' | |
working-directory: ${{ env.MERGE_COMMIT_BRANCH_DIR }} | |
run: | | |
yarn | |
yarn track-bundle-size | |
yarn generate-components-api --prev-stats=${{env.PREV_DOCS_GEN_STATS_REPORT_PATH}} | |
# | |
# | |
# | |
# Prepare & upload reports | |
# | |
# | |
# | |
- name: 'Prepare artifact (pr number)' | |
shell: bash | |
run: | | |
echo ${{ github.event.pull_request.number }} > ./${{ env.PR_NUM_ARTIFACT }} | |
- name: 'Upload artifact (pr number)' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.PR_NUM_ARTIFACT }} | |
path: ./${{ env.PR_NUM_ARTIFACT }} | |
retention-days: 1 # minimum retention | |
- name: 'Upload artifact (report 1 content)' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.REPORT_1_ARTIFACT }} | |
path: ${{ env.REPORT_1_PATH }} | |
retention-days: 1 # minimum retention | |
- name: 'Upload artifact (report 2 content)' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.REPORT_2_ARTIFACT }} | |
path: ${{ env.REPORT_2_PATH }} | |
retention-days: 1 # minimum retention | |
# | |
# | |
# | |
# | |
# | |
- name: 'Mark as failed if any quality check is unsuccessful' | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const REPORTS_MAP = { | |
'${{env.REPORT_1_PATH}}': 'Size of some package exceeds threshold', | |
'${{env.REPORT_2_PATH}}': 'The amount of props/type without comments is increased' | |
}; | |
const fs = require('fs'); | |
const errors = []; | |
Object.keys(REPORTS_MAP).forEach((key) => { | |
if (fs.existsSync(key)) { | |
const reportContent = fs.readFileSync(key).toString(); | |
if (reportContent.indexOf('${{env.ERROR_STATUS_TAG}}') !== -1) { | |
errors.push(REPORTS_MAP[key]); | |
} | |
} else { | |
errors.push(`Unable to find report at location: ${key}.`); | |
} | |
}); | |
if (errors.length > 0) { | |
core.setFailed(errors.join('; ')); | |
} |