Files
dockerhub-description/src/main.ts
Peter Evans 579f64ca0a
Some checks failed
Publish Docker Image / publish (push) Has been cancelled
fix: use the truncated short description (#148)
2023-04-10 08:18:10 +09:00

60 lines
1.8 KiB
TypeScript

import * as core from '@actions/core'
import * as inputHelper from './input-helper'
import * as dockerhubHelper from './dockerhub-helper'
import * as readmeHelper from './readme-helper'
import * as utils from './utils'
import {inspect} from 'util'
const SHORT_DESCRIPTION_MAX_BYTES = 100
async function run(): Promise<void> {
try {
const inputs = inputHelper.getInputs()
core.debug(`Inputs: ${inspect(inputs)}`)
inputHelper.validateInputs(inputs)
// Fetch the readme content
core.info('Reading description source file')
const readmeContent = await readmeHelper.getReadmeContent(
inputs.readmeFilepath,
inputs.enableUrlCompletion,
inputs.imageExtensions
)
core.debug(readmeContent)
// Truncate the short description if it is too long
const truncatedShortDescription = utils.truncateToBytes(
inputs.shortDescription,
SHORT_DESCRIPTION_MAX_BYTES
)
if (truncatedShortDescription.length !== inputs.shortDescription.length) {
core.warning(
`The short description exceeds DockerHub's limit and has been truncated to ${SHORT_DESCRIPTION_MAX_BYTES} bytes.`
)
}
core.debug(`Truncated short description: ${truncatedShortDescription}`)
// 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,
truncatedShortDescription,
readmeContent
)
core.info('Request successful')
} catch (error) {
core.debug(inspect(error))
core.setFailed(utils.getErrorMessage(error))
}
}
run()