refactor: Run tests on Node 18 & 20 #112
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
name: Node.js CI | |
on: | |
push: | |
branches: [ master, develop ] | |
pull_request: | |
branches: [ master, develop ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: true | |
matrix: | |
node-version: [18.x, 20.x] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v2 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- run: npm install | |
- run: npm run build --if-present | |
- run: npm run test --if-present | |
# Only run the coverage once | |
- if: ${{ matrix.node-version == '14.x' }} | |
name: Get Coverage for badge | |
run: | | |
# var SUMMARY = [ | |
# '', | |
# '=============================== Coverage summary ===============================', | |
# 'Statements : 32.5% ( 39/120 )', | |
# 'Branches : 38.89% ( 21/54 )', | |
# 'Functions : 21.74% ( 5/23 )', | |
# 'Lines : 31.93% ( 38/119 )', | |
# '================================================================================', | |
# '' | |
# ]; | |
# SUMMARY = SUMMARY.split('\n')[5]; // 'Lines : 31.93% ( 38/119 )' | |
# SUMMARY = SUMMARY.split(':')[1].split('(')[0].trim(); // '31.93%' | |
SUMMARY="$(npm run test-ci | tail -2 | head -1)" | |
TOKENS=($SUMMARY) | |
# process.env.COVERAGE = '31.93%'; | |
echo "COVERAGE=$(echo ${TOKENS[2]})" >> $GITHUB_ENV | |
# var REF = 'refs/pull/27/merge.json'; | |
REF=${{ github.ref }} | |
# console.log('github.ref: ' + REF); | |
echo "github.ref: $REF" | |
# var PATHS = REF.split('/'); | |
IFS='/' read -ra PATHS <<< "$REF" | |
# var BRANCH_NAME = PATHS[1] + PATHS[2]; | |
BRANCH_NAME="${PATHS[1]}_${PATHS[2]}" | |
# console.log(BRANCH_NAME); // 'pull_27' | |
echo $BRANCH_NAME | |
# process.env.BRANCH = 'pull_27'; | |
echo "BRANCH=$(echo ${BRANCH_NAME})" >> $GITHUB_ENV | |
- if: ${{ matrix.node-version == '14.x' }} | |
name: Create the Badge | |
uses: schneegans/[email protected] | |
with: | |
auth: ${{ secrets.GIST_SECRET }} | |
gistID: 550f6ee414a26e0c8eae7cb6af3c214e | |
filename: rollup-plugin-critical__${{ env.BRANCH }}.json | |
label: Test Coverage | |
message: ${{ env.COVERAGE }} | |
color: green | |
namedLogo: jest |