Skip to content

Commit d460705

Browse files
Merge pull request #74 from DSACMS/v1.2.0
V1.2.0
2 parents a1a4b7e + 60adecd commit d460705

21,697 files changed

Lines changed: 373 additions & 5186974 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/updateCodeJSON.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222

2323
- name: Update code.json
2424
id: generator
25-
uses: DSACMS/automated-codejson-generator@sachin/jsonValidationImplementation
25+
uses: DSACMS/automated-codejson-generator@v1.2.0
2626
with:
2727
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2828
ADMIN_TOKEN: ${{ secrets.ADMIN_PAT }}

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Dependency directory
2-
node_modules
2+
node_modules/
3+
4+
# Typescript build files
5+
dist/
36

47
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
58
# Logs
@@ -23,7 +26,7 @@ pids
2326
lib-cov
2427

2528
# Coverage directory used by tools like istanbul
26-
coverage
29+
coverage/
2730
*.lcov
2831

2932
# nyc test coverage

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ 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+
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+
4153
### Workflow and Branching
4254

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

README.md

Lines changed: 86 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,58 @@ A GitHub Action that automatically generates and maintains code.json files for f
66

77
This project provides a GitHub Action that helps federal agencies maintain their code.json files, which are required for compliance with the Federal Source Code Policy. The action automatically calculates and updates various metadata fields including labor hours, programming languages used, repository information, and timestamps. It can either create pull requests or push directly to branches (with appropriate permissions), making it easier to keep code.json files accurate and up-to-date.
88

9-
## Inputs
9+
## How It Works
1010

11-
```yaml
12-
GITHUB_TOKEN:
13-
description: "GitHub token used for API access and PR creation"
14-
required: true
15-
default: ${{ github.token }}
16-
17-
BRANCH:
18-
description: "Name of the branch to update"
19-
required: false
11+
**Automatic Generation**
2012

21-
SKIP_PR:
22-
description: "Try to push directly to branch first, fallback to PR if it fails. Requires ADMIN_TOKEN."
23-
required: false
24-
default: "false"
13+
- The action calculates metadata and creates a PR or pushes directly
14+
- Users can then fill in manual fields by editing the PR
2515

26-
ADMIN_TOKEN:
27-
description: "Personal Access Token with admin/write privileges for direct push. Required when SKIP_PR is true."
28-
required: false
29-
```
16+
**PR Validation**
3017

31-
## Outputs
18+
- When users edit code.json in a PR, validation runs automatically on every commit
19+
- The PR cannot be merged if validation fails (when branch protection is enabled)
20+
- Error messages help users fix issues quickly
21+
- Validation ensures only valid code.json reaches your main branch
3222

33-
```yaml
34-
updated:
35-
description: "Boolean indicating whether code.json was updated"
36-
pr_url:
37-
description: "URL of the created pull request if changes were made via PR"
38-
commit_sha:
39-
description: "SHA of the commit if pushed directly to branch"
40-
method_used:
41-
description: "Method used for the update: 'direct_push' or 'pull_request'"
42-
```
23+
**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.
4324

4425
## Workflow Examples
4526

4627
### Option 1: Direct Push
4728

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.
29+
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. Refer to this [section](https://github.com/DSACMS/automated-codejson-generator?tab=readme-ov-file#setting-up-personal-access-token-pat) for a guide to create the necessary Personal Access Token.
30+
31+
#### Direct Push Mode Limitations
32+
33+
**Important:** Direct push mode (`SKIP_PR: "true"`) will fall back to creating a pull request if:
34+
- Branch protection rules are enabled on the target branch
35+
- The PAT doesn't have sufficient permissions
36+
- Any other push restriction exists
37+
38+
This is expected behavior. If you need all updates to go through pull requests, use `SKIP_PR: "false"`.
39+
40+
##### When Direct Push Works
41+
- No branch protection on target branch
42+
- PAT has write access
43+
- No other repository restrictions
44+
45+
##### When It Falls Back to PR
46+
- Any branch protection enabled
47+
- Any push restrictions
48+
49+
**Recommendation:** For repositories with branch protection, use `SKIP_PR: "false"` to always create pull requests.
4950

5051
```yaml
5152
name: Update Code.json
5253
on:
5354
schedule:
5455
- cron: 0 0 1 * * # First day of every month
5556
workflow_dispatch:
57+
pull_request:
58+
types: [opened, synchronize]
59+
paths:
60+
- "code.json"
5661

5762
permissions:
5863
contents: write
@@ -73,7 +78,7 @@ jobs:
7378
uses: DSACMS/automated-codejson-generator@v1.2.0
7479
with:
7580
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76-
ADMIN_TOKEN: ${{ secrets.ADMIN_PAT }} # PAT with admin/push permissions
81+
ADMIN_TOKEN: ${{ secrets.ADMIN_PAT }} # PAT with admin/push permissions
7782
BRANCH: "main"
7883
SKIP_PR: "true"
7984

@@ -89,14 +94,18 @@ jobs:
8994
9095
### Option 2: Pull Request Only
9196
92-
This approach always creates a pull request, ensuring code review for all changes.
97+
This approach always creates a pull request for both automatic generation and validation of manual edits, ensuring code review for all changes.
9398
9499
```yaml
95100
name: Update Code.json
96101
on:
97102
schedule:
98103
- cron: 0 0 1 * * # First day of every month
99104
workflow_dispatch:
105+
pull_request:
106+
types: [opened, synchronize]
107+
paths:
108+
- "code.json"
100109

101110
permissions:
102111
contents: write
@@ -113,11 +122,49 @@ jobs:
113122
fetch-depth: 0
114123

115124
- name: Update code.json
116-
uses: DSACMS/automated-codejson-generator@latest
125+
uses: DSACMS/automated-codejson-generator@v1.2.0
117126
with:
118127
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
119128
BRANCH: "main"
120-
SKIP_PR: "false"
129+
SKIP_PR: "false"
130+
```
131+
132+
### Inputs
133+
134+
```yaml
135+
GITHUB_TOKEN:
136+
description: "GitHub token used for API access and PR creation"
137+
required: true
138+
default: ${{ github.token }}
139+
140+
BRANCH:
141+
description: "Name of the branch to update"
142+
required: false
143+
144+
SKIP_PR:
145+
description: "Try to push directly to branch first, fallback to PR if it fails. Requires ADMIN_TOKEN."
146+
required: false
147+
default: "false"
148+
149+
ADMIN_TOKEN:
150+
description: "Personal Access Token with admin/write privileges for direct push. Required when SKIP_PR is true."
151+
required: false
152+
```
153+
154+
### Outputs
155+
156+
```yaml
157+
updated:
158+
description: "Boolean indicating whether code.json was updated"
159+
160+
pr_url:
161+
description: "URL of the created pull request if changes were made via PR"
162+
163+
commit_sha:
164+
description: "SHA of the commit if pushed directly to branch"
165+
166+
method_used:
167+
description: "Method used for the update: 'direct_push' or 'pull_request'"
121168
```
122169
123170
## Setting Up Personal Access Token (PAT)
@@ -128,10 +175,10 @@ To use the direct push functionality, you'll need to create a Personal Access To
128175
129176
1. **Go to GitHub Settings**: Navigate to your GitHub account settings
130177
2. **Developer Settings**: Click on "Developer settings" in the left sidebar
131-
3. **Personal Access Tokens**: Choose "Tokens (classic)" or "Fine-grained tokens"
178+
3. **Personal Access Tokens**: Choose "Tokens (classic)"
132179
4. **Generate New Token**: Click "Generate new token"
133180
5. **Configure Token**:
134-
- **Name**: Give it a descriptive name like "Code.json Generator"
181+
- **Name**: Give it a name like "code.json Generator"
135182
- **Expiration**: Set appropriate expiration (recommend 90 days or 1 year)
136183
- **Scopes**:
137184
- For classic tokens: Select `repo` (full repository access)
@@ -149,8 +196,7 @@ To use the direct push functionality, you'll need to create a Personal Access To
149196
5. **Save**: Click "Add secret"
150197

151198
⚠️ _Please make sure the following are enabled within your Repository Action Settings in order to work properly_ ⚠️
152-
<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" />
153-
199+
<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" />
154200

155201
## Generation Context
156202

@@ -174,7 +220,7 @@ The automated code.json generator calculates specific fields by analyzing your r
174220

175221
**dateLastModified**: This uses your repository's last update timestamp, reflecting the most recent changes. No configuration needed.
176222

177-
**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.
223+
**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.
178224

179225
**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.
180226

@@ -214,6 +260,7 @@ An up-to-date list of core team members can be found in [MAINTAINERS.md](MAINTAI
214260
.
215261
├── src/
216262
│ ├── model.ts # TypeScript interfaces for code.json schema
263+
│ ├── validation.ts # Zod schema definitions and validation logic
217264
│ ├── main.ts # Main action logic
218265
│ ├── helper.ts # Helper functions for GitHub API interactions
219266
│ └── index.ts # Action entrypoint

code.json

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,10 @@
2828
"forks": 3,
2929
"clones": 0
3030
},
31-
"platforms": [
32-
"web",
33-
"linux"
34-
],
35-
"categories": [
36-
"developer-tools",
37-
"automation"
38-
],
31+
"platforms": ["web", "linux"],
32+
"categories": ["developer-tools", "automation"],
3933
"softwareType": "standalone/backend",
40-
"languages": [
41-
"TypeScript",
42-
"JavaScript"
43-
],
34+
"languages": ["TypeScript", "JavaScript"],
4435
"maintenance": "internal",
4536
"contractNumber": [],
4637
"SBOM": "https://github.com/DSACMS/automated-codejson-generator/network/dependencies",
@@ -50,11 +41,9 @@
5041
"date": {
5142
"created": "2025-02-07T16:29:38Z",
5243
"lastModified": "2025-10-02T14:32:07Z",
53-
"metaDataLastUpdated": "2025-10-03T14:08:54.770Z"
44+
"metadataLastUpdated": "2025-10-03T14:08:54.770Z"
5445
},
55-
"tags": [
56-
"cmsoss-tier2"
57-
],
46+
"tags": ["cmsoss-tier2"],
5847
"contact": {
5948
"email": "opensource@cms.hhs.gov",
6049
"name": "CMS Open Source Team"
@@ -66,15 +55,9 @@
6655
"userInput": false,
6756
"fismaLevel": "Low",
6857
"group": "CMS/OA/DSAC",
69-
"projects": [
70-
"SHARE IT Act"
71-
],
58+
"projects": ["SHARE IT Act"],
7259
"systems": [],
73-
"subsetInHealthcare": [
74-
"Operational"
75-
],
76-
"userType": [
77-
"Government"
78-
],
60+
"subsetInHealthcare": ["Operational"],
61+
"userType": ["Government"],
7962
"maturityModelTier": 3
80-
}
63+
}

dist/helper.d.ts

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

dist/index.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)