Skip to content

Commit

Permalink
Merge pull request #256 from HatsuneMiku3939/feature/add-osx-support
Browse files Browse the repository at this point in the history
feature: Add OSX runner support
  • Loading branch information
HatsuneMiku3939 authored Feb 27, 2024
2 parents 50946bc + 5554a00 commit 649b0ed
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 4 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: "test"
on:
pull_request:
push:
branches:
- master
- main
- 'releases/*'

jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, macos-13, macos-14]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run prepare
- uses: ./
with:
masks: SECRET1, SECRET2
direnvVersion: 2.32.3
- run: printenv | grep DIRENV_ACTION_TEST
- run: echo $PATH | grep $(pwd)/bin
- run: printenv

test-default-option:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run prepare
- uses: ./
- run: printenv | grep DIRENV_ACTION_TEST
- run: echo $PATH | grep $(pwd)/bin
- run: printenv
File renamed without changes.
43 changes: 39 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,45 @@ const tc = require('@actions/tool-cache');
const exec = require('@actions/exec');
const cache = require('@actions/cache');

const { platform } = require('node:process');
const { arch } = require('node:process');

function direnvBinaryURL(version, platform, arch) {
const baseurl = `https://github.com/direnv/direnv/releases/download/v${version}/direnv`

// supported arch: x64, arm64
// supported platform: linux, darwin
const supportedArch = ['x64', 'arm64'];
const supportedPlatform = ['linux', 'darwin'];

if (!supportedArch.includes(arch)) {
throw new Error(`unsupported arch: ${arch}`);
}

if (!supportedPlatform.includes(platform)) {
throw new Error(`unsupported platform: ${platform}`);
}

const archPlatform = `${platform}-${arch}`;

switch (archPlatform) {
case 'linux-x64':
return `${baseurl}.linux-amd64`;
case 'linux-arm64':
return `${baseurl}.linux-arm64`;
case 'darwin-x64':
return `${baseurl}.darwin-amd64`;
case 'darwin-arm64':
return `${baseurl}.darwin-arm64`;
default:
throw new Error(`unsupported platform: ${archPlatform}`);
}
}

// internal functions
async function installTools() {
const direnvVersion = core.getInput('direnvVersion');
core.info(`installing direnv-${direnvVersion}...`);
core.info(`installing direnv-${direnvVersion} on ${platform}-${arch}`);

// test direnv in cache
const foundToolCache = tc.find('direnv', direnvVersion);
Expand All @@ -16,7 +50,7 @@ async function installTools() {
core.addPath(foundToolCache);
} else {
const workspace = process.env['GITHUB_WORKSPACE'];
const key = `hatsunemiku3939-direnv-action-toolcache-${direnvVersion}`;
const key = `hatsunemiku3939-direnv-action-toolcache-${direnvVersion}-${platform}-${arch}`;
const paths = [`${workspace}/.direnv-action`];
const restoreKeys = [key];

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

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

0 comments on commit 649b0ed

Please sign in to comment.