Skip to content

Commit 61e97b2

Browse files
authored
test: verify artifact round-trip in CI (#26)
1 parent 9ed6b07 commit 61e97b2

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,69 @@ jobs:
102102
- name: Test packed-package fixtures
103103
run: npm run test:fixtures
104104

105+
artifact-pack:
106+
name: Pack the CI artifact
107+
runs-on: ubuntu-latest
108+
timeout-minutes: 15
109+
outputs:
110+
sha256: ${{ steps.pack.outputs.sha256 }}
111+
steps:
112+
- name: Check out the repository
113+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
114+
with:
115+
persist-credentials: false
116+
- name: Set up Node.js 24
117+
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
118+
with:
119+
node-version: 24.x
120+
cache: npm
121+
- name: Install locked dependencies
122+
run: npm ci
123+
- name: Pack exactly one artifact
124+
id: pack
125+
shell: bash
126+
run: |
127+
set -euo pipefail
128+
mkdir -p ci-artifacts
129+
npm pack --pack-destination ci-artifacts
130+
mapfile -t tarballs < <(find ci-artifacts -maxdepth 1 -type f -name '*.tgz' -print)
131+
if [[ "${#tarballs[@]}" -ne 1 ]]; then
132+
echo "Expected exactly one packed artifact, found ${#tarballs[@]}." >&2
133+
exit 1
134+
fi
135+
echo "sha256=$(sha256sum "${tarballs[0]}" | awk '{ print $1 }')" >> "$GITHUB_OUTPUT"
136+
- name: Upload the packed artifact
137+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
138+
with:
139+
name: ci-npm-package
140+
path: ci-artifacts/*.tgz
141+
if-no-files-found: error
142+
143+
artifact-download:
144+
name: Verify the CI artifact round-trip
145+
needs:
146+
- artifact-pack
147+
runs-on: ubuntu-latest
148+
timeout-minutes: 10
149+
steps:
150+
- name: Download the packed artifact by name
151+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
152+
with:
153+
name: ci-npm-package
154+
path: ci-artifacts
155+
- name: Verify the unique artifact and its digest
156+
env:
157+
EXPECTED_SHA256: ${{ needs.artifact-pack.outputs.sha256 }}
158+
shell: bash
159+
run: |
160+
set -euo pipefail
161+
mapfile -t tarballs < <(find ci-artifacts -maxdepth 1 -type f -name '*.tgz' -print)
162+
if [[ "${#tarballs[@]}" -ne 1 ]]; then
163+
echo "Expected exactly one downloaded artifact, found ${#tarballs[@]}." >&2
164+
exit 1
165+
fi
166+
echo "$EXPECTED_SHA256 ${tarballs[0]}" | sha256sum --check --strict
167+
105168
minimum-openai:
106169
name: Minimum OpenAI / Node.js 22
107170
runs-on: ubuntu-latest

tests/ci-workflow.test.mjs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,29 @@ describe("blocking CI workflow", () => {
122122
run: "npm run test:live-contract",
123123
});
124124
});
125+
126+
it("round-trips one packed artifact across separate jobs", () => {
127+
const jobs = readWorkflow().jobs;
128+
const pack = jobs?.["artifact-pack"];
129+
const download = jobs?.["artifact-download"];
130+
131+
expect(pack?.outputs).toEqual({
132+
sha256: "${{ steps.pack.outputs.sha256 }}",
133+
});
134+
expect(download?.needs).toEqual(["artifact-pack"]);
135+
expect(pack.steps.some((step) => step.run?.includes("npm pack"))).toBe(
136+
true,
137+
);
138+
expect(
139+
pack.steps.some((step) =>
140+
step.uses?.startsWith("actions/upload-artifact@"),
141+
),
142+
).toBe(true);
143+
expect(
144+
download.steps.some((step) =>
145+
step.uses?.startsWith("actions/download-artifact@"),
146+
),
147+
).toBe(true);
148+
expect(download.steps.at(-1).run).toContain("sha256sum --check --strict");
149+
});
125150
});

0 commit comments

Comments
 (0)