Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
ci(sdk): keep project code out of jobs that hold a publish credential
Yudhi Armyndharis032c3c0fa4dd
diff --git a/.github/workflows/java-sdk-release.yml b/.github/workflows/java-sdk-release.ymlindex 890f87d05..0e9468097 100644--- a/.github/workflows/java-sdk-release.yml+++ b/.github/workflows/java-sdk-release.yml@@ -18,12 +18,17 @@ permissions:contents: readjobs:- publish:+ # The project's own tests and every test dependency run here, in a job that holds no credential and+ # no signing key. The deploy job below rebuilds the same commit with the tests skipped, so third-party+ # test code never executes beside the Maven Central token and the GPG key.+ verify:runs-on: ubuntu-latesttimeout-minutes: 30defaults:run:working-directory: sdk/java+ permissions:+ contents: readsteps:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7@@ -61,6 +66,31 @@ jobs:fiecho "Tag $REF_NAME matches pom.xml $POM_VERSION"+ - name: Set up JDK+ uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1+ with:+ distribution: temurin+ java-version: '17'+ cache: maven++ # The same gate sdk-ci.yml runs on every SDK change: the artifact published to Maven Central is+ # built from a commit whose `mvn verify` passed.+ - name: Verify+ run: mvn -B verify++ publish:+ # Runs only after the guards and the full test run above passed.+ needs: verify+ runs-on: ubuntu-latest+ timeout-minutes: 30+ defaults:+ run:+ working-directory: sdk/java+ permissions:+ contents: read+ steps:+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7+- name: Guard — publish credentials are presentenv:MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}@@ -93,11 +123,11 @@ jobs:gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}gpg-passphrase: GPG_PASSPHRASE- # No -DskipTests: the artifact published to Maven Central must be the one `mvn verify`- # proved, matching what sdk-ci.yml gates on every SDK change.+ # -DskipTests: the verify job already ran every test on this commit, without credentials; running+ # them again here would execute test code beside the token and the signing key.- name: Deploy to Maven Centralenv:MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}- run: mvn -B -Prelease deploy+ run: mvn -B -Prelease deploy -DskipTestsdiff --git a/.github/workflows/js-sdk-release.yml b/.github/workflows/js-sdk-release.ymlindex 937918155..29275b09f 100644--- a/.github/workflows/js-sdk-release.yml+++ b/.github/workflows/js-sdk-release.yml@@ -25,7 +25,11 @@ permissions:contents: readjobs:- publish:+ # Everything that installs or runs third-party code (the npm install, the test toolchain, the compiler+ # that builds dist/) runs here, in a job that cannot mint a publish credential. Those packages resolve+ # from the lockfile today but are code from many authors, so they must never share a job with+ # id-token: write. Same layout as python-sdk-release.yml.+ build:runs-on: ubuntu-latesttimeout-minutes: 15defaults:@@ -33,9 +37,6 @@ jobs:working-directory: sdk/javascriptpermissions:contents: read- # Mints the OIDC token npm exchanges for its short-lived publish credential. Without this the- # publish falls back to looking for a token and fails — it is the whole mechanism.- id-token: writesteps:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7@@ -69,26 +70,14 @@ jobs:- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7with:- # Trusted publishing needs Node >= 22.14.0; '22' resolves to the latest 22.x, which is well- # past that. No registry-url/NODE_AUTH_TOKEN: OIDC replaces the .npmrc token entirely.+ # '22' resolves to the latest 22.x. No registry-url/NODE_AUTH_TOKEN: nothing here publishes.node-version: '22'cache: 'npm'cache-dependency-path: sdk/javascript/package-lock.json- - name: Use an npm that supports trusted publishing- # The npm bundled with Node 22 predates OIDC publishing (needs >= 11.5.1), and it fails by- # looking for a token rather than by naming the missing support. Pinned to the exact release- # the Dockerfile uses: this npm runs while the job can mint a publish credential, so it must- # not float to whatever version is current when the tag is pushed.- run: |- npm install -g [email protected]- npm --version-- # The audit ci.yml runs over this tree, so a tag cannot publish what main would refuse. The- # package has no runtime dependencies, but its build and test toolchain runs here, in a job that- # can mint a publish credential, and builds the dist/ that ships. `npm audit` reads the lockfile- # alone, so it runs before the install executes any of that toolchain. It has no skip path: an- # npm audit outage fails the publish, and a re-run clears it.+ # The audit ci.yml runs over this tree, so a tag cannot publish what main would refuse. `npm audit`+ # reads the lockfile alone, so it runs before the install executes any of the toolchain. It has no+ # skip path: an npm audit outage fails the publish, and a re-run clears it.- run: npm audit --audit-level=high# --engine-strict: the tests below must not run on a Node the locked toolchain does not support.@@ -101,9 +90,50 @@ jobs:- run: npm run build- run: npm run smoke # packaging plus request smoke; must run after build+ # The tarball that passed the gates above is the one that ships: `npm pack` takes dist/ as built,+ # and the publish job uploads these bytes without a checkout or an install of its own.+ - name: Pack the package+ run: npm pack++ - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7+ with:+ name: js-sdk-package+ path: sdk/javascript/*.tgz+ if-no-files-found: error++ publish:+ # Runs only after the guards, the audit, the tests and the pack above all passed.+ needs: build+ runs-on: ubuntu-latest+ timeout-minutes: 15+ permissions:+ contents: read+ # Mints the OIDC token npm exchanges for its short-lived publish credential. Without this the+ # publish falls back to looking for a token and fails: it is the whole mechanism. No checkout and+ # no project install: this job only uploads the tarball the build job produced and tested.+ id-token: write+ steps:+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7+ with:+ # Trusted publishing needs Node >= 22.14.0; '22' resolves to the latest 22.x, which is well+ # past that.+ node-version: '22'++ - name: Use an npm that supports trusted publishing+ # The npm bundled with Node 22 predates OIDC publishing (needs >= 11.5.1), and it fails by+ # looking for a token rather than by naming the missing support. Pinned to the exact release+ # the Dockerfile uses: this npm runs while the job can mint a publish credential, so it must+ # not float to whatever version is current when the tag is pushed.+ run: |+ npm install -g [email protected]+ npm --version++ - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8+ with:+ name: js-sdk-package+ path: package/+- name: Publish to npm (trusted publishing, provenance automatic)# No --provenance flag: npm attaches provenance on its own for a trusted-publisher release, and# passing it is redundant. --access public is explicit because the package is scoped.- # --ignore-scripts skips prepublishOnly, which would rebuild dist/ after smoke: the dist/ that- # passed the gates above is the one that ships. prepublishOnly stays for a manual publish.- run: npm publish --access public --ignore-scripts+ run: npm publish package/*.tgz --access public --ignore-scriptsdiff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex fc3731a9f..d07780849 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -418,9 +418,11 @@ jobs:- name: Extract release notes from CHANGELOGid: changelog+ env:+ # Through the environment, not interpolated into the script: the value comes from the tag name.+ VERSION: ${{ steps.version.outputs.VERSION }}run: |# Extract the section for this version from CHANGELOG.md- VERSION="${{ steps.version.outputs.VERSION }}"NOTES=$(awk "/^## \[${VERSION}\]/{flag=1; next} /^## \[/{flag=0} flag" CHANGELOG.md)if [ -z "$NOTES" ]; thenNOTES="Release v${VERSION}"diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b75c0ba2d..c41c61f5e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -44,6 +44,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- ffmpeg runs with only `PATH`, `LD_LIBRARY_PATH`, `DYLD_LIBRARY_PATH`, `HOME`, `TMPDIR`, `TEMP`, `TMP`, `LANG`, `LC_ALL` and `SystemRoot` from the gateway's environment, so no secret reaches it or a wrapper script behind `FFMPEG_PATH`.- The release workflow keeps its staging image when a gate fails on a good build, so a re-run of the failed jobs finds it; an abandoned release leaves one stray tag.- The PHP SDK release pushes its tag with git hooks disabled.+- The JavaScript SDK release builds, tests and packs the tarball in a job without the publish credential, and a second job publishes that tarball; the Java SDK release runs its tests in a job without the Maven Central token and the signing key.+- The release workflow reads the version it extracts the release notes for from the environment instead of interpolating it into the script.- Dependabot watches the Python, Java, PHP and Go SDK manifests.### Fixeddiff --git a/sdk/java/README.md b/sdk/java/README.mdindex 9b61ed549..03f5e52de 100644--- a/sdk/java/README.md+++ b/sdk/java/README.md@@ -206,7 +206,8 @@ One-time setup (repository secrets):- `GPG_PRIVATE_KEY` — ASCII-armored signing key.- `GPG_PASSPHRASE` — passphrase for that key.-All four secrets are checked before anything is built, and a missing one **fails+A `verify` job runs the tests with none of them. The `publish` job that follows+checks all four secrets before it builds anything, and a missing one **failsthe run**. That is deliberate: skipping the deploy and reporting green isindistinguishable from a real release in the run list, so configure the secretsbefore tagging rather than tagging to see what happens.diff --git a/sdk/javascript/README.md b/sdk/javascript/README.mdindex f0249e642..fc19a65fe 100644--- a/sdk/javascript/README.md+++ b/sdk/javascript/README.md@@ -122,9 +122,10 @@ Cutting a release:version and never trigger an SDK publish.3. The workflow audits the SDK lockfile (`npm audit --audit-level=high`),re-runs the SDK's tests, typecheck, build and dual CJS/ESM smoke check- (packaging plus requests through each build's client), then publishes.- The published tarball is the one those gates passed, not a later- rebuild.+ (packaging plus requests through each build's client), then packs the+ tarball. A second job, the only one that can mint the publish credential,+ uploads that tarball and runs no project code: the published bytes are the+ ones those gates passed, not a later rebuild.## Licensediff --git a/src/common/ci-privilege-gate.spec.ts b/src/common/ci-privilege-gate.spec.tsindex 9b0c9bccd..6832d543f 100644--- a/src/common/ci-privilege-gate.spec.ts+++ b/src/common/ci-privilege-gate.spec.ts@@ -358,6 +358,19 @@ describe('a job that can mint a publish credential pins global npm installs andit.each(workflows)('%s: id-token jobs run no Python installer or build frontend', file => {expect(pythonInstallsInOidcJobs(file)).toEqual([]);});++ // The JavaScript SDK's toolchain (the install, the test runner, the compiler that builds dist/) is+ // third-party code as well. Its publish job uploads the tarball the build job made and tested, and+ // runs nothing but the pinned npm that publishes it.+ it('js-sdk-release.yml: the id-token job installs no project dependency and runs no project script', () => {+ const runs = oidcJobRuns('js-sdk-release.yml')+ .map(({ run }) => run)+ .join('\n');+ // Non-vacuity: the finder sees the publish step.+ expect(runs).toMatch(/\bnpm publish\b/);+ expect(runs).not.toMatch(/\bnpm[ \t]+(?:ci|test|run|audit|pack|exec|x|rebuild)\b|\bnpx\b/);+ expect(globalInstallsInOidcJobs('js-sdk-release.yml')).toEqual([{ job: 'publish', spec: '[email protected]' }]);+ });});/**diff --git a/src/common/release-gate-parity.spec.ts b/src/common/release-gate-parity.spec.tsindex 75a3e8fea..5ef2006ef 100644--- a/src/common/release-gate-parity.spec.ts+++ b/src/common/release-gate-parity.spec.ts@@ -255,7 +255,7 @@ describe('every npm tree is audited and kept current', () => {// tree from one path to the other is a deliberate edit here.it.each([['release.yml', 'lint', ['', 'dashboard']],- ['js-sdk-release.yml', 'publish', ['sdk/javascript']],+ ['js-sdk-release.yml', 'build', ['sdk/javascript']],])('%s %s audits exactly the trees it publishes', (file, job, published) => {const audits = releaseAudits(file, job);expect(audits.map(audit => audit.tree)).toEqual(published);@@ -265,11 +265,11 @@ describe('every npm tree is audited and kept current', () => {).toEqual([]);});- // `npm audit` reads the lockfile alone, so a high advisory stops the publish job before `npm ci`- // runs any of the toolchain while the job can mint a publish credential.+ // `npm audit` reads the lockfile alone, so a high advisory stops the build job before `npm ci`+ // runs any of the toolchain.it('js-sdk-release.yml audits the SDK before it installs it', () => {- const [audit] = releaseAudits('js-sdk-release.yml', 'publish');- const install = jobSteps('js-sdk-release.yml', 'publish').findIndex(step =>+ const [audit] = releaseAudits('js-sdk-release.yml', 'build');+ const install = jobSteps('js-sdk-release.yml', 'build').findIndex(step =>/^npm ci\b/.test(executableLines(step.run ?? '').trim()),);expect(install).toBeGreaterThan(-1);@@ -312,7 +312,7 @@ describe('every npm tree is audited and kept current', () => {describe('the JavaScript SDK tests run only on a Node their toolchain supports', () => {it.each([['sdk-ci.yml', 'javascript'],- ['js-sdk-release.yml', 'publish'],+ ['js-sdk-release.yml', 'build'],])('%s %s installs under --engine-strict wherever it runs npm test', (file, job) => {const steps = (yaml.load(fs.readFileSync(path.join(workflowDir, file), 'utf8')) as {