Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* #277 - Fix emibcn/badge-action#18

* Fix https://deepsource.io/gh/emibcn/github-badge-action/run/758fc6ba-5019-4a2b-ab32-23242cc066c3/javascript/JS-C1003 - Avoid using wildcard imports - JS-C1003

* Fix `set-output` in own test GH workflow
  • Loading branch information
emibcn authored Dec 9, 2022
1 parent 94cb846 commit 8a5c640
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
else
EXPORT_VALUE="${TMP_GITHUB_REF}"
fi
echo "##[set-output name=branch;]$(echo ${EXPORT_VALUE})"
echo "branch=${EXPORT_VALUE}" >> "${GITHUB_OUTPUT}"
id: extract_branch

- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"access": "public"
},
"dependencies": {
"@actions/core": "^1.3.0",
"@actions/core": "^1.10.0",
"gradient-badge": "^1.3.1"
},
"devDependencies": {
Expand Down
29 changes: 18 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import * as core from '@actions/core'
import {
getInput,
debug,
info,
setOutput,
error,
setFailed
} from '@actions/core'
import gradientBadge from 'gradient-badge'
import fs from 'fs'
import defaultInputMap from './defaultInputMap'
Expand All @@ -14,42 +21,42 @@ const createBadgeFromInputs = ({
const inputs = Object.entries(inputMap).reduce(
(acc, [key, inputName]) => ({
...acc,
[key]: core.getInput(inputName)
[key]: getInput(inputName)
}),
{}
)

console.log('Received inputs:', inputs)
debug('Received inputs:', inputs)

// Fix some inputs
for (const [key, fn] of Object.entries(inputFixes)) {
inputs[key] = fn(inputs)
}

console.log('Generate badge using the given inputs and defaults:', inputs)
info('Generate badge using the given inputs and defaults:', inputs)

// Generate the badge
const { path, ...gradientBadgeOptions } = inputs
const svgString = gradientBadge(gradientBadgeOptions)

// Output badge contents to Action output
if (outputName?.length) {
console.log("Write data to action's output 'badge'...")
core.setOutput(outputName, svgString)
info("Write data to action's output 'badge'...")
setOutput(outputName, svgString)
}

// If path is defined, save SVG data to that file
if (path?.length) {
console.log(`Write data to file ${path}...`)
info(`Write data to file ${path}...`)

// In case an error occurred writing file,
// exception is thrown and success messsage is not printed
fs.writeFileSync(path, svgString)
console.log('Data saved succesfully.')
info('Data saved succesfully.')
}
} catch (error) {
console.error(error)
core.setFailed(error.message)
} catch (err) {
error(err)
setFailed(err.message)
}
}

Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# yarn lockfile v1


"@actions/core@^1.3.0":
"@actions/core@^1.10.0":
version "1.10.0"
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.10.0.tgz#44551c3c71163949a2f06e94d9ca2157a0cfac4f"
integrity sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==
Expand Down

0 comments on commit 8a5c640

Please sign in to comment.