fix(app/docker): correctly parse input variables (#852)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
## 0️ Prepare your machine
|
||||
|
||||
A server with a recent version of [docker](https://www.docker.com/) is required.
|
||||
A machine with a recent version of [docker](https://www.docker.com/) is required.
|
||||
|
||||
## 1️ Run docker image
|
||||
|
||||
@@ -12,3 +12,7 @@ docker run --env INPUT_TOKEN=**** --env INPUT_USER=user --volume=/tmp:/renders g
|
||||
```
|
||||
|
||||
To pass parameters, pass environment variable with the same name as the corresponding action option but in uppercase and prefixed with `INPUT_`.
|
||||
|
||||
Generated files will be created in the mounted `/renders` directory.
|
||||
|
||||
> 💡 When running *metrics* with docker, [`output_action`](/source/plugins/core/README.md#-configuring-output-action) will automatically default to `none` instead. To use a different output action, both `GITHUB_REPOSITORY` (notice the absence of `INPUT_` prefix) and `INPUT_COMMITTER_TOKEN` (with sufficient permissions) environment variables must be set.
|
||||
|
||||
@@ -94,6 +94,14 @@ async function retry(func, {retries = 1, delay = 0} = {}) {
|
||||
info("Setup", "complete")
|
||||
info("Version", conf.package.version)
|
||||
|
||||
//Docker run environment default values
|
||||
if (!metadata.env.ghactions) {
|
||||
info("Docker environment", "(enabled)")
|
||||
process.env.INPUT_OUTPUT_ACTION = process.env.INPUT_OUTPUT_ACTION ?? "none"
|
||||
process.env.INPUT_COMMITTER_TOKEN = process.env.INPUT_COMMITTER_TOKEN ?? process.env.INPUT_TOKEN
|
||||
process.env.GITHUB_REPOSITORY = process.env.GITHUB_REPOSITORY ?? "octocat/hello-world"
|
||||
}
|
||||
|
||||
//Core inputs
|
||||
Object.assign(preset, await presets(core.getInput("config_presets"), {log:false, core}))
|
||||
const {
|
||||
@@ -150,7 +158,7 @@ async function retry(func, {retries = 1, delay = 0} = {}) {
|
||||
//See https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats
|
||||
info("GitHub token format", /^gh[pousr]_/.test(token) ? "correct" : "(old or invalid)")
|
||||
if (!token)
|
||||
throw new Error("You must provide a valid GitHub personal token to gather your metrics (see https://github.com/lowlighter/metrics/blob/master/.github/readme/partials/setup/action/setup.md for more informations)")
|
||||
throw new Error("You must provide a valid GitHub personal token to gather your metrics (see https://github.com/lowlighter/metrics/blob/master/.github/readme/partials/documentation/setup/action.md for more informations)")
|
||||
conf.settings.token = token
|
||||
const api = {}
|
||||
api.graphql = octokit.graphql.defaults({headers:{authorization:`token ${token}`}})
|
||||
@@ -167,7 +175,7 @@ async function retry(func, {retries = 1, delay = 0} = {}) {
|
||||
const {headers} = await api.rest.request("HEAD /")
|
||||
if (!("x-oauth-scopes" in headers)) {
|
||||
throw new Error(
|
||||
'GitHub API did not send any "x-oauth-scopes" header back from provided "token". It means that your token may not be valid or you\'re using GITHUB_TOKEN which cannot be used since metrics will fetch data outside of this repository scope. Use a personal access token instead (see https://github.com/lowlighter/metrics/blob/master/.github/readme/partials/setup/action/setup.md for more informations).',
|
||||
'GitHub API did not send any "x-oauth-scopes" header back from provided "token". It means that your token may not be valid or you\'re using GITHUB_TOKEN which cannot be used since metrics will fetch data outside of this repository scope. Use a personal access token instead (see https://github.com/lowlighter/metrics/blob/master/.github/readme/partials/documentation/setup/action.md for more informations).',
|
||||
)
|
||||
}
|
||||
info("Token validity", "seems ok")
|
||||
@@ -190,11 +198,12 @@ async function retry(func, {retries = 1, delay = 0} = {}) {
|
||||
info("GitHub repository", `${user}/${q.repo}`)
|
||||
|
||||
//Current repository
|
||||
info("Current repository", `${github.context.repo.owner}/${github.context.repo.repo}`)
|
||||
if (metadata.env.ghactions)
|
||||
info("Current repository", `${github.context.repo.owner}/${github.context.repo.repo}`)
|
||||
|
||||
//Committer
|
||||
const committer = {}
|
||||
if (!dryrun) {
|
||||
if ((!dryrun)&&(_action !== "none")) {
|
||||
//Compute committer informations
|
||||
committer.token = _token || token
|
||||
committer.gist = _action === "gist" ? _gist : null
|
||||
@@ -236,7 +245,6 @@ async function retry(func, {retries = 1, delay = 0} = {}) {
|
||||
}
|
||||
else
|
||||
throw error
|
||||
|
||||
}
|
||||
//Retrieve previous render SHA to be able to update file content through API
|
||||
committer.sha = null
|
||||
@@ -258,7 +266,7 @@ async function retry(func, {retries = 1, delay = 0} = {}) {
|
||||
}
|
||||
info("Previous render sha", committer.sha ?? "(none)")
|
||||
}
|
||||
else
|
||||
else if (dryrun)
|
||||
info("Dry-run", true)
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,9 @@ const categories = ["core", "github", "social", "community"]
|
||||
//Previous descriptors
|
||||
let previous = null
|
||||
|
||||
//Environment
|
||||
const env = {ghactions:`${process.env.GITHUB_ACTIONS}` === "true"}
|
||||
|
||||
/**Metadata descriptor parser */
|
||||
export default async function metadata({log = true, diff = false} = {}) {
|
||||
//Paths
|
||||
@@ -81,7 +84,7 @@ export default async function metadata({log = true, diff = false} = {}) {
|
||||
const descriptor = yaml.load(`${await fs.promises.readFile(__descriptor, "utf-8")}`)
|
||||
|
||||
//Metadata
|
||||
return {plugins:Plugins, templates:Templates, packaged, descriptor}
|
||||
return {plugins:Plugins, templates:Templates, packaged, descriptor, env}
|
||||
}
|
||||
|
||||
/**Metadata extractor for inputs */
|
||||
@@ -244,14 +247,19 @@ metadata.plugin = async function({__plugins, __templates, name, logger}) {
|
||||
const q = {}
|
||||
for (const key of Object.keys(inputs)) {
|
||||
//Parse input
|
||||
let value = `${core.getInput(key)}`.trim()
|
||||
try {
|
||||
value = decodeURIComponent(value)
|
||||
}
|
||||
catch {
|
||||
logger(`metrics/inputs > failed to decode uri for ${key}: ${value}`)
|
||||
value = "<default-value>"
|
||||
let value
|
||||
if (env.ghactions) {
|
||||
value = `${core.getInput(key)}`.trim()
|
||||
try {
|
||||
value = decodeURIComponent(value)
|
||||
}
|
||||
catch {
|
||||
logger(`metrics/inputs > failed to decode uri for ${key}: ${value}`)
|
||||
value = "<default-value>"
|
||||
}
|
||||
}
|
||||
else
|
||||
value = process.env[`INPUT_${key.toUpperCase()}`]?.trim() ?? "<default-value>"
|
||||
const unspecified = value === "<default-value>"
|
||||
//From presets
|
||||
if ((key in preset) && (unspecified)) {
|
||||
|
||||
Reference in New Issue
Block a user