Skip to content

Commit d43a337

Browse files
committed
My first action is ready
0 parents  commit d43a337

File tree

391 files changed

+90103
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

391 files changed

+90103
-0
lines changed

.github/workflows/test.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Test
5+
6+
on:
7+
push:
8+
tags:
9+
- '*'
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
name: Runs this action
15+
steps:
16+
- name: action
17+
uses: du5rte/create-secrets-file@v1
18+
with:
19+
secrets: |
20+
API_KEY=${{ secrets.API_KEY }}
21+
SECRET_KEY=${{ secrets.SECRET_KEY }}
22+
DB_URI=${{ secrets.DB_URI }}
23+
file: .env # optional

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Duarte Monteiro
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<p align="center"><a href="https://github.com/du5rte/secrets" target="_blank" rel="noopener noreferrer"><img width="100" src="key.svg" alt="Key"></a></p>
2+
3+
<p align="center"><a href="https://github.com/du5rte/secrets"><img alt="GitHub Actions Test Status" src="https://github.com/du5rte/secrets/workflows/Test/badge.svg"/></p>
4+
5+
# Create Secrets File Action
6+
7+
This action creates a secrets file (e.g. `.env`) by taking environment keys from github secrets.
8+
9+
10+
## Example usage
11+
12+
```yaml
13+
uses: du5rte/create-secrets-file@v1
14+
with:
15+
secrets: |
16+
API_KEY=${{ secrets.API_KEY }}
17+
SECRET_KEY=${{ secrets.SECRET_KEY }}
18+
DB_URI=${{ secrets.DB_URI }}
19+
# optionals
20+
# file: .env
21+
# mode: dotenv
22+
# path: src
23+
```
24+
25+
**Note!**
26+
By default the action dirname would be `/home/runner/work/_actions/du5rte/create-secrets-file/v1` instead it saves it 3 scopes bellow to be accessible to other actions `/home/runner/work/.env`.
27+
28+
### Node.js
29+
If you need a simple secrets handler for Node.js 🗝️, checkout [secrets](https://github.com/du5rte/secrets)
30+
31+
```javascript
32+
import 'secrets'
33+
```
34+
35+
### Babel Plugin
36+
Also works with babel
37+
38+
```
39+
module.exports = {
40+
presets: ['module:metro-react-native-babel-preset'],
41+
plugins: ['secrets/babel-plugin-secrets'],
42+
}
43+
```
44+
45+
## Github Action
46+
To create secrets `.env` file on demands on your github actions checkout [du5rte/create-secrets-file](https://github.com/du5rte/create-secrets-file)
47+
48+
49+
## Inputs
50+
51+
### `secrets`
52+
53+
**Required** The environment keys you wish to save to the file
54+
55+
### `file`
56+
57+
**Optional** The file name it will save it to. Default `.env`.
58+
59+
## Outputs
60+
61+
### `logs`
62+
It should output what keys were parsed and the file
63+
64+
```
65+
Found ".env" in "/":
66+
{
67+
API_KEY: ***
68+
SECRET_KEY: ***
69+
DB_URI: ***
70+
}
71+
```
72+
73+
### `file`
74+
It should then
75+
```
76+
API_KEY: 9j39j39j39j39j3
77+
SECRET_KEY: 0k30k30k30k30k30k3
78+
DB_URI: mongodb+srv://cluster-6f36f36f3.mongodb.net
79+
```

action.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: 'Create Secrets File Action'
2+
description: 'Creating a secrets file from github secrets.'
3+
inputs:
4+
secrets:
5+
description: 'The environment keys'
6+
required: true
7+
file:
8+
description: 'The file name'
9+
default: '.env'
10+
mode:
11+
description: 'Mode can be "dotenv" on "json"'
12+
default: 'dotenv'
13+
path:
14+
description: 'The file root path'
15+
# by default the directory will be
16+
# '/home/runner/work/_actions/du5rte/create-secrets-file/v1'
17+
# this will allow next actions to access it
18+
default: '../../../..'
19+
outputs:
20+
parsed:
21+
description: 'Object version of secrets'
22+
location:
23+
description: 'Location of secrets file'
24+
sanatized:
25+
description: 'Sanatized version of secrets'
26+
success:
27+
description: 'True or False' # boolean
28+
runs:
29+
using: 'node12'
30+
main: 'index.js'
31+
branding:
32+
color: black
33+
icon: eye-off

index.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
const core = require("@actions/core");
5+
const github = require("@actions/github");
6+
7+
// Another Package I've wrote
8+
// https://github.com/du5rte/secrets
9+
const secrets = require("secrets");
10+
11+
try {
12+
const raw = core.getInput("secrets");
13+
const filename = core.getInput("file");
14+
const pathname = core.getInput("path");
15+
const mode = core.getInput("mode");
16+
17+
const parsed = secrets.parse(raw.trim());
18+
19+
if (parsed.length === 0) {
20+
throw new Error("No secrets received");
21+
}
22+
23+
core.setOutput("parsed", parsed);
24+
25+
const fullpath = path.resolve(__dirname, pathname, filename);
26+
27+
console.log("Secrets parsed");
28+
29+
core.setOutput("location", fullpath);
30+
31+
const generated = secrets.format(parsed, mode);
32+
33+
fs.writeFileSync(fullpath, generated);
34+
35+
console.log("Secrets file created");
36+
37+
console.log("Verifying...");
38+
39+
const found = secrets.search();
40+
41+
const sanatized = secrets.sanatize(found);
42+
43+
core.setOutput("sanatized", sanatized);
44+
45+
core.setOutput("success", true);
46+
} catch (error) {
47+
core.setFailed(error.message);
48+
}

key.svg

+1
Loading

node_modules/.yarn-integrity

+43
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/LICENSE.md

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)