Skip to content

Instantly share code, notes, and snippets.

@Ferfalk
Created July 3, 2026 22:02
Show Gist options
  • Select an option

  • Save Ferfalk/f59123063fda49b88cc1c984c3ce2924 to your computer and use it in GitHub Desktop.

Select an option

Save Ferfalk/f59123063fda49b88cc1c984c3ce2924 to your computer and use it in GitHub Desktop.
Nx Pull Request Workflows
name: Reviewdog
on:
push:
branches:
- main
- master
- develop
pull_request:
branches:
- main
- master
- develop
workflow_dispatch:
jobs:
reviewdog:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
pull-requests: write
checks: write
name: Run reviewdog
runs-on: ubuntu-latest
env:
REVIEWDOG_FILTER_MODE: ${{ (github.event_name == 'workflow_dispatch' && 'nofilter') || 'file' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
cache: npm
node-version-file: .nvmrc
- name: Install dependencies
run: npm ci
- name: Lint all projects (on push/dispatch)
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
run: |
echo "Running ESLint for all projects (outputting to individual files)..."
npx nx run-many \
--target=lint \
--all \
--configuration=ci \
--output-style=static \
--parallel=3
continue-on-error: true
- name: Lint affected projects (on pull_request)
if: github.event_name == 'pull_request'
run: |
echo "Running ESLint for affected projects (outputting to individual files)..."
npx nx affected \
--target=lint \
--configuration=ci \
--base=origin/${{ github.base_ref }} \
--output-style=static \
--parallel=3
continue-on-error: true
- name: Concatenate ESLint reports
run: |
echo "Collecting individual ESLint RDJSON reports..."
mkdir -p tmp/eslint-reports # Ensure directory exists
files_to_merge=$(find tmp/eslint-reports -name "*.rdjson" -type f)
if [ -z "$files_to_merge" ]; then
echo "No ESLint RDJSON report files found. Creating an empty RDJSON report."
echo '{"source": {"name": "eslint", "url": "https://eslint.org/"}, "diagnostics": []}' > tmp/eslint-reports/eslint-combined.rdjson
else
jq -s '(.[0].source | {source}) + {diagnostics: map(.diagnostics) | add}' $files_to_merge > tmp/eslint-reports/eslint-combined.rdjson
fi
echo "Combined RDJSON report generated at tmp/eslint-reports/eslint-combined.rdjson"
- name: Typecheck all projects and generate reports
run: |
echo "Running TSC for all projects (outputting to individual files)..."
npx nx run-many \
--target=typecheck \
--all \
--configuration=ci \
--output-style=static \
--parallel=3
continue-on-error: true
- name: Concatenate TSC reports
run: |
echo "Collecting individual TSC report files..."
mkdir -p tmp/typecheck-reports # Ensure directory exists
files_to_merge=$(find tmp/typecheck-reports -name "*.tsc" -type f)
if [ -z "$files_to_merge" ]; then
echo "No TSC report files found. Creating an empty report file."
echo -n "" > tmp/typecheck-reports/tsc-combined.tsc
else
cat $files_to_merge > tmp/typecheck-reports/tsc-combined.tsc
fi
echo "Combined TSC report generated at tmp/typecheck-reports/tsc-combined.tsc"
- name: Setup reviewdog
uses: reviewdog/action-setup@v1
with:
reviewdog_version: v0.20.3
- name: Run reviewdog for ESLint
id: reviewdog-eslint
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cat tmp/eslint-reports/eslint-combined.rdjson | reviewdog \
-f=rdjson \
-name=eslint \
-reporter=github-check \
-filter-mode=${{ env.REVIEWDOG_FILTER_MODE }} \
-fail-level=error \
-level=warning
continue-on-error: true
- name: Run reviewdog for TSC
id: reviewdog-tsc
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cat tmp/typecheck-reports/tsc-combined.tsc | reviewdog \
-f=tsc \
-name=tsc \
-reporter=github-check \
-filter-mode=${{ env.REVIEWDOG_FILTER_MODE }} \
-fail-level=error \
-level=warning \
> /dev/null
continue-on-error: true
- name: Check for reviewdog failures
if: steps.reviewdog-eslint.outcome == 'failure' || steps.reviewdog-tsc.outcome == 'failure'
run: |
echo "One or more reviewdog steps failed. Failing the workflow."
exit 1
name: Tests and Report
on:
push:
branches:
- main
- master
- develop
pull_request:
branches:
- main
- master
- develop
workflow_dispatch:
jobs:
test:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
name: Run Tests and Report
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
cache: npm
node-version-file: .nvmrc
- name: Install dependencies
run: npm ci
- name: Run affected tests
if: github.event_name == 'pull_request'
env:
NODE_OPTIONS: '--experimental-vm-modules'
run: npx nx affected --target=test --base=origin/${{ github.base_ref }} --ci --coverage --output-style=stream
continue-on-error: true
- name: Run all tests
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
env:
NODE_OPTIONS: '--experimental-vm-modules'
run: npx nx run-many --target=test --all --ci --coverage --output-style=stream
continue-on-error: true
- name: Prepare multiple report files input
id: report_inputs
if: github.event_name == 'pull_request' && (success() || failure())
run: |
coverage_files_input=""
junit_files_input=""
shopt -s globstar nullglob
for file_path in ./coverage/apps/**/coverage-summary.json; do
if [ -f "$file_path" ]; then
app_name=$(basename "$(dirname "$file_path")")
coverage_files_input="${coverage_files_input}${app_name}, ${file_path}\n"
fi
done
for file_path in ./coverage/apps/**/jest-junit.xml; do
if [ -f "$file_path" ]; then
app_name=$(basename "$(dirname "$file_path")")
junit_files_input="${junit_files_input}${app_name}, ${file_path}\n"
fi
done
coverage_files_input=$(echo -e "${coverage_files_input}" | sed '/^$/d')
junit_files_input=$(echo -e "${junit_files_input}" | sed '/^$/d')
echo "coverage_files<<EOF" >> $GITHUB_OUTPUT
echo -e "${coverage_files_input}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "junit_files<<EOF" >> $GITHUB_OUTPUT
echo -e "${junit_files_input}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Add coverage comment to PR
if: github.event_name == 'pull_request' && (success() || failure())
uses: MishaKav/jest-coverage-comment@main
with:
multiple-files: ${{ steps.report_inputs.outputs.coverage_files }}
multiple-junitxml-files: ${{ steps.report_inputs.outputs.junit_files }}
title: Unit Tests Results
- name: Report test results
if: success() || failure()
uses: dorny/test-reporter@v2
with:
name: Unit Tests Report
path: 'coverage/**/jest-junit.xml'
reporter: jest-junit
fail-on-error: true
fail-on-empty: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment