Automatically fallback to darwin/amd64 for Terraform versions before 1.0.2 (#409)

Reference: https://github.blog/changelog/2024-04-01-macos-14-sonoma-is-generally-available-and-the-latest-macos-runner-image/

GitHub hosted runners for `macos-latest` are automatically being upgraded to macOS 14 and arm64 architecture machines. Any workflows that are using the upgraded runner can return an error such as:

```
Error: Terraform version 0.12.* not available for darwin and arm64
```

This adds special case logic to automatically fallback to darwin/amd64 when darwin/arm64 is detected and the version is below 1.0.2, which is the first version that had darwin/arm64 release assets. macOS should emulate and run the amd64 binaries until Apple or GitHub removes the emulation support.
This commit is contained in:
Brian Flad 2024-04-23 10:01:38 -04:00 committed by GitHub
parent a75f1a3cce
commit 22013f72bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 3862 additions and 3878 deletions

View file

@ -7,6 +7,7 @@
const fs = require('fs').promises;
const os = require('os');
const path = require('path');
const semver = require('semver');
// External
const core = require('@actions/core');
@ -135,7 +136,15 @@ async function run () {
core.debug(`Finding releases for Terraform version ${version}`);
const release = await releases.getRelease('terraform', version, 'GitHub Action: Setup Terraform');
const platform = mapOS(osPlatform);
const arch = mapArch(osArch);
let arch = mapArch(osArch);
// Terraform was not available for darwin/arm64 until 1.0.2, however macOS
// runners can emulate darwin/amd64.
if (platform === 'darwin' && arch === 'arm64' && semver.valid(release.version) && semver.lt(release.version, '1.0.2')) {
core.warning('Terraform is not available for darwin/arm64 until version 1.0.2. Falling back to darwin/amd64.');
arch = 'amd64';
}
core.debug(`Getting build for Terraform version ${release.version}: ${platform} ${arch}`);
const build = release.getBuild(platform, arch);
if (!build) {