Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(ci): publish SDK tarballs by an unambiguous path, no cache

Yudhi Armyndharisf380cec36137
diff --git a/.github/workflows/java-sdk-release.yml b/.github/workflows/java-sdk-release.yml
index 0e9468097..275493c96 100644
--- a/.github/workflows/java-sdk-release.yml
+++ b/.github/workflows/java-sdk-release.yml
@@ -111,12 +111,15 @@ jobs:
exit 1
fi
+ # No `cache: maven` here. The cache is written by jobs that run third-party test code (the verify
+ # job above and sdk-ci.yml on main), and this job executes the gpg and publishing plugins from the
+ # local repository with the signing key and the Central token in its environment, so a restored
+ # plugin jar would run with both. The plugins are resolved from Maven Central instead.
- name: Set up JDK + signing key
uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1
with:
distribution: temurin
java-version: '17'
- cache: maven
server-id: central
server-username: MAVEN_CENTRAL_USERNAME
server-password: MAVEN_CENTRAL_PASSWORD
diff --git a/.github/workflows/js-sdk-release.yml b/.github/workflows/js-sdk-release.yml
index 29275b09f..72f544564 100644
--- a/.github/workflows/js-sdk-release.yml
+++ b/.github/workflows/js-sdk-release.yml
@@ -135,5 +135,7 @@ jobs:
- 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.
- run: npm publish package/*.tgz --access public --ignore-scripts
+ # passing it is redundant. --access public is explicit because the package is scoped. The
+ # tarball is named by its absolute path because npm reads `package/file.tgz` as the GitHub
+ # shorthand user/repo, which the pinned npm refuses to fetch.
+ run: npm publish "$GITHUB_WORKSPACE"/package/*.tgz --access public --ignore-scripts
diff --git a/src/common/ci-privilege-gate.spec.ts b/src/common/ci-privilege-gate.spec.ts
index 6832d543f..658835c89 100644
--- a/src/common/ci-privilege-gate.spec.ts
+++ b/src/common/ci-privilege-gate.spec.ts
@@ -371,6 +371,60 @@ describe('a job that can mint a publish credential pins global npm installs and
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]' }]);
});
+
+ // npm reads `dir/file.tgz` as the GitHub shorthand user/repo (hosted-git-info is tried before the file
+ // check), and the pinned npm refuses git specs by default, so a tarball is named by an absolute path.
+ it('js-sdk-release.yml: the publish step names the tarball in a form npm reads as a file', () => {
+ const runs = oidcJobRuns('js-sdk-release.yml')
+ .map(({ run }) => run)
+ .join('\n');
+ const target = /\bnpm publish\s+(?:-\S+\s+)*(\S+)/.exec(runs)?.[1] ?? '';
+ expect(target).toMatch(/^(?:"?\$\{?GITHUB_WORKSPACE\}?"?|)\/[^\s]*\.tgz$/);
+ });
+
+ // The caches a setup action restores are written by jobs that run third-party test code. A job that
+ // holds a publish credential executes what it restores, with that credential in its environment.
+ it.each(workflows.filter(file => /-sdk-release\.yml$/.test(file)))(
+ '%s: a job that holds a publish credential restores no cache',
+ file => {
+ const workflow = yaml.load(fs.readFileSync(path.join(workflowDir, file), 'utf8')) as OidcWorkflow;
+ const holdsCredential = (def: OidcJob): boolean =>
+ grantsIdToken(def.permissions !== undefined ? def.permissions : workflow.permissions) ||
+ (def.steps ?? []).some(step => /\bsecrets\.(?!GITHUB_TOKEN\b)/.test(JSON.stringify([step.env, step.with])));
+ const offenders = Object.entries(workflow.jobs ?? {})
+ .filter(([, def]) => holdsCredential(def))
+ .flatMap(([job, def]) =>
+ (def.steps ?? [])
+ .filter(step => {
+ const inputs = (step.with ?? {}) as Record<string, unknown>;
+ return (step.uses ?? '').startsWith('actions/cache') || inputs.cache !== undefined;
+ })
+ .map(step => `${job}: ${step.uses ?? step.name ?? 'step'} restores a cache`),
+ );
+ expect(offenders).toEqual([]);
+ },
+ );
+
+ it('finds a cache restored beside a publish credential', () => {
+ const workflow: OidcWorkflow = {
+ jobs: {
+ publish: {
+ steps: [
+ {
+ uses: 'actions/setup-java@v6',
+ with: { cache: 'maven', 'gpg-private-key': '${{ secrets.GPG_PRIVATE_KEY }}' },
+ },
+ ],
+ },
+ },
+ };
+ const hits = Object.values(workflow.jobs ?? {}).filter(def =>
+ (def.steps ?? []).some(
+ step => /\bsecrets\./.test(JSON.stringify(step.with)) && (step.with as { cache?: string }).cache,
+ ),
+ );
+ expect(hits).toHaveLength(1);
+ });
});
/**