2020-09-23 08:58:52 +02:00
|
|
|
import * as core from '@actions/core'
|
|
|
|
|
|
|
|
const README_FILEPATH_DEFAULT = './README.md'
|
|
|
|
|
|
|
|
interface Inputs {
|
2020-09-25 04:13:16 +02:00
|
|
|
username: string
|
|
|
|
password: string
|
|
|
|
repository: string
|
2020-09-25 08:22:36 +02:00
|
|
|
shortDescription: string
|
2020-09-23 08:58:52 +02:00
|
|
|
readmeFilepath: string
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getInputs(): Inputs {
|
|
|
|
const inputs = {
|
2020-09-25 04:13:16 +02:00
|
|
|
username: core.getInput('username'),
|
|
|
|
password: core.getInput('password'),
|
|
|
|
repository: core.getInput('repository'),
|
2020-09-25 08:22:36 +02:00
|
|
|
shortDescription: core.getInput('short-description'),
|
2020-09-23 08:58:52 +02:00
|
|
|
readmeFilepath: core.getInput('readme-filepath')
|
|
|
|
}
|
|
|
|
|
|
|
|
// Environment variable input alternatives and their aliases
|
|
|
|
|
2020-09-25 04:13:16 +02:00
|
|
|
if (!inputs.username && process.env['DOCKERHUB_USERNAME']) {
|
|
|
|
inputs.username = process.env['DOCKERHUB_USERNAME']
|
2020-09-23 08:58:52 +02:00
|
|
|
}
|
2020-09-25 04:13:16 +02:00
|
|
|
if (!inputs.username && process.env['DOCKER_USERNAME']) {
|
|
|
|
inputs.username = process.env['DOCKER_USERNAME']
|
2020-09-23 08:58:52 +02:00
|
|
|
}
|
|
|
|
|
2020-09-25 04:13:16 +02:00
|
|
|
if (!inputs.password && process.env['DOCKERHUB_PASSWORD']) {
|
|
|
|
inputs.password = process.env['DOCKERHUB_PASSWORD']
|
2020-09-23 08:58:52 +02:00
|
|
|
}
|
2020-09-25 04:13:16 +02:00
|
|
|
if (!inputs.password && process.env['DOCKER_PASSWORD']) {
|
|
|
|
inputs.password = process.env['DOCKER_PASSWORD']
|
2020-09-23 08:58:52 +02:00
|
|
|
}
|
|
|
|
|
2020-09-25 04:13:16 +02:00
|
|
|
if (!inputs.repository && process.env['DOCKERHUB_REPOSITORY']) {
|
|
|
|
inputs.repository = process.env['DOCKERHUB_REPOSITORY']
|
2020-09-23 08:58:52 +02:00
|
|
|
}
|
2020-09-25 04:13:16 +02:00
|
|
|
if (!inputs.repository && process.env['DOCKER_REPOSITORY']) {
|
|
|
|
inputs.repository = process.env['DOCKER_REPOSITORY']
|
2020-09-23 08:58:52 +02:00
|
|
|
}
|
|
|
|
|
2020-09-25 08:22:36 +02:00
|
|
|
if (!inputs.shortDescription && process.env['SHORT_DESCRIPTION']) {
|
|
|
|
inputs.shortDescription = process.env['SHORT_DESCRIPTION']
|
|
|
|
}
|
|
|
|
|
2020-09-23 08:58:52 +02:00
|
|
|
if (!inputs.readmeFilepath && process.env['README_FILEPATH']) {
|
|
|
|
inputs.readmeFilepath = process.env['README_FILEPATH']
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set defaults
|
|
|
|
if (!inputs.readmeFilepath) {
|
|
|
|
inputs.readmeFilepath = README_FILEPATH_DEFAULT
|
|
|
|
}
|
2020-09-25 07:41:18 +02:00
|
|
|
if (!inputs.repository && process.env['GITHUB_REPOSITORY']) {
|
|
|
|
inputs.repository = process.env['GITHUB_REPOSITORY']
|
|
|
|
}
|
2020-09-23 08:58:52 +02:00
|
|
|
|
2021-02-04 01:54:07 +01:00
|
|
|
// Docker repositories must be all lower case
|
|
|
|
inputs.repository = inputs.repository.toLowerCase()
|
|
|
|
|
2020-09-23 08:58:52 +02:00
|
|
|
return inputs
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkRequiredInput(input: string, name: string): void {
|
|
|
|
if (!input) {
|
|
|
|
throw new Error(`Required input '${name}' is missing.`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function validateInputs(inputs: Inputs): void {
|
2020-09-25 04:13:16 +02:00
|
|
|
checkRequiredInput(inputs.username, 'username')
|
|
|
|
checkRequiredInput(inputs.password, 'password')
|
2020-09-23 08:58:52 +02:00
|
|
|
}
|