Skip to content

Commit 4b8449e

Browse files
authored
[PM-26935] Create a workflow for Claude code reviews (#456)
* Create an org workflow for Claude code reviews
1 parent 6732eec commit 4b8449e

File tree

5 files changed

+348
-2
lines changed

5 files changed

+348
-2
lines changed

.github/copilot-instructions.md renamed to .claude/CLAUDE.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# GitHub Copilot Instructions for Bitwarden GitHub Actions
1+
# Bitwarden GitHub Actions - Claude Code Configuration
22

33
## Repository Overview
44

55
This repository contains a collection of custom GitHub Actions used by Bitwarden to simplify and standardize CI/CD pipelines across their projects. The repository follows a modular structure where each action is self-contained in its own directory with its own `action.yml` file.
66

77
**Repository Details:**
8+
89
- **Type**: GitHub Actions collection
910
- **Size**: Medium-sized repository with ~20 custom actions
1011
- **Languages**: TypeScript, Python, JavaScript, Shell scripts, YAML
@@ -13,14 +14,17 @@ This repository contains a collection of custom GitHub Actions used by Bitwarden
1314
## Build and Validation Instructions
1415

1516
### Prerequisites
17+
1618
- Node.js (version 22+ for TypeScript actions)
1719
- Python 3.13+ (for Python-based actions)
1820
- Docker (for containerized actions)
1921

2022
### Initial Setup
23+
2124
1. **Always run `npm install` first** in the repository root to install development dependencies including Prettier, Husky, and lint-staged.
2225

2326
### Code Formatting and Linting
27+
2428
- **Code formatting**: This repository uses Prettier for all file types
2529
- **Pre-commit hooks**: Husky is configured to run lint-staged on commit
2630
- **Command**: `npx prettier --cache --write --ignore-unknown .` (formats all files)
@@ -51,32 +55,39 @@ Refer to the [rules directory](https://github.com/bitwarden/workflow-linter/tree
5155
**Python requirement**: Python 3.13+ with `pip install bitwarden_workflow_linter`
5256

5357
### Testing Individual Actions
58+
5459
Each action has its own test workflow in `.github/workflows/test-*.yml`:
60+
5561
- `test-version-bump.yml` - Tests version bumping functionality
56-
- `test-get-secrets.yml` - Tests Azure Key Vault integration
62+
- `test-get-secrets.yml` - Tests Azure Key Vault integration
5763
- `test-download-artifacts.yml` - Tests artifact downloading
5864
- `test-release-version-check.yml` - Tests release version validation
5965
- And others...
6066

6167
**Test execution**: Tests run automatically on PRs affecting specific action directories.
6268

6369
### TypeScript Actions Build Process
70+
6471
For TypeScript-based actions (e.g., `get-keyvault-secrets`):
72+
6573
1. Source files are in `src/` directory
6674
2. **Always run `npm run build`** or `tsc` to compile TypeScript to JavaScript
6775
3. Compiled output goes to `lib/` directory
6876
4. The `action.yml` references the compiled `lib/main.js` file
6977
5. **Critical**: Always commit both source AND compiled files
7078

7179
### Docker-based Actions
80+
7281
For containerized actions (e.g., `version-bump`, `get-checksum`):
82+
7383
- Use `Dockerfile` in action directory
7484
- Python scripts use `main.py` as entry point
7585
- **No local build required** - Docker builds during action execution
7686

7787
## Project Layout and Architecture
7888

7989
### Repository Structure
90+
8091
```
8192
/
8293
├── package.json # Root dependencies (Prettier, Husky, lint-staged)
@@ -101,31 +112,37 @@ For containerized actions (e.g., `version-bump`, `get-checksum`):
101112
### Key Actions by Type
102113

103114
**TypeScript/Node.js Actions:**
115+
104116
- `get-keyvault-secrets/` - Azure Key Vault integration
105117
- `download-artifacts/` - Artifact management
106118

107119
**Python/Docker Actions:**
120+
108121
- `version-bump/` - File version updating (JSON, XML, PLIST, YAML)
109122
- `get-checksum/` - SHA256 checksum generation
110123
- `crowdin/` - Translation management
111124

112125
**Shell/YAML Actions:**
126+
113127
- `azure-login/`, `azure-logout/` - Azure authentication
114128
- `setup-docker-trust/` - Docker configuration
115129
- Various reporting and utility actions
116130

117131
### CI/CD Validation Pipeline
118132

119133
**Pre-commit Checks:**
134+
120135
1. Prettier formatting (automatic via Husky)
121136
2. Lint-staged validation
122137

123138
**Pull Request Checks:**
139+
124140
1. Workflow linting (if `.github/workflows/` changed)
125141
2. Action-specific tests (if action directory changed)
126142
3. Various security and quality scans
127143

128144
**Critical Validation Steps:**
145+
129146
- **Workflow files**: Must pass `bitwarden_workflow_linter` validation
130147
- **TypeScript actions**: Must have compiled `lib/` output committed
131148
- **All files**: Must pass Prettier formatting
@@ -134,32 +151,38 @@ For containerized actions (e.g., `version-bump`, `get-checksum`):
134151
### Dependencies and Requirements
135152

136153
**Development Dependencies (root):**
154+
137155
- `prettier` - Code formatting
138156
- `husky` - Git hooks
139157
- `lint-staged` - Staged file processing
140158

141159
**Action-specific Dependencies:**
160+
142161
- TypeScript actions: `@actions/core`, `@actions/exec`, type definitions
143162
- Python actions: Standard library primarily, some use external packages
144163

145164
### File Patterns and Conventions
146165

147166
**Action Definition Files:**
167+
148168
- Every action directory MUST have an `action.yml` file
149169
- Branding should include `icon` and `color` properties
150170
- Input/output definitions follow GitHub Actions schema
151171

152172
**TypeScript Actions:**
173+
153174
- Source in `src/`, compiled output in `lib/`
154175
- Use `@actions/core` for GitHub Actions integration
155176
- `tsconfig.json` for TypeScript configuration
156177

157178
**Python Actions:**
179+
158180
- Main script typically named `main.py`
159181
- Use environment variables for input (`os.getenv("INPUT_*")`)
160182
- Docker-based execution via `Dockerfile`
161183

162184
**Testing:**
185+
163186
- Test workflows named `test-[action-name].yml`
164187
- Test fixtures in `tests/fixtures/` subdirectories
165188
- Tests validate action outputs and side effects
@@ -169,23 +192,27 @@ For containerized actions (e.g., `version-bump`, `get-checksum`):
169192
All code changes and action development must follow security best practices relevant to GitHub Actions and Bitwarden's standards:
170193

171194
**GitHub Actions Security:**
195+
172196
- **No hard-coded secrets or credentials** - Use secure parameter passing
173197
- **Validate all action inputs** - Sanitize and validate user-provided inputs to prevent injection attacks
174198
- **Use pinned action versions** - All external actions must be pinned to specific commit hashes (enforced by workflow linter)
175199
- **Minimize permissions** - Use least privilege principle for `permissions` in workflows
176200
- **Secure output handling** - Avoid exposing sensitive data in action outputs or logs
177201

178202
**Secret and Credential Management:**
203+
179204
- Use Azure Key Vault integration properly via `get-keyvault-secrets` action
180205
- Never log or expose secret values in action outputs
181206
- Use GitHub's secret masking capabilities (`core.setSecret()` in TypeScript actions)
182207

183208
**Supply Chain Security:**
209+
184210
- Only use approved actions listed in the workflow linter's approved actions list
185211
- Pin all dependencies to specific versions in `package.json` and `requirements.txt`
186212
- Validate Docker base images and use official, minimal images when possible
187213

188214
**Input Validation:**
215+
189216
- Validate file paths to prevent directory traversal attacks
190217
- Sanitize version strings and other user inputs
191218
- Use proper escaping when constructing shell commands
@@ -195,6 +222,7 @@ All code changes and action development must follow security best practices rele
195222
**Trust these instructions** and only perform additional searching if the information provided is incomplete or found to be incorrect. The repository follows consistent patterns, and the validation processes are well-established.
196223

197224
**When making changes:**
225+
198226
1. Always format code with Prettier before committing
199227
2. For TypeScript actions, always compile and commit the `lib/` output
200228
3. Test changes using the existing test workflows when possible
@@ -203,6 +231,7 @@ All code changes and action development must follow security best practices rele
203231
6. Apply security best practices and validate all inputs
204232

205233
**Common pitfalls to avoid:**
234+
206235
- Forgetting to compile TypeScript actions
207236
- Not running Prettier formatting
208237
- Missing required properties in `action.yml` files

.claude/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Claude Code Configuration
2+
3+
This directory contains Claude Code configuration files for the gh-actions repository.
4+
5+
## Directory Structure
6+
7+
```
8+
.claude/
9+
├── CLAUDE.md # General project context and guidelines
10+
├── commands/ # Custom slash commands
11+
│ └── review-pr.md # /review-pr command for PR reviews
12+
└── prompts/ # Workflow-specific prompts
13+
└── review-code.md # Used by review-code.yml workflow
14+
```
15+
16+
## Custom Commands
17+
18+
### `/review-pr` - Pull Request Review
19+
20+
Triggers a comprehensive PR code review in your current Claude Code session.
21+
22+
**Usage:**
23+
24+
1. Open Claude Code in this repository
25+
2. Check out the PR branch you want to review
26+
3. Tag @claude and type `/review-pr`
27+
28+
**What it does:**
29+
30+
- Analyzes code quality and best practices
31+
- Checks for security vulnerabilities
32+
- Validates workflow linter compliance
33+
- Reviews performance and efficiency
34+
- Provides structured feedback with action items
35+
36+
**Example:**
37+
38+
```
39+
@claude /review-pr
40+
```
41+
42+
## Automated Workflow Reviews
43+
44+
The `review-code.yml` workflow uses the `.claude/prompts/review-code.md` to automatically review PRs via GitHub Actions in each Bitwarden repo. The `review-code.md` is used as a gate to execute the `review-code.yml` workflow. Repos without this file will not see Claude code reviews performed on each pull request.
45+
46+
**How it works:**
47+
48+
1. Workflow triggers on non-draft PRs
49+
2. Reads `.claude/prompts/review-code.md` from the PR's branch
50+
3. Posts review as a sticky comment
51+
4. Updates comment on new commits
52+
53+
**To enable in our repos:**
54+
55+
1. Create `.claude/prompts/review-code.md` with review criteria
56+
2. Workflow runs automatically on subsequent pull requests
57+
58+
## Best Practices
59+
60+
- **Commands** (`.claude/commands/`): For interactive Claude Code sessions
61+
- **Prompts** (`.claude/prompts/`): For automated GitHub Actions workflows
62+
- **CLAUDE.md**: General project context available in all Claude interactions

.claude/commands/review-pr.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
description: Review the current pull request with comprehensive code analysis
3+
---
4+
5+
You are conducting a thorough pull request code review for the Bitwarden gh-actions repository.
6+
7+
## Current Context
8+
- Repository: bitwarden/gh-actions
9+
- This is a collection of reusable GitHub Actions workflows and custom actions
10+
- The code must follow Bitwarden's workflow linter rules
11+
- Security and reliability are paramount
12+
13+
## Review Instructions
14+
15+
Perform a comprehensive review of the current PR with focus on:
16+
17+
### 1. **Code Quality & Best Practices**
18+
- Adherence to GitHub Actions best practices
19+
- Proper error handling and validation
20+
- Code maintainability and clarity
21+
- Appropriate use of GitHub Actions syntax
22+
23+
### 2. **Security Implications**
24+
- No hardcoded secrets or credentials
25+
- Proper permission scoping
26+
- Input validation and sanitization
27+
- Protection against command injection
28+
- Safe handling of user-provided data
29+
30+
### 3. **Workflow Linter Compliance**
31+
Verify compliance with Bitwarden workflow linter rules:
32+
- Actions pinned to commit SHA with version comment
33+
- Permissions explicitly defined
34+
- Runner versions pinned (e.g., ubuntu-24.04)
35+
- Proper naming conventions (capitalized)
36+
- Only approved actions are used
37+
38+
### 4. **Performance & Efficiency**
39+
- Appropriate caching strategies
40+
- Parallel job execution where possible
41+
- Minimal redundant operations
42+
- Efficient use of GitHub Actions resources
43+
44+
### 5. **Testing & Validation**
45+
- Adequate test coverage for new features
46+
- Test workflows follow established patterns
47+
- Integration with existing test infrastructure
48+
49+
## Output Format
50+
51+
Provide a structured review with:
52+
53+
1. **Summary of Changes**
54+
- High-level overview of what this PR accomplishes
55+
- Key files modified and their impact
56+
57+
2. **Critical Issues** (if any)
58+
- Security vulnerabilities
59+
- Breaking changes
60+
- Non-compliant code that must be fixed
61+
62+
3. **Suggested Improvements**
63+
- Optimization opportunities
64+
- Better patterns or approaches
65+
- Documentation enhancements
66+
67+
4. **Good Practices Observed**
68+
- Notable positive aspects (be concise)
69+
- Correct security implementations
70+
- Well-structured code
71+
72+
5. **Action Items**
73+
- Specific tasks for the author
74+
- Priority level (Critical/High/Medium/Low)
75+
76+
Use collapsible `<details>` sections for lengthy explanations to keep the review readable.
77+
78+
**Important**: Focus on being thorough about issues and improvements. For good practices, be brief and just note what was done well.

.claude/prompts/review-code.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Please review this pull request with a focus on:
2+
- Code quality and best practices
3+
- Potential bugs or issues
4+
- Security implications
5+
- Performance considerations
6+
7+
Note: The PR branch is already checked out in the current working directory.
8+
9+
Provide a comprehensive review including:
10+
- Summary of changes since last review
11+
- Critical issues found (be thorough)
12+
- Suggested improvements (be thorough)
13+
- Good practices observed (be concise - list only the most notable items without elaboration)
14+
- Action items for the author
15+
- Leverage collapsible <details> sections where appropriate for lengthy explanations or code snippets to enhance human readability
16+
17+
When reviewing subsequent commits:
18+
- Track status of previously identified issues (fixed/unfixed/reopened)
19+
- Identify NEW problems introduced since last review
20+
- Note if fixes introduced new issues
21+
22+
IMPORTANT: Be comprehensive about issues and improvements. For good practices, be brief - just note what was done well without explaining why or praising excessively.

0 commit comments

Comments
 (0)