Skip to content

Commit

Permalink
Merge pull request #237 from HatsuneMiku3939/master
Browse files Browse the repository at this point in the history
bump v1.0.4
  • Loading branch information
HatsuneMiku3939 authored Nov 8, 2023
2 parents 5456156 + eb086d9 commit 43e04c1
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export DIRENV_ACTION_TEST=HatsuneMiku3939
export PATH=$PATH:$(pwd)/bin
export SECRET1=ULTRA_SECRET1
export SECRET2=VERY_SECRET2
export SECRET3=THIS_IS_UNMASKED
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
- run: npm run prepare
- uses: ./
with:
masks: SECRET1, SECRET2
direnvVersion: 2.32.3
- run: printenv | grep DIRENV_ACTION_TEST
- run: echo $PATH | grep $(pwd)/bin
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This action provides environment variables via [direnv](https://direnv.net/),
## Inputs

- `direnvVersion`: The version of direnv to use. Default: `2.32.1`
- `masks`: Comma seprated list of environment variables to mask. Default: `''`

## Outputs

Expand All @@ -23,6 +24,7 @@ No outputs
uses: HatsuneMiku3939/direnv-action@v1
with:
direnvVersion: 2.32.1
masks: SECRET1, SECRET2
```
This will load `.envrc` residing at the top of the repository.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ branding:
icon: play
color: green
inputs:
masks:
description: 'Comma seprated list of environment variables to mask'
required: true
default: ''
direnvVersion:
description: 'direnv version to use'
required: true
Expand Down
20 changes: 20 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3783,11 +3783,28 @@ async function exportEnvrc() {
outputBuffer += data.toString();
}
};
options.silent = true;

core.info('exporting envrc...');
await exec.exec(`direnv`, ['export', 'json'], options);
return JSON.parse(outputBuffer);
}

async function setMasks(envs) {
const rawMaskList = core.getInput('masks');
const maskList = rawMaskList.split(',').map(function (mask) {
return mask.trim();
});
core.info(`setting masks: ${maskList.join(', ')}`);

maskList.forEach(function (mask) {
const value = envs[mask];
if (value) {
core.setSecret(value);
}
});
}

// action entrypoint
async function main() {
try {
Expand All @@ -3811,6 +3828,9 @@ async function main() {
core.exportVariable(name, value);
}
});

// set masks
await setMasks(envs);
}
catch (error) {
core.setFailed(error.message);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,28 @@ async function exportEnvrc() {
outputBuffer += data.toString();
}
};
options.silent = true;

core.info('exporting envrc...');
await exec.exec(`direnv`, ['export', 'json'], options);
return JSON.parse(outputBuffer);
}

async function setMasks(envs) {
const rawMaskList = core.getInput('masks');
const maskList = rawMaskList.split(',').map(function (mask) {
return mask.trim();
});
core.info(`setting masks: ${maskList.join(', ')}`);

maskList.forEach(function (mask) {
const value = envs[mask];
if (value) {
core.setSecret(value);
}
});
}

// action entrypoint
async function main() {
try {
Expand All @@ -106,6 +123,9 @@ async function main() {
core.exportVariable(name, value);
}
});

// set masks
await setMasks(envs);
}
catch (error) {
core.setFailed(error.message);
Expand Down

0 comments on commit 43e04c1

Please sign in to comment.