Skip to content

Commit 649b0ed

Browse files
Merge pull request #256 from HatsuneMiku3939/feature/add-osx-support
feature: Add OSX runner support
2 parents 50946bc + 5554a00 commit 649b0ed

File tree

3 files changed

+82
-4
lines changed

3 files changed

+82
-4
lines changed

.github/workflows/test.yaml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: "test"
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
- 'releases/*'
9+
10+
jobs:
11+
test:
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, macos-13, macos-14]
15+
runs-on: ${{ matrix.os }}
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: 20
21+
- run: npm ci
22+
- run: npm run prepare
23+
- uses: ./
24+
with:
25+
masks: SECRET1, SECRET2
26+
direnvVersion: 2.32.3
27+
- run: printenv | grep DIRENV_ACTION_TEST
28+
- run: echo $PATH | grep $(pwd)/bin
29+
- run: printenv
30+
31+
test-default-option:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v4
35+
- uses: actions/setup-node@v4
36+
with:
37+
node-version: 20
38+
- run: npm ci
39+
- run: npm run prepare
40+
- uses: ./
41+
- run: printenv | grep DIRENV_ACTION_TEST
42+
- run: echo $PATH | grep $(pwd)/bin
43+
- run: printenv
File renamed without changes.

index.js

+39-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,45 @@ const tc = require('@actions/tool-cache');
33
const exec = require('@actions/exec');
44
const cache = require('@actions/cache');
55

6+
const { platform } = require('node:process');
7+
const { arch } = require('node:process');
8+
9+
function direnvBinaryURL(version, platform, arch) {
10+
const baseurl = `https://github.com/direnv/direnv/releases/download/v${version}/direnv`
11+
12+
// supported arch: x64, arm64
13+
// supported platform: linux, darwin
14+
const supportedArch = ['x64', 'arm64'];
15+
const supportedPlatform = ['linux', 'darwin'];
16+
17+
if (!supportedArch.includes(arch)) {
18+
throw new Error(`unsupported arch: ${arch}`);
19+
}
20+
21+
if (!supportedPlatform.includes(platform)) {
22+
throw new Error(`unsupported platform: ${platform}`);
23+
}
24+
25+
const archPlatform = `${platform}-${arch}`;
26+
27+
switch (archPlatform) {
28+
case 'linux-x64':
29+
return `${baseurl}.linux-amd64`;
30+
case 'linux-arm64':
31+
return `${baseurl}.linux-arm64`;
32+
case 'darwin-x64':
33+
return `${baseurl}.darwin-amd64`;
34+
case 'darwin-arm64':
35+
return `${baseurl}.darwin-arm64`;
36+
default:
37+
throw new Error(`unsupported platform: ${archPlatform}`);
38+
}
39+
}
640

741
// internal functions
842
async function installTools() {
943
const direnvVersion = core.getInput('direnvVersion');
10-
core.info(`installing direnv-${direnvVersion}...`);
44+
core.info(`installing direnv-${direnvVersion} on ${platform}-${arch}`);
1145

1246
// test direnv in cache
1347
const foundToolCache = tc.find('direnv', direnvVersion);
@@ -16,7 +50,7 @@ async function installTools() {
1650
core.addPath(foundToolCache);
1751
} else {
1852
const workspace = process.env['GITHUB_WORKSPACE'];
19-
const key = `hatsunemiku3939-direnv-action-toolcache-${direnvVersion}`;
53+
const key = `hatsunemiku3939-direnv-action-toolcache-${direnvVersion}-${platform}-${arch}`;
2054
const paths = [`${workspace}/.direnv-action`];
2155
const restoreKeys = [key];
2256

@@ -36,8 +70,9 @@ async function installTools() {
3670
// clear
3771
await exec.exec('rm', [`-rf`, `${workspace}/.direnv-action`]);
3872
} else {
39-
core.info('direnv not found in cache, installing...');
40-
const installPath = await tc.downloadTool(`https://github.com/direnv/direnv/releases/download/v${direnvVersion}/direnv.linux-amd64`);
73+
const dlUrl = direnvBinaryURL(direnvVersion, platform, arch);
74+
core.info(`direnv not found in cache, installing ${dlUrl} ...`);
75+
const installPath = await tc.downloadTool(dlUrl);
4176

4277
// set permissions
4378
core.info(`direnv installed ${installPath}, setting permissions...`);

0 commit comments

Comments
 (0)