From 7570a787a2631a2c0e759e5854524cfe1ca14103 Mon Sep 17 00:00:00 2001 From: "Eric J. Smith" Date: Tue, 1 Dec 2026 19:06:19 -0600 Subject: [PATCH 1/2] Harden CI and publish workflow - Scope workflow permissions to contents: read; move npm release and GitHub Packages publishing into separate jobs that need the build and get id-token/packages write only where required. - Compute the version once and pass it to every job via job outputs. - Replace the global replace-in-files-cli install with scripts/set-version.mjs (Node built-ins only). - Pin actions to commit SHAs. - Only tolerate "already published" on GitHub Packages pushes. - Use setup-node npm caching, add a concurrency group, lint once on ubuntu, and test Node 22 on ubuntu. - Group example-app Dependabot updates separately from SDK updates. --- .github/dependabot.yml | 22 +++++ .github/workflows/build.yml | 172 +++++++++++++++++++++++++++--------- eslint.config.mjs | 2 +- scripts/set-version.mjs | 65 ++++++++++++++ 4 files changed, 218 insertions(+), 43 deletions(-) create mode 100644 scripts/set-version.mjs diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 2d0bfccd..60ce3392 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,6 +7,28 @@ updates: cooldown: default-days: 7 groups: + # Dependencies used only by the example apps, so a framework bump that + # breaks an example can't hold up SDK dependency updates. Dependencies + # shared with the SDK packages (react, react-native, typescript, ...) + # stay in npm-dependencies. The first matching group wins. + example-dependencies: + patterns: + - "@expo/*" + - "expo" + - "expo-*" + - "@react-native/*" + - "react-native-*" + - "@sveltejs/*" + - "svelte" + - "svelte-*" + - "@testing-library/*" + - "@vitejs/*" + - "vite" + - "@vue/*" + - "vue" + - "express" + - "jquery" + - "next" npm-dependencies: patterns: - "*" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e502bbc9..508da25c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,26 +3,24 @@ on: [push, pull_request] permissions: contents: read - id-token: write - packages: write + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: - build: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: - - ubuntu-latest - - macos-latest - - windows-latest - node_version: - - 24 - name: Node ${{ matrix.node_version }} on ${{ matrix.os }} + version: + name: Version + runs-on: ubuntu-latest + outputs: + version: ${{ steps.version.outputs.version }} + ci_tag: ${{ steps.version.outputs.ci_tag }} steps: - name: Checkout - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 + persist-credentials: false - name: Build Reason shell: bash run: | @@ -36,20 +34,10 @@ jobs: elif [[ "${GITHUB_REF}" = refs/pull* ]]; then branch="" fi - echo "GIT_BRANCH_SUFFIX=$branch" >> $GITHUB_ENV + echo "GIT_BRANCH_SUFFIX=$branch" >> "$GITHUB_ENV" echo "ref: $GITHUB_REF event: $GITHUB_EVENT_NAME branch_suffix: $branch" - - name: Setup Node.js environment - uses: actions/setup-node@v7 - with: - node-version: ${{ matrix.node_version }} - registry-url: "https://registry.npmjs.org" - - name: Cache node_modules - uses: actions/cache@v6 - with: - path: node_modules - key: ${{ matrix.node_version }}-${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }} - name: Setup .NET SDK for MinVer - uses: actions/setup-dotnet@v6 + uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0 with: dotnet-version: "10.0.x" - name: Build Version @@ -67,37 +55,137 @@ jobs: fi fi - echo "version=$version" >> $GITHUB_OUTPUT + ci_tag="${GIT_BRANCH_SUFFIX%.}" + ci_tag="${ci_tag:-main}" + ci_tag="ci-${ci_tag//\//-}" + + echo "version=$version" >> "$GITHUB_OUTPUT" + echo "ci_tag=$ci_tag" >> "$GITHUB_OUTPUT" echo "Version: $version" - echo "### Version: $version" >> $GITHUB_STEP_SUMMARY + echo "### Version: $version" >> "$GITHUB_STEP_SUMMARY" - npm install --global replace-in-files-cli - replace-in-files --string="3.0.0-dev" --replacement=$version packages/core/src/configuration/Configuration.ts - replace-in-files --string="3.0.0-dev" --replacement=$version **/package*.json - npm ci + build: + needs: version + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + - macos-latest + - windows-latest + node_version: + - 24 + include: + - os: ubuntu-latest + node_version: 22 + name: Node ${{ matrix.node_version }} on ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Setup Node.js environment + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: ${{ matrix.node_version }} + cache: npm + - name: Set Version + shell: bash + run: node scripts/set-version.mjs "$VERSION" + env: + VERSION: ${{ needs.version.outputs.version }} + - name: Install Dependencies + run: npm ci - name: Build run: npm run build - name: Lint + if: matrix.os == 'ubuntu-latest' && matrix.node_version == 24 run: npm run lint - name: Run Tests run: npm test + + # Publish jobs rebuild from a clean checkout so elevated permissions are only + # granted to the job that needs them. They skip dependency caching on purpose. + publish-npm: + name: Publish Release Packages + if: startsWith(github.ref, 'refs/tags/v') + needs: [version, build] + runs-on: ubuntu-latest + environment: npm-release + permissions: + contents: read + id-token: write + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Setup Node.js environment + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 24 + registry-url: "https://registry.npmjs.org" + package-manager-cache: false + - name: Set Version + run: node scripts/set-version.mjs "$VERSION" + env: + VERSION: ${{ needs.version.outputs.version }} + - name: Install Dependencies + run: npm ci + - name: Build + run: npm run build - name: Publish Release Packages - if: startsWith(github.ref, 'refs/tags/v') && matrix.os == 'ubuntu-latest' run: npm publish --workspaces --access public + + publish-github: + name: Push GitHub CI Packages + if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/heads/') && contains(needs.version.outputs.version, '-') + needs: [version, build] + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Setup Node.js environment + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 24 + package-manager-cache: false + - name: Set Version + run: node scripts/set-version.mjs "$VERSION" + env: + VERSION: ${{ needs.version.outputs.version }} + - name: Install Dependencies + run: npm ci + - name: Build + run: npm run build - name: Setup GitHub CI Node.js environment - if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/heads/') && matrix.os == 'ubuntu-latest' && contains(steps.version.outputs.version, '-') - uses: actions/setup-node@v7 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: - node-version: ${{ matrix.node_version }} + node-version: 24 registry-url: "https://npm.pkg.github.com" scope: "@exceptionless" + package-manager-cache: false - name: Push GitHub CI Packages - if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/heads/') && matrix.os == 'ubuntu-latest' && contains(steps.version.outputs.version, '-') shell: bash run: | - TAG_BRANCH="${GIT_BRANCH_SUFFIX%.}" - TAG_BRANCH="${TAG_BRANCH:-main}" - TAG_BRANCH="${TAG_BRANCH//\//-}" - npm publish --workspaces --access public --tag "ci-${TAG_BRANCH}" || true + # Re-runs of the same commit produce the same version; skip packages + # that already exist and let every other publish failure fail the job. + for dir in packages/*/; do + dir="${dir%/}" + name=$(node -p "require('./$dir/package.json').name") + existing=$(npm view "$name@$VERSION" version 2>/dev/null || true) + if [ "$existing" = "$VERSION" ]; then + echo "::notice::$name@$VERSION already exists in GitHub Packages; skipping." + continue + fi + npm publish --workspace "$dir" --access public --tag "$CI_TAG" + done env: - NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} + VERSION: ${{ needs.version.outputs.version }} + CI_TAG: ${{ needs.version.outputs.ci_tag }} + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/eslint.config.mjs b/eslint.config.mjs index c8767cec..f0eb2194 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -7,7 +7,7 @@ import tseslint from "typescript-eslint"; export default defineConfig( { - ignores: ["**/dist/", "**/node_modules/", ".agents/", "example/", "**/expo-plugin/", "**/react-native.config.*"] + ignores: ["**/dist/", "**/node_modules/", ".agents/", "example/", "**/expo-plugin/", "**/react-native.config.*", "scripts/"] }, eslint.configs.recommended, { diff --git a/scripts/set-version.mjs b/scripts/set-version.mjs new file mode 100644 index 00000000..f7bb132f --- /dev/null +++ b/scripts/set-version.mjs @@ -0,0 +1,65 @@ +#!/usr/bin/env node +// Stamps the computed build version over the "3.0.0-dev" placeholder in the +// core configuration, the root and workspace package.json files, and +// package-lock.json. Used by CI before `npm ci`; uses only Node built-ins. +// +// Usage: node scripts/set-version.mjs + +import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs"; +import { dirname, join, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; + +const PLACEHOLDER = "3.0.0-dev"; +const VERSION_PATTERN = /^\d+\.\d+\.\d+\S*$/; + +const version = process.argv[2]; +if (!version || !VERSION_PATTERN.test(version)) { + console.error(`Usage: node scripts/set-version.mjs (got: ${version ?? "nothing"})`); + process.exit(1); +} + +const root = resolve(dirname(fileURLToPath(import.meta.url)), ".."); +const rootPackage = JSON.parse(readFileSync(join(root, "package.json"), "utf8")); + +function workspaceDirs(patterns) { + return patterns.flatMap((pattern) => { + if (!pattern.endsWith("/*")) { + return [pattern]; + } + + const parent = pattern.slice(0, -2); + return readdirSync(join(root, parent), { withFileTypes: true }) + .filter((entry) => entry.isDirectory()) + .map((entry) => `${parent}/${entry.name}`); + }); +} + +const files = [ + "packages/core/src/configuration/Configuration.ts", + "package.json", + "package-lock.json", + ...workspaceDirs(rootPackage.workspaces ?? []) + .map((dir) => `${dir}/package.json`) + .filter((file) => existsSync(join(root, file))) +]; + +let total = 0; +for (const file of files) { + const path = join(root, file); + const content = readFileSync(path, "utf8"); + const parts = content.split(PLACEHOLDER); + if (parts.length === 1) { + continue; + } + + writeFileSync(path, parts.join(version)); + total += parts.length - 1; + console.log(`${file}: ${parts.length - 1} replacement(s)`); +} + +if (total === 0) { + console.error(`No "${PLACEHOLDER}" placeholders found; nothing was versioned.`); + process.exit(1); +} + +console.log(`Set version ${version} (${total} replacement(s) in total).`); From a51aa54e605726cb9a54f91bb4fd302236f983f7 Mon Sep 17 00:00:00 2001 From: "Eric J. Smith" Date: Tue, 1 Dec 2026 19:16:15 -0600 Subject: [PATCH 2/2] Publish CI packages in dependency order The packages/* glob published angularjs and browser before core, so a failed run could leave a CI tag on a package whose exact dependency version didn't exist. --- .github/workflows/build.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 508da25c..3c02af48 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -175,8 +175,9 @@ jobs: run: | # Re-runs of the same commit produce the same version; skip packages # that already exist and let every other publish failure fail the job. - for dir in packages/*/; do - dir="${dir%/}" + # Publish in the root workspace order (dependencies first) so a package is + # never published before the exact dependency version it requires. + for dir in $(node -p "require('./package.json').workspaces.filter((w) => w.startsWith('packages/')).join('\n')"); do name=$(node -p "require('./$dir/package.json').name") existing=$(npm view "$name@$VERSION" version 2>/dev/null || true) if [ "$existing" = "$VERSION" ]; then