Skip to content

Commit 19f28ea

Browse files
edited README
1 parent bb025b0 commit 19f28ea

1 file changed

Lines changed: 97 additions & 6 deletions

File tree

README.md

Lines changed: 97 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,28 @@ A GitHub Action that automatically generates and maintains code.json files for f
44

55
## About the Project
66

7-
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 creates pull requests with these updates, making it easier to keep code.json files accurate and up-to-date.
7+
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

99
## Inputs
1010

1111
```yaml
1212
GITHUB_TOKEN:
13-
description: "GitHub token used for API access"
13+
description: "GitHub token used for API access and PR creation"
1414
required: true
1515
default: ${{ github.token }}
16+
17+
BRANCH:
18+
description: "Name of the branch to update"
19+
required: false
20+
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"
25+
26+
ADMIN_TOKEN:
27+
description: "Personal Access Token with admin/write privileges for direct push. Required when SKIP_PR is true."
28+
required: false
1629
```
1730
1831
## Outputs
@@ -21,12 +34,62 @@ GITHUB_TOKEN:
2134
updated:
2235
description: "Boolean indicating whether code.json was updated"
2336
pr_url:
24-
description: "URL of the created pull request if changes were made"
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'"
2542
```
2643
2744
## Workflow Examples
2845
29-
### Create a PR to add compliant code.json
46+
### Option 1: Direct Push
47+
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.
49+
50+
```yaml
51+
name: Update Code.json (Smart Mode)
52+
on:
53+
schedule:
54+
- cron: 0 0 1 * * # First day of every month
55+
workflow_dispatch:
56+
57+
permissions:
58+
contents: write
59+
pull-requests: write
60+
issues: write
61+
62+
jobs:
63+
update-code-json:
64+
runs-on: ubuntu-latest
65+
steps:
66+
- name: Checkout Repository
67+
uses: actions/checkout@v4
68+
with:
69+
fetch-depth: 0
70+
71+
- name: Update code.json
72+
id: update
73+
uses: DSACMS/automated-codejson-generator@v1.2.0
74+
with:
75+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76+
ADMIN_TOKEN: ${{ secrets.ADMIN_PAT }} # PAT with admin/push permissions
77+
BRANCH: "main"
78+
SKIP_PR: "true"
79+
80+
- name: Report update method
81+
run: |
82+
echo "Update successful: ${{ steps.update.outputs.updated }}"
83+
if [ "${{ steps.update.outputs.method_used }}" = "direct_push" ]; then
84+
echo "Direct push successful! Commit SHA: ${{ steps.update.outputs.commit_sha }}"
85+
elif [ "${{ steps.update.outputs.method_used }}" = "pull_request" ]; then
86+
echo "Created pull request: ${{ steps.update.outputs.pr_url }}"
87+
fi
88+
```
89+
90+
### Option 2: Pull Request Only
91+
92+
This approach always creates a pull request, ensuring code review for all changes.
3093
3194
```yaml
3295
name: Update Code.json
@@ -50,12 +113,40 @@ jobs:
50113
fetch-depth: 0
51114

52115
- name: Update code.json
53-
uses: DSACMS/automated-codejson-generator@v1.0.0
116+
uses: DSACMS/automated-codejson-generator@latest
54117
with:
55118
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56-
BRANCH: "main" # Make sure this is the name of your default branch!
119+
BRANCH: "main"
120+
SKIP_PR: "false"
57121
```
58122
123+
## Setting Up Personal Access Token (PAT)
124+
125+
To use the direct push functionality, you'll need to create a Personal Access Token:
126+
127+
### Creating a PAT
128+
129+
1. **Go to GitHub Settings**: Navigate to your GitHub account settings
130+
2. **Developer Settings**: Click on "Developer settings" in the left sidebar
131+
3. **Personal Access Tokens**: Choose "Tokens (classic)" or "Fine-grained tokens"
132+
4. **Generate New Token**: Click "Generate new token"
133+
5. **Configure Token**:
134+
- **Name**: Give it a descriptive name like "Code.json Generator"
135+
- **Expiration**: Set appropriate expiration (recommend 90 days or 1 year)
136+
- **Scopes**:
137+
- For classic tokens: Select `repo` (full repository access)
138+
- For fine-grained tokens: Select `Contents` (write) and `Metadata` (read)
139+
140+
### Adding PAT to Repository
141+
142+
1. **Repository Settings**: Go to your repository's Settings tab
143+
2. **Secrets and Variables**: Click on "Secrets and variables" → "Actions"
144+
3. **New Secret**: Click "New repository secret"
145+
4. **Configure Secret**:
146+
- **Name**: `ADMIN_PAT`
147+
- **Value**: Paste your Personal Access Token
148+
5. **Save**: Click "Add secret"
149+
59150
⚠️ _Please make sure the following are enabled within your Repository Action Settings in order to work properly_ ⚠️
60151
<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" />
61152

0 commit comments

Comments
 (0)