Bret Comnes 7b14798c89
Update to the latest async-neocities 4.0
BREAKING CHANGE: api_token action input is renamed to api_key, please update this

BREAKING CHANGE: added a required neocities_supporter action input to toggle unsupported file filtering

BREAKING CHANGE: addad a preview_before_deploy action input to toggle informational deploy plans prior to deploys

BREAKING CHANGE: completely rewrote the underlying library to provide better error handling and reporting

BREAKING CHANGE: Remove a bunch of real time stats and progress meters. Deploys were finishing in seconds and these were very complicated to maintain.
2024-11-19 17:35:09 -08:00

85 lines
2.6 KiB
JavaScript

import core from '@actions/core'
import {
NeocitiesAPIClient,
printDeployText,
printPreviewText,
printResultsErrorDump,
SimpleTimer
} from 'async-neocities'
import path from 'node:path'
import assert from 'node:assert'
import fs from 'node:fs/promises'
import { minimatch } from 'minimatch'
async function run () {
const key = core.getInput('api_key') || core.getInput('api_token')
const distDir = path.join(process.cwd(), core.getInput('dist_dir'))
const cleanup = JSON.parse(core.getInput('cleanup'))
const neocitiesSupporter = JSON.parse(core.getInput('neocities_supporter'))
const previewDeploy = JSON.parse(core.getInput('preview_before_deploy'))
const protectedFilesGlob = core.getInput('protected_files')
assert(typeof cleanup === 'boolean', '`cleanup` input must be a boolean "true" or "false"')
assert(typeof neocitiesSupporter === 'boolean', '`neocities_supporter` input must be a boolean "true" or "false"')
assert(typeof previewDeploy === 'boolean', '`preview_before_deploy` input must be a boolean "true" or "false"')
const stat = await fs.stat(distDir)
assert(stat.isDirectory(), '`dist_dir` input must be a path to a directory that exists')
const client = new NeocitiesAPIClient(key)
if (previewDeploy) {
const previewTimer = new SimpleTimer()
console.log('Running deploy preview prior to deployment...\n\n')
const diff = await client.previewDeploy({
directory: distDir,
includeUnsupportedFiles: neocitiesSupporter,
protectedFileFilter: protectedFilesGlob ? minimatch.filter(protectedFilesGlob) : undefined
})
previewTimer.stop()
printPreviewText({
diff,
timer: previewTimer,
cleanup,
includeUnsupportedFiles: neocitiesSupporter
})
}
const deployTimer = new SimpleTimer()
console.log('Deploying to Neocities...')
const results = await client.deploy({
directory: distDir,
cleanup,
includeUnsupportedFiles: neocitiesSupporter,
protectedFileFilter: protectedFilesGlob ? minimatch.filter(protectedFilesGlob) : undefined
})
deployTimer.stop()
if (results.errors.length > 0) {
printResultsErrorDump({
results,
timer: deployTimer
})
core.setFailed('The deploy completed with errors.')
} else {
printDeployText({
results,
timer: deployTimer,
cleanup,
includeUnsupportedFiles: neocitiesSupporter
})
}
}
run().catch(err => {
console.log('Unexpected error/throw during deployment:\n\n')
console.dir(err, { colors: true, depth: 999 })
core.setFailed(err instanceof Error ? err.message : `An unexpected error occurred during deployment: ${err}`)
})