Skip to content

Commit

Permalink
fix: write content to launcher binary
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jun 10, 2024
1 parent 57aeebb commit a6093de
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 38 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ jobs:
command -v renpy-cli
command -v renpy-launcher
- name: Show launcher
if: matrix.os != 'windows-latest'
run: |
ls $(command -v renpy-launcher)
cat $(command -v renpy-launcher)
- name: Check version
if: matrix.os != 'windows-latest'
run: |
Expand All @@ -100,10 +106,17 @@ jobs:
run: renpy-cli --help

- name: Set projects directory
if: matrix.os != 'windows-latest'
run: renpy-launcher set_projects_directory ..

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

- name: Check web support
run: ls ${{ steps.renpy.outputs.launcher}}/../web/index.html

- name: Build web
if: matrix.os != 'windows-latest'
run: |
renpy-launcher web_build ${{ steps.renpy.outputs.launcher }}/../the_question --destination dist
ls dist dist.zip
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ This is a shorthand command for:
- run: renpy-cli ${{ steps.renpy.outputs.launcher }}
```

> [!NOTE]
> The launcher CLI is only available in Linux and macOS.

### `rapt`

**Optional**: Android Support (RAPT). Defaults to `false`:
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions src/__snapshots__/utils.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,3 @@ 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"`;
27 changes: 12 additions & 15 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import * as tc from '@actions/tool-cache';
import os from 'os';

import { run } from '.';
import { createLauncherBinary } from './utils';

jest.mock('@actions/core');
jest.mock('@actions/exec');
jest.mock('@actions/tool-cache');
jest.mock('os');

jest.mock('./utils', () => ({
...jest.requireActual('./utils'),
createLauncherBinary: jest.fn(),
}));

const mockedCore = jest.mocked(core);
const mockedExec = jest.mocked(exec);
const mockedTc = jest.mocked(tc);
Expand Down Expand Up @@ -67,23 +73,14 @@ describe.each([
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(createLauncherBinary).toHaveBeenCalledWith(
sdkDirectory,
launcherName,
expect.stringContaining(cliName),
);

expect(mockedTc.cacheDir).toHaveBeenCalledWith(
sdkDirectory,
cliName,
Expand Down
11 changes: 2 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {
} from '@actions/tool-cache';

import {
createLauncherBinary,
getBinaryDirectory,
getBinaryPath,
getDownloadObject,
getLauncherDirectory,
getLauncherPath,
} from './utils';

export async function run() {
Expand Down Expand Up @@ -57,14 +57,7 @@ export async function run() {
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]);
await createLauncherBinary(binaryDirectory, launcherName, binaryPath);

// Expose the SDK by adding it to the PATH
addPath(binaryDirectory);
Expand Down
24 changes: 19 additions & 5 deletions src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import * as exec from '@actions/exec';
import fs from 'fs/promises';
import os from 'os';

import {
createLauncherBinary,
getBinaryDirectory,
getBinaryPath,
getDownloadObject,
getLauncherDirectory,
getLauncherPath,
} from './utils';

jest.mock('@actions/exec');
const mockedExec = jest.mocked(exec);

jest.mock('fs/promises');
const mockedFs = jest.mocked(fs);

jest.mock('os');
const mockedOs = jest.mocked(os);

Expand Down Expand Up @@ -69,9 +77,15 @@ describe('getLauncherDirectory', () => {
});
});

describe('getLauncherPath', () => {
it('returns launcher path', () => {
const directory = 'directory';
expect(getLauncherPath(directory, name)).toMatchSnapshot();
describe('createLauncherBinary', () => {
it('creates launcher binary', async () => {
const cliPath = 'cliPath';
const launcherPath = `${directory}/${name}`;
await createLauncherBinary(directory, name, cliPath);
expect(mockedFs.writeFile).toHaveBeenCalledWith(
launcherPath,
`${cliPath} ${directory}/launcher "$@"`,
);
expect(mockedExec.exec).toHaveBeenCalledWith('chmod', ['+x', launcherPath]);
});
});
23 changes: 17 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { exec } from '@actions/exec';
import { writeFile } from 'fs/promises';
import { arch, platform } from 'os';
import { join } from 'path';

Expand Down Expand Up @@ -54,12 +56,21 @@ export function getLauncherDirectory(directory: string) {
}

/**
* Gets launcher path.
* Creates launcher binary.
*
* @param directory - Directory
* @param name - Binary name
* @returns - Launcher path
* @param directory - Binary directory
* @param name - Launcher name
* @param cliPath - Binary path
*/
export function getLauncherPath(directory: string, name: string) {
return join(directory, name);
export async function createLauncherBinary(
directory: string,
name: string,
cliPath: string,
) {
const launcherPath = join(directory, name);
await writeFile(
launcherPath,
`${cliPath} ${getLauncherDirectory(directory)} "$@"`,
);
await exec('chmod', ['+x', launcherPath]);
}

0 comments on commit a6093de

Please sign in to comment.