Skip to content

Commit 235019e

Browse files
mfranzkegithub-advanced-security[bot]Copilot
authored
refactor: optimized workflows (#29)
* Reapply "refactor: optimized workflows" This reverts commit 8eb0973. * fix: permissions * Potential fix for code scanning alert no. 11: Workflow does not contain permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Potential fix for code scanning alert no. 12: Workflow does not contain permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Potential fix for code scanning alert no. 13: Workflow does not contain permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Update .github/workflows/default.yml Co-authored-by: Copilot <[email protected]> * Update default.yml * refactor: removed redundant codeql setup * Apply suggestions from code review Co-authored-by: Copilot <[email protected]> * Update .github/WORKFLOWS.md * Update .github/WORKFLOWS.md * refactor: simplification --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: Copilot <[email protected]>
1 parent 8eb0973 commit 235019e

File tree

10 files changed

+372
-93
lines changed

10 files changed

+372
-93
lines changed

.github/WORKFLOWS.md

Lines changed: 121 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,65 @@ This document describes all the GitHub Actions workflows and configurations set
44

55
## Workflows Overview
66

7-
### 1. **CI Workflow** (`.github/workflows/ci.yml`)
7+
### 1. **Default CI/CD Pipeline** (`.github/workflows/default.yml`)
88

9-
**Triggers:** Push to main/develop, Pull requests to main/develop
9+
**Triggers:** Push to main, Pull requests to main, Manual dispatch
10+
11+
**Optimized Parallel Architecture:**
12+
13+
This is the main orchestrator workflow that runs analysis tasks in parallel, then proceeds with build-dependent tasks sequentially:
14+
15+
**Stage 1: Parallel Analysis** (All run simultaneously, no build required)
16+
17+
- **Lint & Code Style** - XO linting, Markdown linting, Package checks by publint, Prettier checks
18+
- **Quality Analysis** - Test coverage, quality metrics (embedded quality checks)
19+
- **Security Analysis** - CodeQL security scanning (embedded security checks)
20+
21+
**Stage 2: Build & Test** (Requires all Stage 1 to pass)
22+
23+
- **CI Tests & Build** - Calls `ci.yml` for comprehensive testing and building
24+
25+
**Stage 3: Performance Testing** (Conditional, requires build)
26+
27+
- **Performance Tests** - Calls `performance.yml` (only when src/ files change)
28+
29+
**Stage 4: Deploy** (Requires all previous stages, main branch only)
30+
31+
- **GitHub Pages Deploy** - Calls `deploy-pages.yml`
32+
33+
**Stage 5: Release** (Conditional, requires all stages, main branch only)
34+
35+
- **Release Management** - Calls `release.yml` (only for changeset/, src/ or package.json changes)
36+
37+
**Benefits:**
38+
39+
- **Parallel efficiency**: All analysis runs simultaneously (3x faster than sequential)
40+
- **Fast failure**: Any analysis failure stops the pipeline before expensive build operations
41+
- **Resource optimization**: Build-dependent tasks only run after all checks pass
42+
- **Conditional execution**: Performance tests only when source files change
43+
- **Gated releases**: Releases only happen after all quality gates pass
44+
45+
### 2. **CI Workflow** (`.github/workflows/ci.yml`)
46+
47+
**Triggers:** Push to main, Pull requests, Workflow calls from default.yml
1048

1149
**Jobs:**
1250

1351
- **Test**: Runs on Node.js 22.x, 24.x
1452
- Checkout repository
1553
- Install dependencies (with npm cache)
16-
- Run linting with `xo`
17-
- Run tests with Vite
54+
- Run tests with Vitest
1855
- Upload test coverage to Codecov
1956
- **Build**: Builds package and uploads artifacts
2057
- Build with `microbundle`
2158
- Upload `dist/` and `examples/` as artifacts
2259
- **Lint Markdown**: Validates all Markdown files
2360

24-
### 2. **GitHub Pages Deployment** (`.github/workflows/deploy-pages.yml`)
61+
_Note: Linting has been moved to default.yml to avoid duplication_
62+
63+
### 3. **GitHub Pages Deployment** (`.github/workflows/deploy-pages.yml`)
2564

26-
**Triggers:** Push to main, Manual dispatch
65+
**Triggers:** Push to main, Manual dispatch, Workflow calls from default.yml
2766

2867
**Features:**
2968

@@ -37,7 +76,7 @@ This document describes all the GitHub Actions workflows and configurations set
3776

3877
**CDN Access:** `https://cdn.jsdelivr.net/npm/css-if-polyfill/dist/index.modern.js`
3978

40-
### 3. **Release Workflow** (`.github/workflows/release.yml`)
79+
### 4. **Release Workflow** (`.github/workflows/release.yml`)
4180

4281
**Triggers:** Git tags starting with `v*`
4382

@@ -47,33 +86,94 @@ This document describes all the GitHub Actions workflows and configurations set
4786
- **GitHub Release**: Creates GitHub release with changelog
4887
- **npm Publish**: Publishes to npm registry (requires `NPM_TOKEN` secret)
4988

50-
### 4. **Code Quality** (`.github/workflows/quality.yml`)
89+
### 5. **Code Quality** (`.github/workflows/quality.yml`)
5190

52-
**Triggers:** Push to main/develop, Pull requests
91+
**Triggers:** Push to main/develop, Pull requests, Workflow calls from default.yml
5392

5493
**Features:**
5594

56-
- Comprehensive linting with detailed reports
57-
- Test coverage analysis
58-
- Bundle size reporting
95+
- Test coverage analysis with detailed reports
96+
- Bundle size analysis
5997
- Security vulnerability scanning
60-
- CodeQL security analysis
6198
- Archives coverage reports as artifacts
6299

63-
### 5. **Documentation Updates** (`.github/workflows/docs.yml`)
100+
_Note: Comprehensive linting has been moved to default.yml to avoid duplication_
101+
102+
### 6. **Performance Testing** (`.github/workflows/performance.yml`)
103+
104+
**Triggers:** Push/PR to main (when src/ changes), Manual dispatch, Workflow calls from default.yml
105+
106+
**Features:**
107+
108+
- Runs performance benchmarks using Playwright
109+
- Tests initialization time and processing speed
110+
- Fails if performance thresholds are exceeded
111+
- Comments benchmark results on PRs
112+
- Uploads performance results as artifacts
113+
114+
### 7. **Security Analysis** (`.github/workflows/codeql.yml`)
64115

65-
**Triggers:** Push to main (when src/, examples/, or README.md changes), Manual dispatch
116+
**Triggers:** Push to main, Pull requests, Scheduled (weekly), Manual dispatch, Workflow calls from default.yml
66117

67118
**Features:**
68119

69-
- Auto-generates API documentation
70-
- Updates examples with latest syntax
71-
- Commits changes back to repository
72-
- Skips CI on documentation commits
120+
- Automated CodeQL security scanning for JavaScript and actions
121+
- Detects potential security vulnerabilities
122+
- Integrates with GitHub Security Advisory database
123+
- Runs weekly on schedule for continuous monitoring
73124

74-
### 6. **Performance Testing** (`.github/workflows/performance.yml`)
125+
### 8. **Release Workflow** (`.github/workflows/release.yml`)
126+
127+
**Triggers:** Push to main (changeset changes), Manual dispatch
128+
129+
**Features:**
130+
131+
- Integrated with Changesets for version management
132+
- Creates version PRs automatically
133+
- Publishes to npm with proper provenance
134+
- Generates GitHub releases with changelogs
135+
136+
_Note: This workflow remains independent as it handles specialized release processes_
137+
138+
## Workflow Architecture
139+
140+
### Parallel + Sequential Design
141+
142+
The new architecture optimizes for maximum efficiency with parallel analysis followed by sequential build-dependent tasks:
143+
144+
```text
145+
Default.yml (Orchestrator)
146+
├── Stage 1: Parallel Analysis (simultaneous)
147+
│ ├── Lint & Code Style
148+
│ ├── Quality Analysis (with embedded testing)
149+
│ └── Security Analysis (CodeQL)
150+
├── Stage 2: CI Tests & Build (requires all Stage 1)
151+
├── Stage 3: Performance Tests (conditional, requires Stage 2)
152+
├── Stage 4: Deploy (main only, requires Stages 2-3)
153+
└── Stage 5: Release (conditional, requires all previous stages)
154+
```
155+
156+
**Key Optimizations:**
157+
158+
- **3x faster Stage 1**: Parallel execution instead of sequential
159+
- **Embedded quality checks**: Tests run within quality job to avoid duplication
160+
- **Embedded security**: CodeQL runs inline instead of calling separate workflow
161+
- **Smart dependencies**: Build only happens after all analysis passes
162+
163+
### Standalone Workflows
164+
165+
Some workflows remain independent for specific use cases:
166+
167+
- **Release** (`release.yml`) - Handles changesets and publishing (now also integrated into default.yml)
168+
- **Individual workflows** - Can still be triggered independently for debugging
169+
170+
### Removed Duplication
75171

76-
**Triggers:** Push/PR to main (when src/ changes), Manual dispatch
172+
- **Linting**: Centralized in default.yml Stage 1
173+
- **Setup/Dependencies**: Managed per workflow but coordinated
174+
- **Build**: Streamlined through CI workflow
175+
- **Security**: Dedicated stage in pipeline
176+
- **Changeset workflow**: Removed duplicate `changeset.yml` (functionality preserved in `release.yml`)
77177

78178
**Features:**
79179

.github/workflows/ci.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ name: CI
22

33
on:
44
push:
5-
branches: [main, develop]
5+
branches: [main]
66
pull_request:
7-
branches: [main, develop]
7+
branches: [main]
8+
workflow_call: # Allow this workflow to be called by other workflows
89

910
jobs:
1011
test:
@@ -31,9 +32,6 @@ jobs:
3132
- name: Install dependencies
3233
run: npm ci
3334

34-
- name: Run linting
35-
run: npm run lint
36-
3735
- name: Run tests
3836
run: npm test
3937

.github/workflows/codeql.yml

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ name: "CodeQL Advanced"
1313

1414
on:
1515
push:
16-
branches: [ "main" ]
16+
branches: ["main"]
1717
pull_request:
18-
branches: [ "main" ]
18+
branches: ["main"]
1919
schedule:
20-
- cron: '18 7 * * 4'
20+
- cron: "18 7 * * 4"
2121
workflow_dispatch:
22+
workflow_call: # Allow this workflow to be called by other workflows
2223

2324
jobs:
2425
analyze:
@@ -44,10 +45,10 @@ jobs:
4445
fail-fast: false
4546
matrix:
4647
include:
47-
- language: actions
48-
build-mode: none
49-
- language: javascript-typescript
50-
build-mode: none
48+
- language: actions
49+
build-mode: none
50+
- language: javascript-typescript
51+
build-mode: none
5152
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift'
5253
# Use `c-cpp` to analyze code written in C, C++ or both
5354
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
@@ -57,50 +58,50 @@ jobs:
5758
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
5859
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
5960
steps:
60-
- name: Checkout repository
61-
uses: actions/checkout@v4
61+
- name: Checkout repository
62+
uses: actions/checkout@v4
6263

63-
# Add any setup steps before running the `github/codeql-action/init` action.
64-
# This includes steps like installing compilers or runtimes (`actions/setup-node`
65-
# or others). This is typically only required for manual builds.
66-
# - name: Setup runtime (example)
67-
# uses: actions/setup-example@v1
68-
- name: Setup Node.js
69-
uses: actions/setup-node@v4
70-
with:
71-
node-version-file: ".nvmrc"
72-
cache: "npm"
64+
# Add any setup steps before running the `github/codeql-action/init` action.
65+
# This includes steps like installing compilers or runtimes (`actions/setup-node`
66+
# or others). This is typically only required for manual builds.
67+
# - name: Setup runtime (example)
68+
# uses: actions/setup-example@v1
69+
- name: Setup Node.js
70+
uses: actions/setup-node@v4
71+
with:
72+
node-version-file: ".nvmrc"
73+
cache: "npm"
7374

74-
# Initializes the CodeQL tools for scanning.
75-
- name: Initialize CodeQL
76-
uses: github/codeql-action/init@v3
77-
with:
78-
languages: ${{ matrix.language }}
79-
build-mode: ${{ matrix.build-mode }}
80-
# If you wish to specify custom queries, you can do so here or in a config file.
81-
# By default, queries listed here will override any specified in a config file.
82-
# Prefix the list here with "+" to use these queries and those in the config file.
75+
# Initializes the CodeQL tools for scanning.
76+
- name: Initialize CodeQL
77+
uses: github/codeql-action/init@v3
78+
with:
79+
languages: ${{ matrix.language }}
80+
build-mode: ${{ matrix.build-mode }}
81+
# If you wish to specify custom queries, you can do so here or in a config file.
82+
# By default, queries listed here will override any specified in a config file.
83+
# Prefix the list here with "+" to use these queries and those in the config file.
8384

84-
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
85-
# queries: security-extended,security-and-quality
85+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
86+
# queries: security-extended,security-and-quality
8687

87-
# If the analyze step fails for one of the languages you are analyzing with
88-
# "We were unable to automatically build your code", modify the matrix above
89-
# to set the build mode to "manual" for that language. Then modify this step
90-
# to build your code.
91-
# ℹ️ Command-line programs to run using the OS shell.
92-
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
93-
- if: matrix.build-mode == 'manual'
94-
shell: bash
95-
run: |
96-
echo 'If you are using a "manual" build mode for one or more of the' \
97-
'languages you are analyzing, replace this with the commands to build' \
98-
'your code, for example:'
99-
echo ' make bootstrap'
100-
echo ' make release'
101-
exit 1
88+
# If the analyze step fails for one of the languages you are analyzing with
89+
# "We were unable to automatically build your code", modify the matrix above
90+
# to set the build mode to "manual" for that language. Then modify this step
91+
# to build your code.
92+
# ℹ️ Command-line programs to run using the OS shell.
93+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
94+
- if: matrix.build-mode == 'manual'
95+
shell: bash
96+
run: |
97+
echo 'If you are using a "manual" build mode for one or more of the' \
98+
'languages you are analyzing, replace this with the commands to build' \
99+
'your code, for example:'
100+
echo ' make bootstrap'
101+
echo ' make release'
102+
exit 1
102103
103-
- name: Perform CodeQL Analysis
104-
uses: github/codeql-action/analyze@v3
105-
with:
106-
category: "/language:${{matrix.language}}"
104+
- name: Perform CodeQL Analysis
105+
uses: github/codeql-action/analyze@v3
106+
with:
107+
category: "/language:${{matrix.language}}"

0 commit comments

Comments
 (0)