Skip to content

Commit 826cb30

Browse files
authored
Merge pull request #4 from kamdubiel/chore/improvements
Add example tests
2 parents 36395bf + 16412ac commit 826cb30

File tree

14 files changed

+1001
-317
lines changed

14 files changed

+1001
-317
lines changed

.github/actions/code-analysis/action.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
name: 👁️‍🗨️ Code Analysis
22
description: 'Run code analysis'
33

4-
inputs:
5-
github-token:
6-
description: 'GitHub token for API access'
7-
required: true
8-
94
runs:
105
using: 'composite'
116
steps:
Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
name: 💻 Node.js setup
22
description: 'Setup Node.js environment and install dependencies'
33

4+
inputs:
5+
install-dependencies:
6+
description: 'Set to false to skip pnpm install (for tooling-only jobs)'
7+
default: 'true'
8+
49
runs:
510
using: 'composite'
611
steps:
@@ -9,37 +14,22 @@ runs:
914
shell: bash
1015

1116
- name: 🎰 Setup Node
12-
uses: actions/setup-node@v4
17+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
1318
with:
1419
node-version-file: 'package.json'
15-
16-
- name: 🎈 Install pNPM
17-
uses: pnpm/action-setup@v3
18-
with:
19-
run_install: false
20-
21-
- name: 📀 Get pnpm store directory
22-
run: |
23-
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
24-
shell: bash
25-
26-
- name: 💾 Setup pnpm cache
27-
uses: actions/cache@v4
28-
with:
29-
path: ${{ env.STORE_PATH }}
30-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
31-
restore-keys: |
32-
${{ runner.os }}-pnpm-store-
20+
cache: 'pnpm'
21+
cache-dependency-path: 'pnpm-lock.yaml'
3322

3423
- name: 📥 Install dependencies
24+
if: inputs.install-dependencies == 'true'
3525
run: pnpm install --frozen-lockfile --prefer-offline --ignore-scripts
3626
shell: bash
3727

3828
- name: 💾 Cache turbo build setup
39-
uses: actions/cache@v4
29+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830
4030
with:
4131
path: .turbo
42-
key: ${{ runner.os }}-turbo-${{ github.head_ref || github.ref_name }}-${{ github.sha }}
32+
key: ${{ runner.os }}-turbo-${{ github.head_ref || github.ref_name }}-${{ hashFiles('pnpm-lock.yaml') }}
4333
restore-keys: |
4434
${{ runner.os }}-turbo-${{ github.head_ref || github.ref_name }}-
4535
${{ runner.os }}-turbo-

.github/actions/test-coverage/action.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

.github/workflows/base-coverage.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: 🧪 CI
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read # required so checkout/actions using GITHUB_TOKEN can read repo
10+
11+
concurrency:
12+
group: ci-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
lint:
17+
runs-on: ubuntu-24.04
18+
steps:
19+
- name: 📥 Checkout Repository
20+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
21+
22+
- name: 💻 Node setup
23+
uses: ./.github/actions/node-setup
24+
25+
- name: 👁️‍🗨️ Code Analysis
26+
uses: ./.github/actions/code-analysis
27+
28+
licenses:
29+
runs-on: ubuntu-24.04
30+
steps:
31+
- name: 📥 Checkout Repository
32+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
33+
34+
- name: 💻 Node setup
35+
uses: ./.github/actions/node-setup
36+
37+
- name: 🗳️ Check Licenses
38+
uses: ./.github/actions/check-licenses
39+
40+
build:
41+
runs-on: ubuntu-24.04
42+
steps:
43+
- name: 📥 Checkout Repository
44+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
45+
46+
- name: 💻 Node setup
47+
uses: ./.github/actions/node-setup
48+
49+
- name: 🏗️ Build packages
50+
run: pnpm build
51+
shell: bash

.github/workflows/code-analysis.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

.github/workflows/coverage.yml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
name: 📊 Tests & Coverage
2+
3+
# Configuration
4+
# Set to 'true' for monorepo, 'false' for single repository
5+
env:
6+
MONOREPO: 'true'
7+
BASE_BRANCH: 'main'
8+
9+
on:
10+
push:
11+
branches:
12+
- main
13+
pull_request:
14+
types: [opened, synchronize, reopened]
15+
16+
concurrency:
17+
group: coverage-${{ github.ref }}
18+
cancel-in-progress: true
19+
20+
permissions:
21+
contents: read # required so checkout/actions using GITHUB_TOKEN can read repo
22+
actions: read # required to download base coverage artifact via workflow run APIs
23+
pull-requests: write # required to post/update coverage diff comments on PRs
24+
25+
jobs:
26+
coverage:
27+
runs-on: ubuntu-24.04
28+
permissions:
29+
actions: read # download base coverage artifact via workflow run APIs
30+
contents: read # checkout
31+
pull-requests: write # comment coverage diff on PRs
32+
env:
33+
EVENT_TYPE: ${{ github.event_name == 'push' && 'push' || 'pr' }}
34+
# Workflow-level env variables (MONOREPO, BASE_BRANCH) are automatically inherited by jobs
35+
steps:
36+
- name: 📥 Checkout Repository
37+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
38+
39+
- name: 💻 Node setup
40+
uses: ./.github/actions/node-setup
41+
42+
- name: 🧪 Test
43+
run: pnpm test:coverage
44+
shell: bash
45+
# Note: If tests fail, the workflow will fail and coverage steps won't run.
46+
# This ensures we only report coverage for passing tests.
47+
48+
- name: 📊 Aggregate coverage results and create summary
49+
if: env.EVENT_TYPE == 'pr'
50+
# MONOREPO is inherited from workflow-level env
51+
run: node scripts/aggregate-coverage-results.js
52+
shell: bash
53+
54+
- name: 🔍 Locate base coverage workflow run
55+
id: locate-base-coverage
56+
if: env.EVENT_TYPE == 'pr'
57+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
58+
env:
59+
BASE_WORKFLOW: coverage.yml
60+
# BASE_BRANCH is inherited from workflow-level env
61+
with:
62+
script: |
63+
const workflowId = process.env.BASE_WORKFLOW;
64+
const baseBranch = process.env.BASE_BRANCH || 'main';
65+
66+
// Get the latest successful workflow run from the base branch
67+
const { data } = await github.rest.actions.listWorkflowRuns({
68+
owner: context.repo.owner,
69+
repo: context.repo.repo,
70+
workflow_id: workflowId,
71+
branch: baseBranch,
72+
per_page: 20,
73+
});
74+
75+
const run = data.workflow_runs.find((run) => run.conclusion === 'success');
76+
if (run) {
77+
core.info(`Found base coverage run ${run.id} from ${baseBranch} branch`);
78+
core.setOutput('run-id', String(run.id));
79+
} else {
80+
core.warning(`No successful base coverage run found for ${baseBranch} branch`);
81+
core.setOutput('run-id', '');
82+
}
83+
84+
- name: 📥 Download base branch coverage artifact
85+
if: env.EVENT_TYPE == 'pr' && steps.locate-base-coverage.outputs.run-id != ''
86+
continue-on-error: true
87+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5
88+
with:
89+
name: base-coverage
90+
path: base-coverage
91+
github-token: ${{ secrets.GITHUB_TOKEN }}
92+
run-id: ${{ steps.locate-base-coverage.outputs.run-id }}
93+
94+
- name: 💬 Comment coverage diff
95+
if: env.EVENT_TYPE == 'pr'
96+
env:
97+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
98+
PR_NUMBER: ${{ github.event.pull_request.number }}
99+
BASE_COVERAGE_ROOT: base-coverage
100+
# MONOREPO and BASE_BRANCH are inherited from workflow-level env
101+
run: node scripts/comment-coverage-diff.js
102+
shell: bash
103+
104+
- name: ♻️ Collect coverage summaries
105+
if: env.EVENT_TYPE == 'push' && github.ref_name == 'main'
106+
# MONOREPO is inherited from workflow-level env
107+
run: |
108+
rm -rf base-coverage
109+
if [ "$MONOREPO" = "true" ]; then
110+
rsync -a \
111+
--include '*/' \
112+
--include 'coverage-summary.json' \
113+
--exclude '*' \
114+
coverage/ base-coverage/
115+
else
116+
mkdir -p base-coverage
117+
cp coverage/coverage-summary.json base-coverage/coverage-summary.json
118+
fi
119+
shell: bash
120+
121+
- name: 📤 Upload coverage artifact
122+
if: env.EVENT_TYPE == 'push' && github.ref_name == 'main'
123+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
124+
with:
125+
name: base-coverage
126+
path: base-coverage
127+
retention-days: 14 # Artifacts expire after 14 days. Adjust if needed, but note that PRs opened after expiration won't have base coverage to compare against.

0 commit comments

Comments
 (0)