Skip to content

Commit 3360bff

Browse files
authored
Add ability to specify OTP architecture (#316)
1 parent e5b6619 commit 3360bff

File tree

5 files changed

+101
-14
lines changed

5 files changed

+101
-14
lines changed

README.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ be the latest.
7171
This list presents the known working version combos between the target operating system
7272
and Erlang/OTP.
7373

74-
| Operating system | Erlang/OTP | Status
75-
|- |- |-
76-
| `ubuntu-18.04` | 17.0 - 25.3 | ✅
77-
| `ubuntu-20.04` | 21.0 - 27 | ✅
78-
| `ubuntu-22.04` | 24.2 - 27 | ✅
79-
| `ubuntu-24.04` | 24.3 - 27 | ✅
80-
| `windows-2019` | 21* - 25 | ✅
81-
| `windows-2022` | 21* - 27 | ✅
74+
| Operating system | Erlang/OTP | OTP Architecture | Status
75+
|- |- | |-
76+
| `ubuntu-18.04` | 17.0 - 25.3 | x86_64, arm64 | ✅
77+
| `ubuntu-20.04` | 21.0 - 27 | x86_64, arm64 | ✅
78+
| `ubuntu-22.04` | 24.2 - 27 | x86_64, arm64 | ✅
79+
| `ubuntu-24.04` | 24.3 - 27 | x86_64, arm64 | ✅
80+
| `windows-2019` | 21\* - 25 | x86_64, x86 | ✅
81+
| `windows-2022` | 21\* - 27 | x86_64, x86 | ✅
8282

8383
**Note** \*: prior to 23, Windows builds are only available for minor versions, e.g. 21.0, 21.3,
8484
22.0, etc.
@@ -194,6 +194,24 @@ jobs:
194194
https://cdn.jsdelivr.net/hex
195195
```
196196

197+
### OTP Architecture
198+
199+
On Windows you can specify the OTP architecture to install.
200+
201+
```yaml
202+
# create this in .github/workflows/ci.yml
203+
on: push
204+
205+
jobs:
206+
test:
207+
runs-on: windows-latest
208+
steps:
209+
- uses: erlef/setup-beam@v1
210+
with:
211+
otp-version: '26'
212+
otp-architecture: '32'
213+
```
214+
197215
### Environment variables
198216

199217
Base installation folders (useful for e.g. fetching headers for NIFs) are available in the following

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ inputs:
1919
otp-version:
2020
description: Version range or exact version of Erlang/OTP to use,
2121
or false when installing only Gleam without OTP
22+
otp-architecture:
23+
description: 32 or 64, to specify the architecture of the OTP to install. Only applies to Windows.
24+
default: 64
2225
elixir-version:
2326
description: Version range or exact version of Elixir to use
2427
gleam-version:

dist/index.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9119,6 +9119,7 @@ main().catch((err) => {
91199119

91209120
async function main() {
91219121
checkPlatform()
9122+
checkOtpArchitecture()
91229123

91239124
const versionFilePath = getInput('version-file', false)
91249125
let versions
@@ -9388,13 +9389,16 @@ async function getOTPVersions(osVersion) {
93889389
otpVersions[otpVersion] = otpVersionOrig // we keep the original for later reference
93899390
})
93909391
} else if (process.platform === 'win32') {
9392+
const file_regex = new RegExp(
9393+
`^otp_win${getInput('otp-architecture')}_(.*).exe$`,
9394+
)
93919395
otpVersionsListings.forEach((otpVersionsListing) => {
93929396
otpVersionsListing
93939397
.map((x) => x.assets)
93949398
.flat()
9395-
.filter((x) => x.name.match(/^otp_win64_.*.exe$/))
9399+
.filter((x) => x.name.match(file_regex))
93969400
.forEach((x) => {
9397-
const otpMatch = x.name.match(/^otp_win64_(.*).exe$/)
9401+
const otpMatch = x.name.match(file_regex)
93989402
const otpVersion = otpMatch[1]
93999403
debugLog('OTP line and parsing', [otpMatch, otpVersion])
94009404
otpVersions[otpVersion] = otpVersion
@@ -9899,7 +9903,9 @@ async function install(toolName, opts) {
98999903
win32: {
99009904
downloadToolURL: () =>
99019905
'https://github.com/erlang/otp/releases/download/' +
9902-
`OTP-${toolVersion}/otp_win64_${toolVersion}.exe`,
9906+
`OTP-${toolVersion}/otp_win${getInput(
9907+
'otp-architecture',
9908+
)}_${toolVersion}.exe`,
99039909
extract: async () => ['file', 'otp.exe'],
99049910
postExtract: async (cachePath) => {
99059911
const cmd = path.join(cachePath, 'otp.exe')
@@ -10155,6 +10161,21 @@ function checkPlatform() {
1015510161
}
1015610162
}
1015710163

10164+
function checkOtpArchitecture() {
10165+
if (process.platform !== 'win32' && getInput('otp-architecture') == '32') {
10166+
throw new Error(
10167+
'@erlef/setup-beam only supports otp-architecture=32 on Windows',
10168+
)
10169+
}
10170+
10171+
if (
10172+
getInput('otp-architecture') !== '32' &&
10173+
getInput('otp-architecture') !== '64'
10174+
) {
10175+
throw new Error('otp-architecture must be 32 or 64')
10176+
}
10177+
}
10178+
1015810179
function debugLoggingEnabled() {
1015910180
return !!process.env.RUNNER_DEBUG
1016010181
}

src/setup-beam.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ main().catch((err) => {
1414

1515
async function main() {
1616
checkPlatform()
17+
checkOtpArchitecture()
1718

1819
const versionFilePath = getInput('version-file', false)
1920
let versions
@@ -288,13 +289,16 @@ async function getOTPVersions(osVersion) {
288289
otpVersions[otpVersion] = otpVersionOrig // we keep the original for later reference
289290
})
290291
} else if (process.platform === 'win32') {
292+
const file_regex = new RegExp(
293+
`^otp_win${getInput('otp-architecture')}_(.*).exe$`,
294+
)
291295
otpVersionsListings.forEach((otpVersionsListing) => {
292296
otpVersionsListing
293297
.map((x) => x.assets)
294298
.flat()
295-
.filter((x) => x.name.match(/^otp_win64_.*.exe$/))
299+
.filter((x) => x.name.match(file_regex))
296300
.forEach((x) => {
297-
const otpMatch = x.name.match(/^otp_win64_(.*).exe$/)
301+
const otpMatch = x.name.match(file_regex)
298302
const otpVersion = otpMatch[1]
299303
debugLog('OTP line and parsing', [otpMatch, otpVersion])
300304
otpVersions[otpVersion] = otpVersion
@@ -799,7 +803,9 @@ async function install(toolName, opts) {
799803
win32: {
800804
downloadToolURL: () =>
801805
'https://github.com/erlang/otp/releases/download/' +
802-
`OTP-${toolVersion}/otp_win64_${toolVersion}.exe`,
806+
`OTP-${toolVersion}/otp_win${getInput(
807+
'otp-architecture',
808+
)}_${toolVersion}.exe`,
803809
extract: async () => ['file', 'otp.exe'],
804810
postExtract: async (cachePath) => {
805811
const cmd = path.join(cachePath, 'otp.exe')
@@ -1055,6 +1061,21 @@ function checkPlatform() {
10551061
}
10561062
}
10571063

1064+
function checkOtpArchitecture() {
1065+
if (process.platform !== 'win32' && getInput('otp-architecture') == '32') {
1066+
throw new Error(
1067+
'@erlef/setup-beam only supports otp-architecture=32 on Windows',
1068+
)
1069+
}
1070+
1071+
if (
1072+
getInput('otp-architecture') !== '32' &&
1073+
getInput('otp-architecture') !== '64'
1074+
) {
1075+
throw new Error('otp-architecture must be 32 or 64')
1076+
}
1077+
}
1078+
10581079
function debugLoggingEnabled() {
10591080
return !!process.env.RUNNER_DEBUG
10601081
}

test/setup-beam.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
simulateInput('otp-version', '25.1.2')
2+
simulateInput('otp-architecture', '64')
23
simulateInput('elixir-version', '1.14.2')
34
simulateInput('rebar3-version', '3.20')
45
simulateInput('install-rebar', 'true')
@@ -283,6 +284,29 @@ async function testOTPVersions() {
283284
expected = '23.0.4'
284285
got = await setupBeam.getOTPVersion(spec, osVersion)
285286
assert.deepStrictEqual(got, expected)
287+
288+
// Check we get the same results for 32-bit OTP
289+
before = simulateInput('otp-architecture', '32')
290+
291+
spec = '24.0.1'
292+
osVersion = 'windows-latest'
293+
expected = '24.0.1'
294+
got = await setupBeam.getOTPVersion(spec, osVersion)
295+
assert.deepStrictEqual(got, expected)
296+
297+
spec = '23.2.x'
298+
osVersion = 'windows-2016'
299+
expected = '23.2.7'
300+
got = await setupBeam.getOTPVersion(spec, osVersion)
301+
assert.deepStrictEqual(got, expected)
302+
303+
spec = '23.0'
304+
osVersion = 'windows-2019'
305+
expected = '23.0.4'
306+
got = await setupBeam.getOTPVersion(spec, osVersion)
307+
assert.deepStrictEqual(got, expected)
308+
309+
simulateInput('otp-architecture', before)
286310
}
287311

288312
simulateInput('hexpm-mirrors', hexMirrors, { multiline: true })

0 commit comments

Comments
 (0)