Skip to content

Commit

Permalink
Option to disable POSIX annotation warnings
Browse files Browse the repository at this point in the history
Co-authored-by: Abhilash Kishore <[email protected]>
  • Loading branch information
jbabala and abhilash1in committed May 7, 2022
1 parent 69c4deb commit e348a56
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ steps:
| `true` | `foo` = `{ "bar": "baz" }`<br>`ham` = `eggs` | `FOO_BAR` = `baz` AND<br>`ham` = `eggs` | If multiple secrets, values that can be parsed into a JSON will be parsed and flattened |
| `false` | `dev_foo` = `{ "bar": "baz" }` | `DEV_FOO` = `{ "bar": "baz" }` | Not parsed |

- `disable-warnings`
- If `disable-warnings: true`, warnings regarding POSIX compliance in GitHub Actions output will be suppressed.

#### Note:
- `${{ secrets.AWS_ACCESS_KEY_ID }}`, `${{ secrets.AWS_SECRET_ACCESS_KEY }}` and `${{ secrets.AWS_REGION }}` refers to [GitHub Secrets](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets). Create the required secrets in your GitHub repository before using them in this GitHub Action.
- If your AWS Secrets Manager secret name contains any characters other than upper case letters, digits and underscores, it will not be used directly as the environment variable name. Rather, it will be transformed into a string that only contains upper case letters, digits and underscores. Refer the table above for examples.
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ inputs:
description: 'If true and secret values are stringified JSON objects, they will be parsed and flattened. Its key value pairs will become individual secrets'
required: false
default: 'false'
disable-warnings:
description: 'If true, disable annotation warnings in the GitHub Actions output.'
required: false
default: 'false'
runs:
using: 'node12'
main: 'dist/index.js'
Expand Down
5 changes: 4 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33303,12 +33303,14 @@ var Inputs;
(function (Inputs) {
Inputs["SECRETS"] = "secrets";
Inputs["PARSE_JSON"] = "parse-json";
Inputs["DISABLE_WARNINGS"] = "disable-warnings";
})(Inputs || (Inputs = {}));

// EXTERNAL MODULE: ./node_modules/aws-sdk/lib/aws.js
var aws = __webpack_require__(71786);
// CONCATENATED MODULE: ./src/utils.ts


/* Validate a possible object i.e., o = { "a": 2 } */
const isJSONObject = (o) => !!o && (typeof o === 'object') && !Array.isArray(o) &&
(() => { try {
Expand Down Expand Up @@ -33370,13 +33372,14 @@ const getPOSIXString = (data) => {
return data.replace(/[^a-zA-Z0-9_]/g, '_').toUpperCase();
};
const injectSecretValueMapToEnvironment = (secretValueMap) => {
const disableWarnings = core.getBooleanInput(Inputs.DISABLE_WARNINGS);
for (const secretName in secretValueMap) {
const secretValue = secretValueMap[secretName];
core.setSecret(secretValue);
// If secretName contains non-posix characters, it can't be read by the shell
// Get POSIX compliant name secondary env name that can be read by the shell
const secretNamePOSIX = getPOSIXString(secretName);
if (secretName !== secretNamePOSIX) {
if (secretName !== secretNamePOSIX && !disableWarnings) {
core.warning('One of the secrets has a name that is not POSIX compliant and hence cannot directly \
be used/injected as an environment variable name. Therefore, it will be transformed into a POSIX compliant \
environment variable name. Enable GitHub Actions Debug Logging \
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export enum Inputs {
SECRETS = 'secrets',
PARSE_JSON = 'parse-json'
PARSE_JSON = 'parse-json',
DISABLE_WARNINGS = 'disable-warnings'
}
5 changes: 4 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as core from '@actions/core'
import { Inputs } from './constants'

/* Validate a possible object i.e., o = { "a": 2 } */
export const isJSONObject = (o: Record<string, any>): boolean =>
Expand Down Expand Up @@ -61,13 +62,15 @@ export const getPOSIXString = (data: string): string => {
}

export const injectSecretValueMapToEnvironment = (secretValueMap: Record<string, any>): void => {
const disableWarnings = core.getBooleanInput(Inputs.DISABLE_WARNINGS)

for (const secretName in secretValueMap) {
const secretValue: string = secretValueMap[secretName]
core.setSecret(secretValue)
// If secretName contains non-posix characters, it can't be read by the shell
// Get POSIX compliant name secondary env name that can be read by the shell
const secretNamePOSIX = getPOSIXString(secretName)
if (secretName !== secretNamePOSIX) {
if (secretName !== secretNamePOSIX && !disableWarnings) {
core.warning('One of the secrets has a name that is not POSIX compliant and hence cannot directly \
be used/injected as an environment variable name. Therefore, it will be transformed into a POSIX compliant \
environment variable name. Enable GitHub Actions Debug Logging \
Expand Down

0 comments on commit e348a56

Please sign in to comment.