1// SPDX-License-Identifier: MIT
2
3package externals
4
5import "runtime"
6
7// Artifact is one pinned external tool: where it comes from and the SHA-256 of
8// the archive. The pins mirror actions/runner's Misc/externals.sh (node20
9// 20.20.2, node24 24.21.0), so a workflow sees the Node.js it would see on a
10// GitHub-hosted runner. The checksums of the nodejs.org builds come from the
11// official SHASUMS256.txt of each release (those of the alpine builds are the
12// digests of the GitHub release assets), and the archives are the .tar.gz ones
13// (the Go standard library has no xz).
14type Artifact struct {
15 // Name is the directory of the GitHub layout, below /home/runner/externals:
16 // node20, node24, node20_alpine, node24_alpine.
17 Name string
18 // Version is the Node.js version without the leading "v".
19 Version string
20 // Arch is GitHub's architecture name: x64 or arm64.
21 Arch string
22 // URL is the https location of the .tar.gz.
23 URL string
24 // SHA256 is the lower-case hex SHA-256 of the archive.
25 SHA256 string
26 // StripTop: the archive has one top directory to drop (nodejs.org); the
27 // actions/alpine_nodejs archives start at ./bin/node.
28 StripTop bool
29}
30
31// dirName is the directory of the artifact below the externals directory.
32func (a Artifact) dirName() string { return a.Name + "-" + a.Version + "-" + a.Arch }
33
34// The versions of actions/runner's externals.sh.
35const (
36 node20Version = "20.20.2"
37 node24Version = "24.21.0"
38)
39
40const (
41 nodeDist = "https://nodejs.org/dist/"
42 alpineDist = "https://github.com/actions/alpine_nodejs/releases/download/"
43)
44
45func nodejs(name, version, arch, sum string) Artifact {
46 return Artifact{
47 Name: name, Version: version, Arch: arch, SHA256: sum, StripTop: true,
48 URL: nodeDist + "v" + version + "/node-v" + version + "-linux-" + arch + ".tar.gz",
49 }
50}
51
52// alpine is a build of actions/alpine_nodejs (musl, x64 only), for job
53// containers based on Alpine.
54func alpine(name, version, sum string) Artifact {
55 return Artifact{
56 Name: name, Version: version, Arch: "x64", SHA256: sum,
57 URL: alpineDist + "v" + version + "/node-v" + version + "-alpine-x64.tar.gz",
58 }
59}
60
61// Pinned is every artifact the runner knows, for all architectures.
62var Pinned = []Artifact{
63 nodejs("node20", node20Version, "x64", "19e56f0825510207dd904f087fe52faa0a4eb6b2aab5f0ea7a33830d04888b8b"),
64 nodejs("node20", node20Version, "arm64", "47ef73d543ecf6eb19435f6c03a0ac4809b3bf0dd6b26c7c571efc2a6572a74d"),
65 nodejs("node24", node24Version, "x64", "6e1db87ef58b8819e5d5402eff1536491b18edd8eb7bee5ef7897876e88dc5ff"),
66 nodejs("node24", node24Version, "arm64", "724282c3b43aec998aa9527380465b45d229e021b58035f5f4f63095eabfe5d5"),
67 // actions/runner ships the alpine builds for x64 only. The checksums are
68 // those of the GitHub release assets.
69 alpine("node20_alpine", node20Version, "f21a2253025a5d1a14332a0b1ed48871689c5ca9aa37a6141428944b75de7d91"),
70 alpine("node24_alpine", node24Version, "2a4a9c6af9b6f1dd67e4c460474a6fbb64fafffe49e1166af80715bfd4e50775"),
71}
72
73// HostArch is GitHub's name for the architecture of this host ("" when the
74// runner has no build for it).
75func HostArch() string {
76 switch runtime.GOARCH {
77 case "amd64":
78 return "x64"
79 case "arm64":
80 return "arm64"
81 }
82 return ""
83}
84
85// ForArch selects the artifacts of one architecture, in table order.
86func ForArch(all []Artifact, arch string) []Artifact {
87 var out []Artifact
88 for _, a := range all {
89 if a.Arch == arch {
90 out = append(out, a)
91 }
92 }
93 return out
94}