dockerhub-description/src/main.ts

41 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-09-23 08:58:52 +02:00
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'
2020-09-23 08:58:52 +02:00
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(
2020-09-25 04:13:16 +02:00
inputs.username,
inputs.password
2020-09-23 08:58:52 +02:00
)
// Send a PATCH request to update the description of the repository
core.info('Sending PATCH request')
await dockerhubHelper.updateRepositoryDescription(
token,
2020-09-25 04:13:16 +02:00
inputs.repository,
2020-09-25 08:22:36 +02:00
inputs.shortDescription,
2020-09-23 08:58:52 +02:00
readmeContent
)
core.info('Request successful')
2021-09-02 06:50:05 +02:00
} catch (error: any) {
2020-09-23 08:58:52 +02:00
core.debug(inspect(error))
core.setFailed(error.message)
}
}
run()