Repository navigation
198 lines (180 loc) · 6.88 KB
/
Copy pathnpm-stage.yml
File metadata and controls
198 lines (180 loc) · 6.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
name: npm stage
on:
workflow_dispatch:
inputs:
version:
description: Version to stage, or "nightly" for a dated prerelease
required: true
type: string
default: nightly
d2_ref:
description: Exact D2 release tag to build, or empty for the dispatched master commit
required: false
type: string
default: ""
permissions:
contents: read
concurrency:
group: npm-stage
cancel-in-progress: false
jobs:
pack:
if: github.ref == 'refs/heads/master' && github.ref_protected
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
submodules: recursive
- name: Select the exact D2 release source
if: inputs.d2_ref != ''
env:
D2_REF: ${{ inputs.d2_ref }}
run: |
set -euo pipefail
if ! [[ "$D2_REF" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z]+([.-][0-9A-Za-z]+)*)?$ ]]; then
echo "d2_ref must be a v-prefixed semantic-version tag" >&2
exit 1
fi
source_commit=$(git rev-parse --verify "refs/tags/$D2_REF^{commit}")
git merge-base --is-ancestor "$source_commit" "$GITHUB_SHA"
git checkout --detach "$source_commit"
git submodule update --init --recursive
echo "Building D2 $D2_REF from $source_commit" >>"$GITHUB_STEP_SUMMARY"
- uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: ./go.mod
cache: true
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: "24"
registry-url: https://registry.npmjs.org
package-manager-cache: false
- name: Install supported npm and Bun
run: |
npm install --global npm@12.2.3 bun@1.4.5
npm --version
bun --version
- name: Install the selected release's WASM toolchain
run: |
if [ -x ./ci/install-wasm-tools.sh ]; then
exec ./ci/install-wasm-tools.sh
fi
# Release tags built with standard Go used Binaryen 131.
BINARYEN_VERSION="version_131"
BINARYEN_SHA256="b5bf1f0eaf17c63ee588ff7a5954dc8f6ce2c26989051c66f24dfe9ece3e46db"
BINARYEN_ARCHIVE="$RUNNER_TEMP/binaryen-${BINARYEN_VERSION}-x86_64-linux.tar.gz"
curl -fsSL \
"https://github.com/WebAssembly/binaryen/releases/download/${BINARYEN_VERSION}/binaryen-${BINARYEN_VERSION}-x86_64-linux.tar.gz" \
-o "$BINARYEN_ARCHIVE"
echo "$BINARYEN_SHA256 $BINARYEN_ARCHIVE" | sha256sum --check --strict
tar -xzf "$BINARYEN_ARCHIVE" -C "$RUNNER_TEMP"
sudo cp "$RUNNER_TEMP/binaryen-${BINARYEN_VERSION}"/bin/* /usr/local/bin/
wasm-opt --version
- name: Build, test, and pack both package identities
env:
NPM_PACKAGE_TARGET: both
NPM_PACK_DIR: ${{ runner.temp }}/npm-packages
NPM_PUBLISH_MODE: pack
NPM_VERSION: ${{ inputs.version }}
run: |
cd d2js/js
bun install --frozen-lockfile
./ci/build.sh
bun run test:all
git diff --exit-code
- name: Upload immutable package tarballs
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: npm-packages
path: ${{ runner.temp }}/npm-packages
if-no-files-found: error
compression-level: 0
stage:
name: stage-${{ matrix.package }}
needs: pack
runs-on: ubuntu-latest
timeout-minutes: 10
environment: npm-release
permissions:
contents: read
id-token: write
strategy:
fail-fast: false
matrix:
package:
- d2lang
- terrastruct
steps:
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: "24"
registry-url: https://registry.npmjs.org
package-manager-cache: false
- name: Install supported npm
run: |
npm install --global npm@12.2.3
npm --version
- name: Download immutable package tarballs
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: npm-packages
path: ${{ runner.temp }}/npm-packages
- name: Verify and stage package for review
env:
PACKAGE_KEY: ${{ matrix.package }}
run: |
set -euo pipefail
manifest="$RUNNER_TEMP/npm-packages/manifest.json"
case "$PACKAGE_KEY" in
d2lang) package_name=@d2lang/d2 ;;
terrastruct) package_name=@terrastruct/d2 ;;
*)
echo "unexpected package key: $PACKAGE_KEY" >&2
exit 1
;;
esac
metadata=$(node - "$manifest" "$package_name" <<'NODE'
const fs = require('fs');
const manifest = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'));
const packageName = process.argv[3];
const record = manifest.packages && manifest.packages[packageName];
if (manifest.schemaVersion !== 1 || !record) {
process.exit(1);
}
process.stdout.write([
manifest.version,
manifest.tag,
record.filename,
record.shasum,
record.integrity,
].join('\t'));
NODE
)
IFS=$'\t' read -r version tag filename expected_shasum expected_integrity <<<"$metadata"
if [[ -z "$version" || -z "$tag" || -z "$filename" ||
"$filename" != "${filename##*/}" ]]; then
echo "invalid npm package manifest" >&2
exit 1
fi
tarball="$RUNNER_TEMP/npm-packages/$filename"
test -f "$tarball"
node - "$tarball" "$expected_shasum" "$expected_integrity" <<'NODE'
const crypto = require('crypto');
const fs = require('fs');
const bytes = fs.readFileSync(process.argv[2]);
const expectedShasum = process.argv[3];
const expectedIntegrity = process.argv[4];
const shasum = crypto.createHash('sha1').update(bytes).digest('hex');
const integrity = `sha512-${crypto.createHash('sha512').update(bytes).digest('base64')}`;
if (shasum !== expectedShasum || integrity !== expectedIntegrity) {
throw new Error('npm tarball integrity mismatch');
}
NODE
tar -xOzf "$tarball" package/package.json | jq -e \
--arg name "$package_name" \
--arg version "$version" \
'.name == $name and .version == $version and .publishConfig.access == "public"' \
>/dev/null
npm stage publish "$tarball" --tag "$tag"