Skip to content

Commit

Permalink
add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kindermax committed Feb 21, 2022
1 parent 7183499 commit a0d015f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 14 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,48 @@
# lets-action
Github action to setup lets task runner

* [Usage](#usage)
* [Workflow](#workflow)
* [Customizing](#customizing)
* [inputs](#inputs)


## Usage

### Workflow

```yaml
name: lets

on:
pull_request:
push:

jobs:
lets:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Install Lets
uses: lets/lets-action@v1
with:
version: latest
-
name: Run Lets
run: lets --version
```
## Customizing
### inputs
Following inputs can be used as `step.with` keys

| Name | Type | Default | Description |
|------------------|---------|--------------|------------------------------------------------------------------|

| `version`**¹** | String | `latest` | Lets version |
|
17 changes: 17 additions & 0 deletions src/__tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,21 @@ describe('installer', () => {
.rejects
.toThrow(`Cannot find Lets ${version} release`);
}, 100000);
});

describe('getFilename', () => {
it('filename for linux amd64', () => {
const filename = installer.getFilename('linux', 'x64');
expect(filename).toBe('lets_Linux_x86_64.tar.gz');
});

it('filename for MacOS amd64', () => {
const filename = installer.getFilename('darwin', 'x64');
expect(filename).toBe('lets_Darwin_x86_64.tar.gz');
});

it('filename for MacOS arm64', () => {
const filename = installer.getFilename('darwin', 'arm');
expect(filename).toBe('lets_Darwin_arm64.tar.gz');
});
});
19 changes: 5 additions & 14 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import * as github from './github';
import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';

const osPlat: string = os.platform();
const osArch: string = os.arch();

export async function getLets(version: string): Promise<string> {
const release: string | null = await github.getRelease(version);
if (!release) {
throw new Error(`Cannot find Lets ${version} release`);
}

const filename = getFilename();
const filename = getFilename(os.platform(), os.arch());
const downloadUrl = util.format(
'https://github.com/lets-cli/lets/releases/download/%s/%s',
release,
Expand All @@ -38,30 +35,24 @@ export async function getLets(version: string): Promise<string> {
return exePath;
}

const getFilename = (): string => {
export const getFilename = (osPlat: string, osArch: string): string => {
let arch: string;
core.info(`Platform ${osPlat}, arch: ${osArch}`);

switch (osArch) {
case 'x64': {
arch = 'x86_64';
break;
}
case 'x32': {
arch = 'i386';
break;
}
case 'arm': {
const arm_version = (process.config.variables as any).arm_version;
arch = arm_version ? 'armv' + arm_version : 'arm';
arch = 'arm64';
break;
}
default: {
arch = osArch;
break;
}
}
if (osPlat == 'darwin') {
arch = 'all';
}
const platform: string = osPlat == 'darwin' ? 'Darwin' : 'Linux';
const ext: string = 'tar.gz';
return util.format('lets_%s_%s.%s', platform, arch, ext);
Expand Down

0 comments on commit a0d015f

Please sign in to comment.