Repository: pulumi/actions
Pull request #367 (2021-08-23 12:26:01)

feat: Add support for arm64 architecture
Added support for the Pulumi GitHub Action on arm64 based architecture.




Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1144fd8..bd9606c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,7 +2,7 @@
 
 ## HEAD (Unreleased)
 
-_(none)_
+- Add support for arm64 architecture
 
 ---
 
diff --git a/package.json b/package.json
index 5498abb..aa4a1bb 100644
--- a/package.json
+++ b/package.json
@@ -27,7 +27,7 @@
     "@types/node": "~14.17.10",
     "@typescript-eslint/eslint-plugin": "~4.29.2",
     "@typescript-eslint/parser": "~4.29.2",
-    "@vercel/ncc": "^0.29.1",
+    "@vercel/ncc": "^0.29.2",
     "eslint": "~7.32.0",
     "eslint-config-prettier": "~8.3.0",
     "eslint-plugin-import": "^2.24.0",
diff --git a/src/libs/pulumi-cli.ts b/src/libs/pulumi-cli.ts
index 5b7482c..9404c04 100644
--- a/src/libs/pulumi-cli.ts
+++ b/src/libs/pulumi-cli.ts
@@ -15,23 +15,30 @@ export async function run(...args: string[]): Promise<void> {
   await exec.exec(`pulumi`, args, true);
 }
 
-export async function downloadCli(range: string): Promise<void> {
+export function getPlatform(): string | undefined {
   const platforms = {
-    linux: 'linux-x64',
-    darwin: 'darwin-x64',
-    win32: 'windows-x64',
+    'linux-x64': 'linux-x64',
+    'linux-arm64': 'linux-arm64',
+    'darwin-x64': 'darwin-x64',
+    'darwin-arm64': 'darwin-arm64',
+    'win32-x64': 'windows-x64',
   };
 
   const runnerPlatform = os.platform();
+  const runnerArch = os.arch();
+
+  return platforms[`${runnerPlatform}-${runnerArch}`];
+}
 
-  if (!(runnerPlatform in platforms)) {
+export async function downloadCli(range: string): Promise<void> {
+  const platform = getPlatform();
+
+  if (!platform) {
     throw new Error(
-      'Unsupported operating system - Pulumi CLI is only released for Darwin, Linux and Windows',
+      'Unsupported operating system - Pulumi CLI is only released for Darwin (x64, arm64), Linux (x64, arm64) and Windows (x64)',
     );
   }
 
-  const platform = platforms[runnerPlatform];
-
   core.info(`Configured range: ${range}`);
 
   const { version, downloads } = await getVersionObject(range);
diff --git a/yarn.lock b/yarn.lock
index 086cf88..74dc144 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1060,10 +1060,10 @@
     "@typescript-eslint/types" "4.29.2"
     eslint-visitor-keys "^2.0.0"
 
-"@vercel/ncc@^0.29.1":
-  version "0.29.1"
-  resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.29.1.tgz#d62b1b9508a2bc7a822791ff6a6eb3e08a2cfdd7"
-  integrity sha512-92d2AApJtkpampMqKgfqWbYkuFvqRFs8kPkKLTbesSB9RVwWfiI3i6mgBxtZgMV9iRuLPVZ+OBNocKHXZSRj6Q==
+"@vercel/ncc@^0.29.2":
+  version "0.29.2"
+  resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.29.2.tgz#29a35d21b03267a538b536168af766f4270ae8f4"
+  integrity sha512-eUxibZD92k+rY0oZJFZooGqdVpGkDrrHlUhj9UAWrtoyXCGmNOWC1Kcr2KPrZoHRSlWwHOcRnkn2nGT+aHY2KA==
 
 abab@^2.0.3:
   version "2.0.3"


Test patch:
diff --git a/src/libs/__tests__/get-platform.test.ts b/src/libs/__tests__/get-platform.test.ts
new file mode 100644
index 0000000..12b06c0
--- /dev/null
+++ b/src/libs/__tests__/get-platform.test.ts
@@ -0,0 +1,32 @@
+import * as os from 'os';
+import * as playback from 'jest-playback';
+import { mocked } from 'ts-jest/utils';
+import { getPlatform } from '../pulumi-cli';
+playback.setup(__dirname);
+
+jest.mock('os');
+
+const mockedOs = mocked(os);
+
+describe('get-platform', () => {
+  it.each([
+    ['darwin', 'x64', 'darwin-x64'],
+    ['darwin', 'arm64', 'darwin-arm64'],
+    ['darwin', 'x32', undefined],
+    ['linux', 'x64', 'linux-x64'],
+    ['linux', 'arm64', 'linux-arm64'],
+    ['linux', 'x32', undefined],
+    ['win32', 'x64', 'windows-x64'],
+    ['win32', 'x32', undefined],
+    ['android', 'x32', undefined],
+  ] as const)(
+    'should return platform for %s %s',
+    async (platform, arch, expected) => {
+      mockedOs.platform.mockReturnValue(platform);
+      mockedOs.arch.mockReturnValue(arch);
+
+      const p = getPlatform();
+      expect(p).toEqual(expected);
+    },
+  );
+});