Skip to content

Commit ff7cd1d

Browse files
editied documentation
1 parent 8f25c15 commit ff7cd1d

2 files changed

Lines changed: 46 additions & 11 deletions

File tree

CONTRIBUTING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ npm run package
3838
npm test
3939
```
4040

41+
## Validation
42+
43+
The action uses [Zod](https://zod.dev/) for schema validation, automatically validating code.json in two scenarios:
44+
45+
### 1. Before Generation
46+
Every time the action generates or updates code.json (via schedule or workflow_dispatch), it validates the output before creating a PR or pushing. If validation fails, no changes are made.
47+
48+
### 2. On PR Edits
49+
When the `pull_request` trigger is configured, the action validates code.json whenever it's edited in a PR. This ensures users cannot accidentally merge invalid JSON.
50+
4151
### Workflow and Branching
4252

4353
We follow the [GitHub Flow Workflow](https://guides.github.com/introduction/flow/):

README.md

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,33 @@ ADMIN_TOKEN:
3333
```yaml
3434
updated:
3535
description: "Boolean indicating whether code.json was updated"
36+
3637
pr_url:
3738
description: "URL of the created pull request if changes were made via PR"
39+
3840
commit_sha:
3941
description: "SHA of the commit if pushed directly to branch"
42+
4043
method_used:
4144
description: "Method used for the update: 'direct_push' or 'pull_request'"
4245
```
4346
4447
## Workflow Examples
4548
46-
### Option 1: Direct Push
49+
### Option 1: Direct Push
4750
48-
This approach tries to push directly to the branch using a Personal Access Token, but falls back to creating a pull request if the direct push fails.
51+
This approach tries to push directly to the branch using a Personal Access Token, but falls back to creating a pull request if the direct push fails. When users need to edit code.json, they should create a PR which will automatically validate their changes.
4952
5053
```yaml
51-
name: Update Code.json (Smart Mode)
54+
name: Update Code.json
5255
on:
5356
schedule:
5457
- cron: 0 0 1 * * # First day of every month
5558
workflow_dispatch:
59+
pull_request:
60+
types: [opened, synchronize]
61+
paths:
62+
- 'code.json'
5663

5764
permissions:
5865
contents: write
@@ -89,14 +96,18 @@ jobs:
8996
9097
### Option 2: Pull Request Only
9198
92-
This approach always creates a pull request, ensuring code review for all changes.
99+
This approach always creates a pull request for both automatic generation and validation of manual edits, ensuring code review for all changes.
93100
94101
```yaml
95102
name: Update Code.json
96103
on:
97104
schedule:
98105
- cron: 0 0 1 * * # First day of every month
99106
workflow_dispatch:
107+
pull_request:
108+
types: [opened, synchronize]
109+
paths:
110+
- 'code.json'
100111

101112
permissions:
102113
contents: write
@@ -113,13 +124,27 @@ jobs:
113124
fetch-depth: 0
114125

115126
- name: Update code.json
116-
uses: DSACMS/automated-codejson-generator@latest
127+
uses: DSACMS/automated-codejson-generator@v1.2.0
117128
with:
118129
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
119130
BRANCH: "main"
120131
SKIP_PR: "false"
121132
```
122133
134+
### How It Works
135+
136+
**Automatic Generation**
137+
- The action calculates metadata, validates it, and creates a PR or pushes directly
138+
- Validation ensures only valid code.json is created
139+
- Users can then fill in manual fields by editing the PR
140+
141+
**PR Validation**
142+
- When users edit code.json in a PR, validation runs automatically on every commit
143+
- The PR cannot be merged if validation fails (when branch protection is enabled)
144+
- Error messages help users fix issues quickly
145+
146+
**Important:** For direct push mode, users should always create PRs when manually editing code.json to ensure validation runs. Direct edits to the main branch will not be validated by this action.
147+
123148
## Setting Up Personal Access Token (PAT)
124149
125150
To use the direct push functionality, you'll need to create a Personal Access Token:
@@ -128,14 +153,14 @@ To use the direct push functionality, you'll need to create a Personal Access To
128153
129154
1. **Go to GitHub Settings**: Navigate to your GitHub account settings
130155
2. **Developer Settings**: Click on "Developer settings" in the left sidebar
131-
3. **Personal Access Tokens**: Choose "Tokens (classic)" or "Fine-grained tokens"
156+
3. **Personal Access Tokens**: Choose "Tokens (classic)"
132157
4. **Generate New Token**: Click "Generate new token"
133158
5. **Configure Token**:
134-
- **Name**: Give it a descriptive name like "Code.json Generator"
159+
- **Name**: Give it a name like "code.json Generator"
135160
- **Expiration**: Set appropriate expiration (recommend 90 days or 1 year)
136161
- **Scopes**:
137-
- For classic tokens: Select `repo` (full repository access)
138-
- For fine-grained tokens: Select `Contents` (write) and `Metadata` (read)
162+
- Select `repo` (full repository access)
163+
6. **Store Token**: Copy and paste your token and store it for the next part
139164

140165
### Adding PAT to Repository
141166

@@ -148,8 +173,7 @@ To use the direct push functionality, you'll need to create a Personal Access To
148173
5. **Save**: Click "Add secret"
149174

150175
⚠️ _Please make sure the following are enabled within your Repository Action Settings in order to work properly_ ⚠️
151-
<img width="789" height="361" alt="Screenshot 2025-08-05 at 1 44 36 PM" src="https://github.com/user-attachments/assets/3795dc0e-c4c4-4378-8eb2-b7b9d861c08a" />
152-
176+
<img width="789" height="361" alt="Screenshot 2025-08-05 at 1 44 36 PM" src="https://github.com/user-attachments/assets/3795dc0e-c4c4-4378-8eb2-b7b9d861c08a" />
153177

154178
## Generation Context
155179

@@ -213,6 +237,7 @@ An up-to-date list of core team members can be found in [MAINTAINERS.md](MAINTAI
213237
.
214238
├── src/
215239
│ ├── model.ts # TypeScript interfaces for code.json schema
240+
│ ├── validation.ts # Zod schema definitions and validation logic
216241
│ ├── main.ts # Main action logic
217242
│ ├── helper.ts # Helper functions for GitHub API interactions
218243
│ └── index.ts # Action entrypoint

0 commit comments

Comments
 (0)