You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,6 +38,18 @@ npm run package
38
38
npm test
39
39
```
40
40
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
+
47
+
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.
48
+
49
+
### 2. On PR Edits
50
+
51
+
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.
52
+
41
53
### Workflow and Branching
42
54
43
55
We follow the [GitHub Flow Workflow](https://guides.github.com/introduction/flow/):
Copy file name to clipboardExpand all lines: README.md
+41-14Lines changed: 41 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,10 +33,13 @@ ADMIN_TOKEN:
33
33
```yaml
34
34
updated:
35
35
description: "Boolean indicating whether code.json was updated"
36
+
36
37
pr_url:
37
38
description: "URL of the created pull request if changes were made via PR"
39
+
38
40
commit_sha:
39
41
description: "SHA of the commit if pushed directly to branch"
42
+
40
43
method_used:
41
44
description: "Method used for the update: 'direct_push' or 'pull_request'"
42
45
```
@@ -45,14 +48,18 @@ method_used:
45
48
46
49
### Option 1: Direct Push
47
50
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.
49
52
50
53
```yaml
51
-
name: Update Code.json (Smart Mode)
54
+
name: Update Code.json
52
55
on:
53
56
schedule:
54
57
- cron: 0 0 1 * * # First day of every month
55
58
workflow_dispatch:
59
+
pull_request:
60
+
types: [opened, synchronize]
61
+
paths:
62
+
- "code.json"
56
63
57
64
permissions:
58
65
contents: write
@@ -73,7 +80,7 @@ jobs:
73
80
uses: DSACMS/automated-codejson-generator@v1.2.0
74
81
with:
75
82
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76
-
ADMIN_TOKEN: ${{ secrets.ADMIN_PAT }} # PAT with admin/push permissions
83
+
ADMIN_TOKEN: ${{ secrets.ADMIN_PAT }} # PAT with admin/push permissions
77
84
BRANCH: "main"
78
85
SKIP_PR: "true"
79
86
@@ -89,14 +96,18 @@ jobs:
89
96
90
97
### Option 2: Pull Request Only
91
98
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.
93
100
94
101
```yaml
95
102
name: Update Code.json
96
103
on:
97
104
schedule:
98
105
- cron: 0 0 1 * * # First day of every month
99
106
workflow_dispatch:
107
+
pull_request:
108
+
types: [opened, synchronize]
109
+
paths:
110
+
- "code.json"
100
111
101
112
permissions:
102
113
contents: write
@@ -113,13 +124,29 @@ jobs:
113
124
fetch-depth: 0
114
125
115
126
- name: Update code.json
116
-
uses: DSACMS/automated-codejson-generator@latest
127
+
uses: DSACMS/automated-codejson-generator@v1.2.0
117
128
with:
118
129
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
119
130
BRANCH: "main"
120
-
SKIP_PR: "false"
131
+
SKIP_PR: "false"
121
132
```
122
133
134
+
### How It Works
135
+
136
+
**Automatic Generation**
137
+
138
+
- The action calculates metadata, validates it, and creates a PR or pushes directly
139
+
- Validation ensures only valid code.json is created
140
+
- Users can then fill in manual fields by editing the PR
141
+
142
+
**PR Validation**
143
+
144
+
- When users edit code.json in a PR, validation runs automatically on every commit
145
+
- The PR cannot be merged if validation fails (when branch protection is enabled)
146
+
- Error messages help users fix issues quickly
147
+
148
+
**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.
149
+
123
150
## Setting Up Personal Access Token (PAT)
124
151
125
152
To use the direct push functionality, you'll need to create a Personal Access Token:
@@ -128,14 +155,14 @@ To use the direct push functionality, you'll need to create a Personal Access To
128
155
129
156
1. **Go to GitHub Settings**: Navigate to your GitHub account settings
130
157
2. **Developer Settings**: Click on "Developer settings" in the left sidebar
131
-
3. **Personal Access Tokens**: Choose "Tokens (classic)" or "Fine-grained tokens"
@@ -173,7 +199,7 @@ The automated code.json generator calculates specific fields by analyzing your r
173
199
174
200
**dateLastModified**: This uses your repository's last update timestamp, reflecting the most recent changes. No configuration needed.
175
201
176
-
**dateMetaDataLastUpdated**: The generator sets this to the current timestamp each time it runs, providing a record of when the metadata was last refreshed. No configuration needed.
202
+
**dateMetadataLastUpdated**: The generator sets this to the current timestamp each time it runs, providing a record of when the metadata was last refreshed. No configuration needed.
177
203
178
204
**feedbackMechanism**: The repository's issues URL in the format of {repositoryURL}/issues. If you already have a code.json file with existing feedback mechanisms, the generator preserves those values. No configuration needed.
179
205
@@ -213,6 +239,7 @@ An up-to-date list of core team members can be found in [MAINTAINERS.md](MAINTAI
213
239
.
214
240
├── src/
215
241
│ ├── model.ts # TypeScript interfaces for code.json schema
242
+
│ ├── validation.ts # Zod schema definitions and validation logic
216
243
│ ├── main.ts # Main action logic
217
244
│ ├── helper.ts # Helper functions for GitHub API interactions
0 commit comments