From 7b3384042f0ee6864a3065200b5fd3c9975df994 Mon Sep 17 00:00:00 2001 From: AjayBThorat-20 Date: Fri, 9 Oct 2026 00:16:26 +0530 Subject: [PATCH 1/2] ci: pin actions to commit SHAs, least-privilege permissions, cross-platform matrix - Pin every action to a full commit SHA (with its version as a comment) and set persist-credentials: false on checkouts. - Default workflow permissions to contents: read; jobs request only what they need. - Test on ubuntu/macos/windows x Node 20/22/24. Windows is informational (continue-on-error) until npm spawning and the grep-based unused fallback work there. - release.yml: publish via npm trusted publishing (OIDC, with provenance) instead of a long-lived NPM_TOKEN, and create the GitHub Release from the CHANGELOG automatically. - Move create-test-projects.sh into test/ and tidy .gitignore. --- .github/workflows/ci.yml | 52 +++++++++++++------ .github/workflows/codeql.yml | 13 +++-- .github/workflows/release.yml | 31 ++++++++--- .github/workflows/scorecard.yml | 6 +-- .gitignore | 9 +--- .../create-test-projects.sh | 0 6 files changed, 74 insertions(+), 37 deletions(-) rename create-test-projects.sh => test/create-test-projects.sh (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c67221a..6dc85cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,9 @@ on: pull_request: branches: [main] +permissions: + contents: read + jobs: version-guard: # Catches the two failure modes behind the npm/GitHub version desync @@ -18,13 +21,14 @@ jobs: # would fail on ordinary work, not just an actual version mistake. runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: fetch-depth: 0 + persist-credentials: false - - uses: actions/setup-node@v4 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 with: - node-version: '20' + node-version: '24' - name: Install dependencies run: npm ci @@ -68,22 +72,36 @@ jobs: } " - test-and-audit: - runs-on: ubuntu-latest + test: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + # '20' resolves to the latest 20.x, which satisfies engines' ^20.19.0 + # (the oldest Node with require(esm), needed for ESM-only uuid@14). + node: ['20', '22', '24'] + runs-on: ${{ matrix.os }} + # Windows is expected to fail for now: npm is spawned with + # execFileSync('npm'), which can't find npm.cmd on Windows, and the + # unused-dependency fallback shells out to grep, which Windows lacks by + # default. Informational until both are fixed; then drop this line to + # make Windows a real gate. + continue-on-error: ${{ matrix.os == 'windows-latest' }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false - - uses: actions/setup-node@v4 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 with: - node-version: '20' + node-version: ${{ matrix.node }} - - name: Install dependencies - run: npm ci + - run: npm ci - - name: Run test suite with coverage - run: npm run test:coverage + - run: npm run test:coverage - name: Audit for known vulnerabilities + if: matrix.os == 'ubuntu-latest' && matrix.node == '24' run: npm audit --audit-level=high integration-smoke: @@ -99,11 +117,13 @@ jobs: # informational rather than a merge gate for that reason. continue-on-error: true steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false - - uses: actions/setup-node@v4 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 with: - node-version: '20' + node-version: '24' - name: Install dependencies run: npm ci @@ -115,7 +135,7 @@ jobs: # generated on demand rather than committed — a fresh CI checkout # doesn't have them until this runs. - name: Generate test fixture projects - run: bash create-test-projects.sh + run: bash test/create-test-projects.sh - name: Install fixture project dependencies run: | diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 6c326ae..fdb2505 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -13,6 +13,9 @@ on: schedule: - cron: '17 3 * * 1' # weekly, Monday 03:17 UTC +permissions: + contents: read + jobs: analyze: runs-on: ubuntu-latest @@ -24,15 +27,17 @@ jobs: matrix: language: ['javascript-typescript'] steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false - - uses: github/codeql-action/init@v3 + - uses: github/codeql-action/init@1190a975f95ce23525efb6a3fc21ea29567c1b52 # v3.38.2 with: languages: ${{ matrix.language }} queries: security-extended - - uses: github/codeql-action/autobuild@v3 + - uses: github/codeql-action/autobuild@1190a975f95ce23525efb6a3fc21ea29567c1b52 # v3.38.2 - - uses: github/codeql-action/analyze@v3 + - uses: github/codeql-action/analyze@1190a975f95ce23525efb6a3fc21ea29567c1b52 # v3.38.2 with: category: '/language:${{ matrix.language }}' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d56a7fc..f3c09dd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,24 +5,35 @@ name: Release # tag that doesn't match package.json's version can never publish — this is # the automation that closes the gap the manual "tag it, then remember to # also run `npm publish`" workflow left open. +# +# Publishing uses npm trusted publishing (OIDC) — no NPM_TOKEN secret needed. on: push: tags: - 'v*.*.*' +permissions: + contents: read + jobs: publish: runs-on: ubuntu-latest permissions: - contents: read + contents: write # create the GitHub Release + id-token: write # npm trusted publishing (OIDC) steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false - - uses: actions/setup-node@v4 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 with: - node-version: '20' + node-version: '24' registry-url: 'https://registry.npmjs.org' + - name: Make sure npm supports trusted publishing (11.5.1+) + run: npm install -g npm@11 + - name: Install dependencies run: npm ci @@ -31,14 +42,20 @@ jobs: TAG_VERSION="${GITHUB_REF_NAME#v}" PACKAGE_VERSION=$(node -p "require('./package.json').version") if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then - echo "::error::Tag $GITHUB_REF_NAME (version $TAG_VERSION) does not match package.json version $PACKAGE_VERSION — refusing to publish." + echo "::error::Tag $GITHUB_REF_NAME does not match package.json version $PACKAGE_VERSION" exit 1 fi - name: Run tests run: npm test - - name: Publish to npm + - name: Publish to npm (no token; OIDC + provenance) run: npm publish + + - name: Create GitHub Release from CHANGELOG env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + GH_TOKEN: ${{ github.token }} + run: | + VERSION="${GITHUB_REF_NAME#v}" + awk -v v="$VERSION" '$0 ~ "^## \\[" v "\\]" { found=1; next } found && /^## \[/ { exit } found { print }' CHANGELOG.md > release-notes.md + gh release create "$GITHUB_REF_NAME" --title "$GITHUB_REF_NAME" --notes-file release-notes.md diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index 04015b6..5289b12 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -20,16 +20,16 @@ jobs: security-events: write id-token: write steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: persist-credentials: false - - uses: ossf/scorecard-action@v2.4.4 + - uses: ossf/scorecard-action@2d1146689b8cda280b9bc96326124645441f03bc # v2.4.4 with: results_file: results.sarif results_format: sarif publish_results: true - - uses: github/codeql-action/upload-sarif@v3 + - uses: github/codeql-action/upload-sarif@1190a975f95ce23525efb6a3fc21ea29567c1b52 # v3.38.2 with: sarif_file: results.sarif diff --git a/.gitignore b/.gitignore index e468562..10ba4fc 100644 --- a/.gitignore +++ b/.gitignore @@ -14,20 +14,14 @@ coverage/ *.tmp .cache/.npmrc .npmrc -.devcompass-cache.json .devcompass-backups/ devcompass-fix-report.json # Graph visualization outputs dependency-graph.html -final-test.html *.graph.html *.graph.json -test1.html -test1.json -test1-shallow.html -devcompass-v310-test/ -# DevCompass config (contains GitHub token) +# DevCompass config (tokens are stored in ~/.devcompass, not here) .devcompass/ knip.json @@ -37,6 +31,7 @@ knip.json test/* !test/unit/ !test/integration/ +!test/create-test-projects.sh # Internal growth/roadmap notes — not for the public repo plan/ \ No newline at end of file diff --git a/create-test-projects.sh b/test/create-test-projects.sh similarity index 100% rename from create-test-projects.sh rename to test/create-test-projects.sh From 36029a6cf53236a992a2696f9f6f4f63150191f9 Mon Sep 17 00:00:00 2001 From: AjayBThorat-20 Date: Fri, 9 Oct 2026 00:16:58 +0530 Subject: [PATCH 2/2] fix(test): stop create-test-projects.sh deleting itself Its cleanup step removes everything under test/ except unit/ and integration/. Now that the script itself lives in test/, it deleted its own tracked file every time it ran (unnoticed in CI, where the checkout is thrown away, but it wiped the file from a local working tree). --- test/create-test-projects.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/create-test-projects.sh b/test/create-test-projects.sh index bf5af65..8c59ca1 100755 --- a/test/create-test-projects.sh +++ b/test/create-test-projects.sh @@ -29,7 +29,7 @@ mkdir -p "$TEST_DIR" # actually runs (test/integration/test-complete-suite.sh calls this script # itself, then immediately tries to run scripts this find would otherwise # have just deleted). -find "$TEST_DIR" -mindepth 1 -maxdepth 1 ! -name 'unit' ! -name 'integration' -exec rm -rf {} + +find "$TEST_DIR" -mindepth 1 -maxdepth 1 ! -name 'unit' ! -name 'integration' ! -name 'create-test-projects.sh' -exec rm -rf {} + echo -e "${CYAN}📁 Created test directory: $TEST_DIR${NC}" echo ""