-
Notifications
You must be signed in to change notification settings - Fork 5
Auto-discover and verify new gov dependencie #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
haseebmalik18
wants to merge
15
commits into
DSACMS:dev
Choose a base branch
from
haseebmalik18:dsacms/haseeb/auto-update-gov-dependencies
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
589aca3
Add federal agency npm packages to gov dependencies
haseebmalik18 135b725
Add federal npm and PyPI dependencies and split gov-dependencies into…
haseebmalik18 8aef604
Add gov org allowlist and two-way package verifier
haseebmalik18 cfa9ca4
Add cached GitHub and npm org discovery
haseebmalik18 65b1845
Add data file codegen for verified entries
haseebmalik18 ebcca18
Add update orchestrator and report generation
haseebmalik18 dbfe2f8
Expand federal org allowlist
haseebmalik18 4a6b414
Handle discovery fetch failures without poisoning cache
haseebmalik18 89d7f59
Merge branch 'dev' into dsacms/haseeb/auto-update-gov-dependencies
haseebmalik18 794b4f1
Filter unpublished and private packages from discovery
haseebmalik18 67f0164
Trim allowlist to verified federal orgs
haseebmalik18 36d20b7
Document the gov-update modules for maintainers
haseebmalik18 a3ac229
Update the gov-update allowlist, tests, and README
haseebmalik18 d043286
Merge branch 'dev' into dsacms/haseeb/auto-update-gov-dependencies
haseebmalik18 daa5f5c
Add the weekly gov-dependencies update workflow
haseebmalik18 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| name: Update Gov Dependencies | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| schedule: | ||
| - cron: "0 6 * * 1" | ||
|
|
||
| jobs: | ||
| update-gov-dependencies: | ||
| runs-on: ubuntu-latest | ||
| # The first run has no cache and sweeps every allowlisted org, so it takes a | ||
| # while. Later runs only revisit repos that changed and finish much faster. | ||
| timeout-minutes: 360 | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: "20" | ||
| cache: "npm" | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install | ||
|
|
||
| # Discovery results record each repo's last push time, so a restored cache | ||
| # lets the run skip every repo that has not changed. The run id in the key | ||
| # means each run saves a fresh copy for the next one. | ||
| - name: Restore discovery cache | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: .gov-update-cache | ||
| key: gov-update-cache-${{ github.run_id }} | ||
| restore-keys: gov-update-cache- | ||
|
|
||
| - name: Discover and verify packages | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| GOV_UPDATE_CACHE: .gov-update-cache/repos.json | ||
| GOV_UPDATE_REPORT: gov-update-report.md | ||
| run: npm run update-gov-dependencies | ||
|
|
||
| - name: Check for changes | ||
| id: changes | ||
| run: | | ||
| if git diff --quiet -- src/gov-dependencies.data.ts; then | ||
| echo "changed=false" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "changed=true" >> $GITHUB_OUTPUT | ||
| fi | ||
|
|
||
| - name: Read report | ||
| if: steps.changes.outputs.changed == 'true' | ||
| id: report | ||
| run: | | ||
| { | ||
| echo "text<<GOV_UPDATE_REPORT_EOF" | ||
| cat gov-update-report.md | ||
| echo "GOV_UPDATE_REPORT_EOF" | ||
| } >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Create Pull Request | ||
| if: steps.changes.outputs.changed == 'true' | ||
| uses: peter-evans/create-pull-request@v6 | ||
| with: | ||
| commit-message: "chore: update federal dependency list" | ||
| title: "chore: update federal dependency list" | ||
| body: | | ||
| ${{ steps.report.outputs.text }} | ||
|
|
||
| Each package above passed verification: its registry metadata points | ||
| at a repository in an allowlisted federal organization, and that | ||
| repository declares the package name itself. | ||
|
|
||
| Anything listed as flagged was **not** added and needs a maintainer | ||
| to decide. Entries are only ever added, never removed automatically. | ||
| branch: automated/update-gov-dependencies | ||
| delete-branch: true | ||
| # The report and cache are build artifacts, so only the data file is | ||
| # allowed into the commit. | ||
| add-paths: src/gov-dependencies.data.ts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| import { describe, it, expect } from "@jest/globals"; | ||
| import { | ||
| addEntries, | ||
| existingKeys, | ||
| DataFileEntry, | ||
| } from "../../gov-update/codegen.js"; | ||
|
|
||
| const FIXTURE = `export interface ReusedCodeEntry { | ||
| name: string; | ||
| URL: string; | ||
| } | ||
|
|
||
| const DESIGN_SYSTEM: ReusedCodeEntry = { | ||
| name: "design-system (CMS)", | ||
| URL: "https://github.com/cmsgov/design-system", | ||
| }; | ||
|
|
||
| const NGX_TOOL: ReusedCodeEntry = { | ||
| name: "ngx-tool (GSA)", | ||
| URL: "https://github.com/gsa/ngx-tool", | ||
| }; | ||
|
|
||
| export const GOV_DEPENDENCIES: Record<string, ReusedCodeEntry> = { | ||
| "@gsa/ngx-tool": NGX_TOOL, | ||
| "design-system": DESIGN_SYSTEM, | ||
| }; | ||
|
|
||
| export const GOV_DEPENDENCIES_PYPI: Record<string, ReusedCodeEntry> = { | ||
| "design-system": DESIGN_SYSTEM, | ||
| }; | ||
| `; | ||
|
|
||
| describe("existingKeys", () => { | ||
| it("reads keys from both maps", () => { | ||
| expect([...existingKeys(FIXTURE, "npm")].sort()).toEqual([ | ||
| "@gsa/ngx-tool", | ||
| "design-system", | ||
| ]); | ||
| expect([...existingKeys(FIXTURE, "pypi")]).toEqual(["design-system"]); | ||
| }); | ||
| }); | ||
|
|
||
| describe("addEntries", () => { | ||
| it("inserts an unscoped npm key alphabetically with a new const", () => { | ||
| const entries: DataFileEntry[] = [ | ||
| { | ||
| eco: "npm", | ||
| key: "amortize", | ||
| displayName: "amortize (CFPB)", | ||
| url: "https://github.com/cfpb/amortize", | ||
| }, | ||
| ]; | ||
| const out = addEntries(FIXTURE, entries); | ||
| expect(out).toContain("const AMORTIZE: ReusedCodeEntry = {"); | ||
| expect(out).toContain(' name: "amortize (CFPB)",'); | ||
| const npmBlock = out.slice(out.indexOf("GOV_DEPENDENCIES:")); | ||
| expect(npmBlock.indexOf("amortize: AMORTIZE")).toBeLessThan( | ||
| npmBlock.indexOf('"design-system": DESIGN_SYSTEM'), | ||
| ); | ||
| }); | ||
|
|
||
| it("groups scoped npm keys among the existing scoped block", () => { | ||
| const entries: DataFileEntry[] = [ | ||
| { | ||
| eco: "npm", | ||
| key: "@cfpb/analytics", | ||
| displayName: "analytics (CFPB)", | ||
| url: "https://github.com/cfpb/analytics", | ||
| }, | ||
| ]; | ||
| const out = addEntries(FIXTURE, entries); | ||
| const npmBlock = out.slice( | ||
| out.indexOf("GOV_DEPENDENCIES:"), | ||
| out.indexOf("GOV_DEPENDENCIES_PYPI:"), | ||
| ); | ||
| expect(npmBlock).toContain('"@cfpb/analytics": CFPB_ANALYTICS'); | ||
| expect(npmBlock.indexOf("@cfpb/analytics")).toBeLessThan( | ||
| npmBlock.indexOf('"design-system": DESIGN_SYSTEM'), | ||
| ); | ||
| }); | ||
|
|
||
| it("reuses an existing const when the repo URL already appears", () => { | ||
| const entries: DataFileEntry[] = [ | ||
| { | ||
| eco: "npm", | ||
| key: "@cmsgov/design-system", | ||
| displayName: "design-system (CMS)", | ||
| url: "https://github.com/cmsgov/design-system", | ||
| }, | ||
| ]; | ||
| const out = addEntries(FIXTURE, entries); | ||
| expect(out).toContain('"@cmsgov/design-system": DESIGN_SYSTEM'); | ||
| expect(out.match(/const DESIGN_SYSTEM:/g)).toHaveLength(1); | ||
| }); | ||
|
|
||
| it("quotes keys that are not valid identifiers", () => { | ||
| const entries: DataFileEntry[] = [ | ||
| { | ||
| eco: "pypi", | ||
| key: "scikit-learn-gov", | ||
| displayName: "scikit-learn-gov (NIST)", | ||
| url: "https://github.com/usnistgov/scikit-learn-gov", | ||
| }, | ||
| ]; | ||
| const out = addEntries(FIXTURE, entries); | ||
| expect(out).toContain('"scikit-learn-gov": SCIKIT_LEARN_GOV'); | ||
| }); | ||
|
|
||
| it("prefixes const names that would start with a digit", () => { | ||
| const entries: DataFileEntry[] = [ | ||
| { | ||
| eco: "pypi", | ||
| key: "3d-viz", | ||
| displayName: "3d-viz (CMS)", | ||
| url: "https://github.com/cmsgov/3d-viz", | ||
| }, | ||
| ]; | ||
| const out = addEntries(FIXTURE, entries); | ||
| expect(out).toContain("const PKG_3D_VIZ: ReusedCodeEntry = {"); | ||
| expect(out).toContain('"3d-viz": PKG_3D_VIZ'); | ||
| }); | ||
|
|
||
| it("is idempotent-safe for keys already present", () => { | ||
| const before = existingKeys(FIXTURE, "npm").size; | ||
| const out = addEntries(FIXTURE, [ | ||
| { | ||
| eco: "npm", | ||
| key: "amortize", | ||
| displayName: "amortize (CFPB)", | ||
| url: "https://github.com/cfpb/amortize", | ||
| }, | ||
| ]); | ||
| expect(existingKeys(out, "npm").size).toBe(before + 1); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this section could you specifically list the commands to run the job so it is straightforward for future devs? Also just wanted to verify if the job is automated? I don't see a workflow file / code of when the job is triggered to run and makes the PR with the data list update but I could've missed something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just added, I wanted to keep it a seperate PR for adding the automated workflow to avoid crowding this PR, but in the interest of time it is probably best to just add it here.