Skip to content

Commit afca82c

Browse files
committed
Setup Action
1 parent 8b56e94 commit afca82c

File tree

10 files changed

+33964
-0
lines changed

10 files changed

+33964
-0
lines changed

.github/workflows/test.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: "Test"
2+
on:
3+
pull_request:
4+
types:
5+
- opened
6+
- reopened
7+
- synchronize
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
main:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Harden Runner
17+
uses: step-security/harden-runner@v2
18+
with:
19+
egress-policy: audit
20+
21+
- uses: actions/checkout@v3
22+
- uses: ./
23+
with:
24+
name: "new-json-file.json"
25+
json: '{"name":"user", "password":"mypass"}'

.gitignore

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# IntelliJ
2+
.idea/
3+
4+
# Dependency directory
5+
node_modules
6+
7+
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
8+
# Logs
9+
logs
10+
*.log
11+
npm-debug.log*
12+
yarn-debug.log*
13+
yarn-error.log*
14+
lerna-debug.log*
15+
16+
# Diagnostic reports (https://nodejs.org/api/report.html)
17+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
18+
19+
# Runtime data
20+
pids
21+
*.pid
22+
*.seed
23+
*.pid.lock
24+
25+
# Directory for instrumented libs generated by jscoverage/JSCover
26+
lib-cov
27+
28+
# Coverage directory used by tools like istanbul
29+
coverage
30+
*.lcov
31+
32+
# nyc test coverage
33+
.nyc_output
34+
35+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
36+
.grunt
37+
38+
# Bower dependency directory (https://bower.io/)
39+
bower_components
40+
41+
# node-waf configuration
42+
.lock-wscript
43+
44+
# Compiled binary addons (https://nodejs.org/api/addons.html)
45+
build/Release
46+
47+
# Dependency directories
48+
jspm_packages/
49+
50+
# TypeScript v1 declaration files
51+
typings/
52+
53+
# TypeScript cache
54+
*.tsbuildinfo
55+
56+
# Optional npm cache directory
57+
.npm
58+
59+
# Optional eslint cache
60+
.eslintcache
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
78+
# next.js build output
79+
.next
80+
81+
# nuxt.js build output
82+
.nuxt
83+
84+
# vuepress build output
85+
.vuepress/dist
86+
87+
# Serverless directories
88+
.serverless/
89+
90+
# FuseBox cache
91+
.fusebox/
92+
93+
# DynamoDB Local files
94+
.dynamodb/
95+
96+
# OS metadata
97+
.DS_Store
98+
Thumbs.db
99+
100+
# Ignore built ts files
101+
__tests__/runner/*
102+
lib/**/*

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 José Daniel
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

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
## Create .json file to use in other steps of the workflow
2+
3+
---
4+
5+
Example of the output on the .json file created:
6+
7+
```json
8+
{
9+
"name": "step-security",
10+
"password": "mypass"
11+
}
12+
```
13+
14+
### How to use
15+
16+
You can define a json structure on the secrets of your repository:
17+
18+
```json
19+
{
20+
"name": "step-security",
21+
"password": "mypass"
22+
}
23+
```
24+
25+
<sub><sup>MY_JSON (Secrets variables can be configured on repository settings > Secrets)</sup></sub>
26+
27+
and use in this way:
28+
29+
```yaml
30+
- name: create-json
31+
id: create-json
32+
uses: step-security/create-json@v1
33+
with:
34+
name: "credentials.json"
35+
json: ${{ secrets.MY_JSON }}
36+
```
37+
38+
Or just declare a string of a json on the property `json` like:
39+
40+
```yaml
41+
- name: create-json
42+
id: create-json
43+
uses: step-security/create-json@v1
44+
with:
45+
name: "new-json-file.json"
46+
json: '{"name":"step-security", "password":"mypass"}'
47+
```
48+
49+
<sub><sup>The json have to be inside a string.</sup></sub>
50+
51+
You also can save the json on a subdirectory using the property `dir`:
52+
53+
```yaml
54+
- name: create-json
55+
id: create-json
56+
uses: step-security/create-json@v1
57+
with:
58+
name: "credentials.json"
59+
json: ${{ secrets.CREDENTIALS_JSON }}
60+
dir: "src/"
61+
```
62+
63+
Remember that when you create a .json file, the file was not commited, you have to commit the file if you will use the `HEAD` branch with the file to push the repository to other service, like deploy to heroku or other platforms.
64+
65+
If you want to create more than one json files, you have to specify different IDs for the action like:
66+
67+
```yaml
68+
- name: create-json
69+
id: create-json-1 # First ID
70+
uses: step-security/create-json@v1
71+
with:
72+
name: "credentials.json"
73+
json: ${{ secrets.CREDENTIALS_JSON }}
74+
dir: "src/"
75+
- name: create-json
76+
id: create-json-2 # Second ID
77+
uses: step-security/create-json@v1
78+
with:
79+
name: "other.json"
80+
json: '{"name":"step-security", "password":"mypass"}'
81+
dir: "src/"
82+
```
83+
84+
### Real Example (Creating and Using on Other Steps)
85+
86+
```yaml
87+
name: Heroku CI - CD
88+
89+
on:
90+
push:
91+
branches: [master]
92+
93+
jobs:
94+
deploy:
95+
runs-on: ubuntu-latest
96+
steps:
97+
- uses: actions/checkout@master
98+
- uses: actions/setup-go@v1
99+
with:
100+
go-version: "1.14.6"
101+
- run: cd src && go mod vendor
102+
- name: create-json
103+
id: create-json
104+
uses: step-security/create-json@v1
105+
with:
106+
name: "devdatatools-firebase-adminsdk.json"
107+
json: ${{ secrets.CREDENTIALS_JSON }}
108+
dir: "src/"
109+
- run: git config --global user.email "[email protected]" && git config --global user.name "step-security" && git add . && git add --force src/devdatatools-firebase-adminsdk.json && git status && git commit -a -m "Deploy Heroku Commit with the Credentials JSON created!"
110+
- uses: akhileshns/[email protected]
111+
with:
112+
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
113+
heroku_app_name: "dev-data-tools-api-golang"
114+
heroku_email: "[email protected]"
115+
appdir: "src"
116+
```
117+
118+
After commit and use with Heroku the file is deleted after the workflow and the JSON is not showed on the log, perfect for public repositories.

SECURITY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Security Policy
2+
3+
## Reporting a Vulnerability
4+
5+
Please report security vulnerabilities to [email protected]

action.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: "create-json"
2+
description: "Create an JSON file from secret or a string of a json."
3+
inputs:
4+
name:
5+
description: "The name of the file to be written. | file.json "
6+
required: true
7+
json:
8+
description: 'The json string that can be a secret of the github repo or a string of a json. | "{"title": "my json"}" '
9+
required: true
10+
dir:
11+
description: "Optional subfolder directory to save the json file. | src/ "
12+
required: false
13+
outputs:
14+
successfully:
15+
description: "Feedback message of success "
16+
runs:
17+
using: "node16"
18+
main: "./dist/index.js"
19+
branding:
20+
icon: "shield"
21+
color: "green"

0 commit comments

Comments
 (0)