Skip to content

Commit

Permalink
fix: I forgot to update the action.yml. This should fix a LOT of bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChecksumDev committed Jul 19, 2024
1 parent b44e9e1 commit c5235a9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
19 changes: 13 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down
39 changes: 15 additions & 24 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
const streamPipeline = promisify(pipeline)

async function downloadFile(url: string, outputPath: string, token?: string): Promise<void> {
core.info(`Starting download from URL: ${url}`)
const packageJson = require('../package.json')
const userAgent = `beat-forge/init-beatsaber@${packageJson.version}`
Expand Down Expand Up @@ -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')
}

Expand Down Expand Up @@ -126,12 +117,12 @@ async function run(): Promise<void> {
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}`
Expand Down

0 comments on commit c5235a9

Please sign in to comment.