diff --git a/README.md b/README.md index 2b7d050..711410b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ This will clone the stripped Beat Saber references to the default path `./Refs` | Name | Description | Required | Default | | ---------- | ---------------------------------------------------------------------------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------- | -| `token` | GitHub token for cloning the Beat Saber repository. | No | None | +| `token` | GitHub token for cloning the Beat Saber repository. | No | `${{ github.token }}` | | `version` | Version of Beat Saber for the modding environment. If not specified, the action will try to infer it from a `manifest.json`. | No | None | | `manifest` | Path to a specific `manifest.json` file for version inference. If not provided, the action will search recursively. | No | None | | `path` | Path to clone the stripped Beat Saber references to. | No | `./Refs` | diff --git a/action.yml b/action.yml index 2df9d94..ef8ea2a 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ -name: "Initialize Beat Saber References" -description: "A GitHub Action to initialize a stripped modding environment for use in GitHub Actions." +name: "Initialize Beat Saber Development Environment" +description: "A GitHub Action to initialize a Beat Saber modding environment" author: "BeatForge" branding: @@ -11,17 +11,24 @@ inputs: description: "The GitHub token to use for downloading the modding environment" default: ${{ github.token }} required: false - repo: - description: "The version repository to use" - default: "https://github.com/beat-forge/beatsaber-stripped" - required: false version: description: "The BeatSaber version to use" required: true + manifest: + description: "The path to the manifest.json file to infer version if not specified" + required: false path: description: "The location to install the modding environment to, defaults to ./Refs" required: false default: "./Refs" + host: + description: "The GitHub host to use, defaults to github.com" + required: false + default: "github.com" + repo: + description: "The repository to use (format: owner/repo)" + default: "beat-forge/beatsaber-stripped" + required: false runs: using: node20 diff --git a/src/index.ts b/src/index.ts index 524e9dc..283056e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,13 @@ import * as core from '@actions/core' import { promises as fs, createWriteStream } from 'fs' import { dirname, join, resolve } from 'path' +import { pipeline } from 'stream' import * as tar from 'tar' +import { promisify } from 'util' -async function downloadFile( - url: string, - outputPath: string, - token?: string -): Promise { +const streamPipeline = promisify(pipeline) + +async function downloadFile(url: string, outputPath: string, token?: string): Promise { core.info(`Starting download from URL: ${url}`) const packageJson = require('../package.json') const userAgent = `beat-forge/init-beatsaber@${packageJson.version}` @@ -36,24 +36,15 @@ async function downloadFile( core.debug(`Created directory for output path: ${dirname(outputPath)}`) const fileStream = createWriteStream(outputPath) - const reader = response.body?.getReader() - - if (!reader) { - core.error('Failed to get reader from response body') - throw new Error('Failed to get reader from response body') - } core.info('Starting to read and write file stream') - const pump = async () => { - while (true) { - const { done, value } = await reader.read() - if (done) break - if (value) fileStream.write(value) - } - fileStream.close() + + if (response.body) { + await streamPipeline(response.body, fileStream) + } else { + throw new Error('Response body is null') } - await pump() core.info('File downloaded and written successfully') } @@ -126,12 +117,12 @@ async function run(): Promise { core.info('Initializing Beat Saber modding environment...') const token = core.getInput('token') - let requestedVersion = core.getInput('version') - let manifestPath = core.getInput('manifest') - let referencesPath = core.getInput('path') || './Refs' + const repo = core.getInput('repo') + const host = core.getInput('host') - let repo = core.getInput('repo') || 'beat-forge/beatsaber-stripped' - let host = core.getInput('host') || 'github.com' + const manifestPath = core.getInput('manifest') + const referencesPath = core.getInput('path') + let requestedVersion = core.getInput('version') core.debug( `Inputs: version=${requestedVersion}, manifest=${manifestPath}, path=${referencesPath}, repo=${repo}, host=${host}`