Skip to content

Commit c0feca7

Browse files
committed
Update workflow & ts
1 parent 9b0267b commit c0feca7

4 files changed

Lines changed: 126 additions & 683 deletions

File tree

.github/workflows/ci.yml

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jobs:
88
runs-on: ubuntu-latest
99
# if: startsWith(github.ref, 'refs/tags/') || github.head_ref || ${{ env.ACT }}
1010
steps:
11-
- uses: actions/checkout@v3
12-
- uses: volta-cli/action@v4
11+
- uses: actions/checkout@v7
12+
- uses: volta-cli/action@v5
1313
with:
14-
node-version: 18
14+
node-version: 24
1515
- run: npm ci
1616
- run: npm run lint
1717
- run: npm run build
@@ -22,12 +22,13 @@ jobs:
2222
- uses: montudor/action-zip@v1
2323
with:
2424
args: zip -0 -qq -r node_modules.zip node_modules
25-
- uses: actions/upload-artifact@v3
25+
- uses: actions/upload-artifact@v4
2626
with:
2727
name: node-modules-artifact-${{ github.run_number }}
2828
retention-days: 1
2929
path: node_modules.zip
30-
- uses: actions/upload-artifact@v3
30+
compression-level: 0
31+
- uses: actions/upload-artifact@v4
3132
with:
3233
name: build-artifact-${{ github.run_number }}
3334
retention-days: 1
@@ -43,20 +44,20 @@ jobs:
4344
needs: build
4445
runs-on: ubuntu-latest
4546
steps:
46-
- uses: actions/download-artifact@v3
47+
- uses: actions/download-artifact@v4
4748
with:
4849
name: build-artifact-${{ github.run_number }}
49-
- uses: actions/download-artifact@v3
50+
- uses: actions/download-artifact@v4
5051
with:
5152
name: node-modules-artifact-${{ github.run_number }}
5253
- uses: montudor/action-zip@v1
5354
with:
5455
args: unzip -qq node_modules.zip -d .
5556
- uses: volta-cli/action@v4
5657
with:
57-
node-version: 18
58+
node-version: 24
5859
- run: npm run coverage
59-
- uses: actions/upload-artifact@v3
60+
- uses: actions/upload-artifact@v4
6061
with:
6162
name: coverage-${{ github.run_number }}
6263
retention-days: 1
@@ -71,13 +72,13 @@ jobs:
7172
needs: build
7273
strategy:
7374
matrix:
74-
node: ['7.10.1', 10, 16] # 18 is tested by coverage in build stage
75+
node: ['7.10.1', 10, 16, 18]
7576
runs-on: ubuntu-latest
7677
steps:
77-
- uses: actions/download-artifact@v3
78+
- uses: actions/download-artifact@v4
7879
with:
7980
name: build-artifact-${{ github.run_number }}
80-
- uses: actions/download-artifact@v3
81+
- uses: actions/download-artifact@v4
8182
with:
8283
name: node-modules-artifact-${{ github.run_number }}
8384
- uses: montudor/action-zip@v1
@@ -86,23 +87,4 @@ jobs:
8687
- uses: volta-cli/action@v4
8788
with:
8889
node-version: ${{ matrix.node }}
89-
- run: volta run --node ${{ matrix.node }} npm test
90-
91-
deploy:
92-
needs: [test, coverage]
93-
runs-on: ubuntu-latest
94-
environment: deploy
95-
if: startsWith(github.ref, 'refs/tags/')
96-
steps:
97-
# Setup .npmrc file to publish to npm
98-
- uses: actions/setup-node@v3
99-
with:
100-
node-version: 18
101-
registry-url: 'https://registry.npmjs.org'
102-
- uses: actions/download-artifact@v3
103-
with:
104-
name: build-artifact-${{ github.run_number }}
105-
- run: npm publish --access public
106-
if: ${{ !env.ACT }}
107-
env:
108-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
90+
- run: volta run --node ${{ matrix.node }} npm test

.github/workflows/publish.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: JsonStreamStringify-Publish
2+
3+
on:
4+
workflow_run:
5+
workflows: [JsonStreamStringify-CI]
6+
types: [completed]
7+
workflow_dispatch:
8+
inputs:
9+
ci_run_id:
10+
description: CI workflow run ID to download build-artifact from (defaults to latest successful CI run on --ref branch)
11+
required: false
12+
dry_run:
13+
description: Verify auth and tarball with npm publish --dry-run instead of publishing
14+
type: boolean
15+
default: true
16+
17+
permissions:
18+
id-token: write # Required for OIDC trusted publishing
19+
contents: read
20+
actions: read # Required to download artifacts from the CI workflow run
21+
22+
jobs:
23+
publish:
24+
runs-on: ubuntu-latest
25+
environment: deploy
26+
if: >
27+
github.event_name == 'workflow_dispatch' ||
28+
(github.event.workflow_run.conclusion == 'success' &&
29+
github.event.workflow_run.event == 'push' &&
30+
!github.event.workflow_run.head_branch)
31+
steps:
32+
- name: Resolve CI workflow run
33+
id: ci-run
34+
env:
35+
GH_TOKEN: ${{ github.token }}
36+
run: |
37+
if [ "${{ github.event_name }}" = "workflow_run" ]; then
38+
echo "run_id=${{ github.event.workflow_run.id }}" >> "$GITHUB_OUTPUT"
39+
echo "run_number=${{ github.event.workflow_run.run_number }}" >> "$GITHUB_OUTPUT"
40+
exit 0
41+
fi
42+
43+
if [ -n "${{ inputs.ci_run_id }}" ]; then
44+
run_id="${{ inputs.ci_run_id }}"
45+
else
46+
branch="${GITHUB_REF#refs/heads/}"
47+
run_id="$(gh api "repos/${{ github.repository }}/actions/workflows/JsonStreamStringify-CI/runs" \
48+
-f branch="$branch" \
49+
-f status=completed \
50+
-f event=push \
51+
--jq '.workflow_runs[] | select(.conclusion == "success") | .id' | head -1)"
52+
fi
53+
54+
if [ -z "$run_id" ]; then
55+
echo "::error::No successful CI run found. Run CI first or pass ci_run_id."
56+
exit 1
57+
fi
58+
59+
run_number="$(gh api "repos/${{ github.repository }}/actions/runs/$run_id" --jq '.run_number')"
60+
echo "run_id=$run_id" >> "$GITHUB_OUTPUT"
61+
echo "run_number=$run_number" >> "$GITHUB_OUTPUT"
62+
echo "Using CI run $run_id (#$run_number)"
63+
64+
- name: Verify build artifact exists
65+
env:
66+
GH_TOKEN: ${{ github.token }}
67+
run: |
68+
artifact_name="build-artifact-${{ steps.ci-run.outputs.run_number }}"
69+
count="$(gh api "repos/${{ github.repository }}/actions/runs/${{ steps.ci-run.outputs.run_id }}/artifacts" \
70+
--jq "[.artifacts[] | select(.name == \"$artifact_name\")] | length")"
71+
if [ "$count" -eq 0 ]; then
72+
echo "::error::Artifact $artifact_name not found on CI run ${{ steps.ci-run.outputs.run_id }}"
73+
exit 1
74+
fi
75+
echo "Found artifact: $artifact_name"
76+
77+
- uses: actions/setup-node@v6
78+
with:
79+
node-version: 24
80+
registry-url: 'https://registry.npmjs.org'
81+
package-manager-cache: false # never use caching in release builds
82+
83+
- uses: actions/download-artifact@v4
84+
with:
85+
name: build-artifact-${{ steps.ci-run.outputs.run_number }}
86+
github-token: ${{ secrets.GITHUB_TOKEN }}
87+
run-id: ${{ steps.ci-run.outputs.run_id }}
88+
89+
- name: Verify artifact contents
90+
run: |
91+
test -f package.json
92+
test -d lib
93+
npm pkg get name version
94+
95+
- name: Publish to npm
96+
if: ${{ !env.ACT }}
97+
run: |
98+
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.dry_run }}" = "true" ]; then
99+
echo "Dry run — validating tarball and registry auth without publishing"
100+
npm publish --dry-run
101+
else
102+
npm publish
103+
fi

0 commit comments

Comments
 (0)