Skip to content

Commit

Permalink
feat: add launcher binary and input launcher-name
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jun 10, 2024
1 parent b4f6384 commit 1598898
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 43 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,19 @@ jobs:
renios: true
web: true

- name: Locate binary
run: command -v renpy-cli
- name: Locate binaries
run: |
command -v renpy-cli
command -v renpy-launcher
- name: Get version
id: version
run: echo "RENPY_VERSION=$(renpy-cli --version)" >> $GITHUB_OUTPUT

- name: Check version
if: matrix.os != 'windows-latest'
run: |
renpy-cli --version &> RENPY_VERSION
if [[ $(cat RENPY_VERSION) != *'${{ matrix.version }}'* ]]; then
if [[ '${{ steps.version.outputs.RENPY_VERSION }}' != *'${{ matrix.version }}'* ]]; then
echo 'Version does not match. See version below:'
renpy-cli --version
exit 1
Expand All @@ -96,15 +101,10 @@ jobs:
run: renpy-cli --help

- name: Set projects directory
run: renpy-cli ${{ steps.renpy.outputs.launcher }} set_projects_directory ..
run: renpy-launcher set_projects_directory ..

- name: Set project
run: renpy-cli ${{ steps.renpy.outputs.launcher }} set_project .

- name: Check web support
if: matrix.os != 'windows-latest'
run: |
if [[ ! -f ${{ steps.renpy.outputs.launcher}}/../web/index.html ]]; then
echo 'Web Platform Support (Renpyweb) not found.'
exit 1
fi
run: ls ${{ steps.renpy.outputs.launcher}}/../web/index.html
48 changes: 41 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,53 @@ See [action.yml](action.yml)
## Inputs
### `cli-name`

**Optional**: CLI name. Defaults to `renpy-cli`:

```yaml
- uses: remarkablegames/setup-renpy@v1
with:
cli-name: renpy-cli
- run: renpy-cli
```

> [!WARNING]
> CLI name cannot be `renpy` due to the SDK structure.

### `cli-version`

**Optional**: The CLI [version](https://www.renpy.org/release_list.html). Defaults to [`8.2.1`](https://www.renpy.org/latest.html):
**Optional**: CLI [version](https://www.renpy.org/release_list.html). Defaults to [`8.2.1`](https://www.renpy.org/latest.html):

```yaml
- uses: remarkablegames/setup-renpy@v1
with:
cli-version: 8.2.1
- run: renpy-cli --version
```

### `cli-name`
### `launcher-name`

**Optional**: The CLI name. Defaults to `renpy-cli`:
**Optional**: Launcher name. Defaults to `renpy-launcher`:

```yaml
- uses: remarkablegames/setup-renpy@v1
with:
cli-name: renpy-cli
launcher-name: renpy-launcher
- run: renpy-launcher
```

> [!NOTE]
> The CLI name cannot be `renpy` due to the SDK directory structure.
This is a shorthand command for:

```yaml
- uses: remarkablegames/setup-renpy@v1
id: renpy
- run: renpy-cli ${{ steps.renpy.outputs.launcher }}
```

### `rapt`

Expand Down Expand Up @@ -94,9 +119,18 @@ See [action.yml](action.yml)
- uses: remarkablegames/setup-renpy@v1
id: renpy
- run: renpy-cli ${{ steps.renpy.outputs.launcher }} set_project .
- run: renpy-cli ${{ steps.renpy.outputs.launcher }}
```

> [!TIP]
> Prefer using `renpy-launcher`:
>
> ```yaml
> - uses: remarkablegames/setup-renpy@v1
>
> - run: renpy-launcher
> ```

## Contributions

Contributions are welcome!
Expand Down
10 changes: 7 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ name: setup-renpy
description: Set up GitHub Actions workflow with Ren'Py CLI
author: remarkablemark
inputs:
cli-name:
description: CLI name
required: false
default: renpy-cli
cli-version:
description: CLI version
required: false
default: 8.2.1
cli-name:
description: CLI name
launcher-name:
description: Launcher name
required: false
default: renpy-cli
default: renpy-launcher
rapt:
description: Android Support (RAPT)
required: false
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/__snapshots__/utils.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,5 @@ exports[`getDownloadObject when OS is "win32" and arch is "x64" gets download ob
`;

exports[`getLauncherDirectory returns launcher directory 1`] = `"directory/launcher"`;

exports[`getLauncherPath returns launcher path 1`] = `"directory/name"`;
34 changes: 29 additions & 5 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ beforeEach(() => {
jest.resetAllMocks();
});

const name = 'cli-name';
const cliName = 'cli-name';
const version = '1.2.3';
const launcherName = 'launcher-name';
const pathToTarball = 'path/to/tarball';
const pathToCLI = 'path/to/cli';

Expand All @@ -37,7 +38,9 @@ describe.each([
case 'cli-version':
return version;
case 'cli-name':
return name;
return cliName;
case 'launcher-name':
return launcherName;
default:
return '';
}
Expand All @@ -61,11 +64,32 @@ describe.each([

expect(mockedExec.exec).toHaveBeenCalledWith('mv', [
expect.stringContaining('renpy'),
expect.stringContaining(name),
expect.stringContaining(cliName),
]);

expect(mockedExec.exec).toHaveBeenCalledWith('touch', [
expect.stringContaining(launcherName),
]);

expect(mockedExec.exec).toHaveBeenCalledWith('echo', [
expect.stringMatching(/.+cli-name(.exe)? .+launcher .+[$@].+/),
'>',
expect.stringContaining(launcherName),
]);

expect(mockedExec.exec).toHaveBeenCalledWith('chmod', [
'+x',
expect.stringContaining(launcherName),
]);

const sdkDirectory = `${pathToCLI}/renpy-${version}-sdk${arch.includes('arm') ? 'arm' : ''}`;
expect(mockedTc.cacheDir).toHaveBeenCalledWith(sdkDirectory, name, version);

expect(mockedTc.cacheDir).toHaveBeenCalledWith(
sdkDirectory,
cliName,
version,
);

expect(mockedCore.addPath).toHaveBeenCalledWith(sdkDirectory);

expect(mockedCore.setOutput).toHaveBeenCalledWith(
Expand All @@ -89,7 +113,7 @@ describe.each([
case 'cli-version':
return version;
case 'cli-name':
return name;
return cliName;
case 'rapt':
return String(inputs.rapt);
case 'renios':
Expand Down
29 changes: 22 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import {
getBinaryPath,
getDownloadObject,
getLauncherDirectory,
getLauncherPath,
} from './utils';

export async function run() {
try {
// Get the version and name of the SDK to be installed
const version = getInput('cli-version');
const name = getInput('cli-name');
const cliName = getInput('cli-name');
const launcherName = getInput('launcher-name');

// Download the specific version of the SDK (e.g., tarball/zipball)
const download = getDownloadObject(version);
Expand All @@ -32,14 +34,16 @@ export async function run() {
);

// Rename the binary
const binaryPath = getBinaryPath(binaryDirectory, name).replace('.sh', '');
const binaryPath = getBinaryPath(binaryDirectory, cliName).replace(
'.sh',
'',
);
await exec('mv', [getBinaryPath(binaryDirectory, 'renpy'), binaryPath]);

// Add Android/iOS/Web support
const addons = (['rapt', 'renios', 'web'] as const).filter(
(addon) => getInput(addon) === 'true',
);

await Promise.all(
addons.map((addon) =>
downloadTool(download[addon]).then((downloadPath) =>
Expand All @@ -48,14 +52,25 @@ export async function run() {
),
);

// Cache the SDK
await cacheDir(binaryDirectory, [name, ...addons].join('_'), version);
// Expose SDK Launcher path
const launcherDirectory = getLauncherDirectory(binaryDirectory);
setOutput('launcher', launcherDirectory);

// Create the launcher binary
const launcherPath = getLauncherPath(binaryDirectory, launcherName);
await exec('touch', [launcherPath]);
await exec('echo', [
`${binaryPath} ${launcherDirectory} "$@"`,
'>',
launcherPath,
]);
await exec('chmod', ['+x', launcherPath]);

// Expose the SDK by adding it to the PATH
addPath(binaryDirectory);

// Expose SDK Launcher path
setOutput('launcher', getLauncherDirectory(binaryDirectory));
// Cache the SDK
await cacheDir(binaryDirectory, [cliName, ...addons].join('_'), version);
} catch (error) {
if (error instanceof Error) {
setFailed(error.message);
Expand Down
27 changes: 18 additions & 9 deletions src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getBinaryPath,
getDownloadObject,
getLauncherDirectory,
getLauncherPath,
} from './utils';

jest.mock('os');
Expand All @@ -23,12 +24,15 @@ const table = platforms.reduce(

const version = '8.2.1';

beforeEach(() => {
jest.resetAllMocks();
});

describe('getDownloadObject', () => {
describe.each(table)('when OS is %p and arch is %p', (os, arch) => {
beforeEach(() => {
jest.resetAllMocks();
mockedOs.platform.mockReturnValueOnce(os as NodeJS.Platform);
mockedOs.arch.mockReturnValueOnce(arch);
mockedOs.platform.mockReturnValue(os as NodeJS.Platform);
mockedOs.arch.mockReturnValue(arch);
});

it('gets download object', () => {
Expand All @@ -37,16 +41,16 @@ describe('getDownloadObject', () => {
});
});

const directory = 'directory';
const name = 'name';

describe('getBinaryPath', () => {
describe.each(platforms)('when OS is %p', (os) => {
beforeEach(() => {
jest.resetAllMocks();
mockedOs.platform.mockReturnValueOnce(os);
mockedOs.platform.mockReturnValue(os);
});

it('returns CLI filepath', () => {
const directory = 'directory';
const name = 'name';
expect(getBinaryPath(directory, name)).toMatchSnapshot();
});
});
Expand All @@ -55,14 +59,19 @@ describe('getBinaryPath', () => {
describe('getBinaryDirectory', () => {
it.each(architectures)('returns CLI directory for arch %p', (arch) => {
mockedOs.arch.mockReturnValueOnce(arch);
const directory = 'directory';
expect(getBinaryDirectory(directory, version)).toMatchSnapshot();
});
});

describe('getLauncherDirectory', () => {
it('returns launcher directory', () => {
const directory = 'directory';
expect(getLauncherDirectory(directory)).toMatchSnapshot();
});
});

describe('getLauncherPath', () => {
it('returns launcher path', () => {
const directory = 'directory';
expect(getLauncherPath(directory, name)).toMatchSnapshot();
});
});
11 changes: 11 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,14 @@ export function getBinaryDirectory(directory: string, version: string) {
export function getLauncherDirectory(directory: string) {
return join(directory, 'launcher');
}

/**
* Gets launcher path.
*
* @param directory - Directory
* @param name - Binary name
* @returns - Launcher path
*/
export function getLauncherPath(directory: string, name: string) {
return join(directory, name);
}

0 comments on commit 1598898

Please sign in to comment.