fix: fixed workflows #109
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: Unit tests | |
on: | |
push: | |
workflow_call: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
# Give the default GITHUB_TOKEN write permission to commit and push the changed files back to the repository. | |
contents: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.head_ref }} | |
token: ${{ github.token }} | |
- name: Set Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18.x | |
- name: Install PNPM | |
uses: pnpm/action-setup@v4 | |
with: | |
version: 9 | |
run_install: false | |
- name: Enable Corepack | |
run: corepack enable | |
- name: Get PNPM store directory | |
shell: bash | |
run: echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV | |
- name: Setup PNPM cache | |
uses: actions/cache@v4 | |
with: | |
path: ${{ env.STORE_PATH }} | |
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-pnpm-store- | |
- name: Install dependencies | |
run: pnpm install --frozen-lockfile | |
- name: Execute unit tests | |
run: | | |
pnpm run build | |
pnpm run fmt:check | |
pnpm run test | |
- name: allow access to coverage.sh | |
run: chmod +x ./scripts/coverage.sh | |
shell: bash | |
- name: Extract coverage | |
id: coverage | |
run: | | |
value=$(pnpm run test:cov | awk '/All files/ {print $10}' | tr -d '%') | |
echo "coverage=$value" >> $GITHUB_OUTPUT | |
- name: Add test coverage to README | |
run: ./scripts/coverage.sh | |
shell: bash | |
env: | |
COVERAGE: ${{ steps.coverage.outputs.coverage }} | |
- name: Check if coverage changed | |
id: check_coverage_changed | |
run: | | |
echo "::set-output name=coverage_changed::$(git diff --name-only README.md | grep -E '^README.md$')" | |
- name: Commit changes | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
if: ${{ github.ref == 'refs/heads/main' && steps.check_coverage_changed.outputs.coverage_changed != '' }} | |
with: | |
commit_message: "Generate coverage badge" | |
file_pattern: "README.md" | |
commit_author: Aave <[email protected]> |