dockerhub-description/src/main.ts
2022-08-18 12:17:06 +09:00

40 lines
1.1 KiB
TypeScript

import * as core from '@actions/core'
import * as inputHelper from './input-helper'
import * as dockerhubHelper from './dockerhub-helper'
import * as fs from 'fs'
import {inspect} from 'util'
async function run(): Promise<void> {
try {
const inputs = inputHelper.getInputs()
core.debug(`Inputs: ${inspect(inputs)}`)
inputHelper.validateInputs(inputs)
// Fetch the readme content
const readmeContent = await fs.promises.readFile(inputs.readmeFilepath, {
encoding: 'utf8'
})
// Acquire a token for the Docker Hub API
core.info('Acquiring token')
const token = await dockerhubHelper.getToken(
inputs.username,
inputs.password
)
// Send a PATCH request to update the description of the repository
core.info('Sending PATCH request')
await dockerhubHelper.updateRepositoryDescription(
token,
inputs.repository,
inputs.shortDescription,
readmeContent
)
core.info('Request successful')
} catch (error: any) {
core.debug(inspect(error))
core.setFailed(error.message)
}
}
run()