Skip to content

Merge pull request #362 from emibcn/dependabot/npm_and_yarn/eslint-pl… #783

Merge pull request #362 from emibcn/dependabot/npm_and_yarn/eslint-pl…

Merge pull request #362 from emibcn/dependabot/npm_and_yarn/eslint-pl… #783

Workflow file for this run

name: General Validity
on:
workflow_dispatch:
push:
branches: [ main ]
paths-ignore:
# Can we use '**.md' ?
- 'README.md'
- 'SECURITY.md'
- 'CODE_OF_CONDUCT.md'
- 'LICENSE'
- '.gitignore'
- '.npmignore'
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-20.04
strategy:
matrix:
node: [14]
# Map a step output to a job output
outputs:
coverage: ${{ steps.coverage.outputs.coverage }}
coverage-rounded-display: ${{ steps.coverage.outputs.coverage-rounded-display }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4.0.4
with:
node-version: ${{ matrix.node }}
- name: Cache node modules
uses: actions/cache@v4
with:
path: |
node_modules
.yarn/cache
key: ${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('.github/workflows/*.yml') }}
restore-keys: |
${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}
${{ runner.OS }}-build
- name: yarn install
run: yarn --color --immutable
- name: test + coverage
run: yarn test:unit
# Coverage badges will be updated on any branch
# and saved into a dedicated one
- name: Check test coverage
uses: johanvanhelden/gha-clover-test-coverage-check@v1
id: coverage
with:
percentage: 50
exit: 0
rounded-precision: 2
filename: "coverage/clover.xml"
badge:
# Only generate and publish if these conditions are met:
# - The test step ended successfully
# - One of these is met:
# - This is a pull request event and the pull actor is the same as the repo owner
# - This is a push event and the push event is on branch 'main'
needs: test
if: ${{ ( github.event_name == 'pull_request' && github.actor == github.repository_owner ) || github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
steps:
- name: Extract branch name
run: |
TMP_PULL_HEAD_REF="${{ github.head_ref }}"
TMP_GITHUB_REF="${GITHUB_REF#refs/heads/}"
EXPORT_VALUE=""
if [ "${TMP_PULL_HEAD_REF}" != "" ]
then
EXPORT_VALUE="${TMP_PULL_HEAD_REF}"
else
EXPORT_VALUE="${TMP_GITHUB_REF}"
fi
echo "branch=${EXPORT_VALUE}" >> "${GITHUB_OUTPUT}"
id: extract_branch
- uses: actions/checkout@v4
with:
ref: badges
# Use the output from the `coverage` step
- name: Generate the badge SVG image
uses: emibcn/badge-action@v2.0.3
id: badge
with:
label: 'Coverage'
status: ${{ needs.test.outputs.coverage-rounded-display }}
color: ${{
needs.test.outputs.coverage > 90 && 'green' ||
needs.test.outputs.coverage > 80 && 'yellow,green' ||
needs.test.outputs.coverage > 70 && 'yellow' ||
needs.test.outputs.coverage > 60 && 'orange,yellow' ||
needs.test.outputs.coverage > 50 && 'orange' ||
needs.test.outputs.coverage > 40 && 'red,orange' ||
needs.test.outputs.coverage > 30 && 'red,red,orange' ||
needs.test.outputs.coverage > 20 && 'red,red,red,orange' ||
'red' }}
path: test-coverage.svg
- name: Commit badge
env:
BRANCH: ${{ steps.extract_branch.outputs.branch }}
FILE: 'test-coverage.svg'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
mkdir -p "${BRANCH}"
mv "${FILE}" "${BRANCH}"
git add "${BRANCH}/${FILE}"
# Will give error if badge did not changed
git commit -m "Add/Update badge" || true
- name: Push badge commit
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: badges
test-build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4.0.4
with:
node-version: 14.x
- name: Cache node modules
uses: actions/cache@v4
with:
path: |
node_modules
.yarn/cache
key: ${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('.github/workflows/*.yml') }}
restore-keys: |
${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}
${{ runner.OS }}-build
- name: yarn install
run: yarn --immutable
- name: test build
run: yarn test:build-test
docs:
runs-on: ubuntu-20.04
needs: [test, test-build]
if: ${{ ( github.event_name == 'pull_request' && github.event.pull_request.merged == true ) || github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4.0.4
with:
node-version: 14.x
- name: Cache node modules
uses: actions/cache@v4
with:
path: |
node_modules
.yarn/cache
key: ${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('.github/workflows/*.yml') }}
restore-keys: |
${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}
${{ runner.OS }}-build
- name: yarn install
run: yarn --immutable
- name: generate docs
run: yarn mkdocs
- name: Deploy to GitHub Pages
if: success()
uses: crazy-max/ghaction-github-pages@v4
with:
target_branch: gh-pages
build_dir: doc
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}