Skip to content

Commit 0536ccd

Browse files
committed
refactor: ♻️ inputs name
1 parent 4e9d2fe commit 0536ccd

File tree

8 files changed

+80
-25
lines changed

8 files changed

+80
-25
lines changed

.github/workflows/needs-more-info.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ jobs:
1919
id: generate_token
2020
uses: ./
2121
with:
22-
APP_ID: ${{ secrets.APP_ID }}
23-
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
22+
app_id: ${{ secrets.APP_ID }}
23+
private_key: ${{ secrets.PRIVATE_KEY }}
2424
- uses: bubkoo/needs-more-info@v1
2525
with:
2626
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}

README.md

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,21 @@ This GitHub Action can be used to impersonate a GitHub App when `secrets.GITHUB_
44

55
[`secrets.GITHUB_TOKEN`](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token) has limitations such as [not being able to triggering a new workflow from another workflow](https://github.community/t5/GitHub-Actions/Triggering-a-new-workflow-from-another-workflow/td-p/31676). A workaround is to use a [personal access token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) from a [personal user/bot account](https://help.github.com/en/github/getting-started-with-github/types-of-github-accounts#personal-user-accounts). However, for organizations, GitHub Apps are [a more appropriate automation solution](https://developer.github.com/apps/differences-between-apps/#machine-vs-bot-accounts).
66

7-
## Example Workflow
7+
We can also use an app token to [custom an action's name and avatar](https://github.community/t/change-bots-name-avatar/18349).
8+
9+
![all links](https://github.com/bubkoo/use-app-token/blob/master/screenshot.jpg?raw=true)
10+
11+
## Usage
12+
13+
Use action's output in other actions.
814

915
```yml
16+
name: Needs More Info
17+
on:
18+
pull_request:
19+
types: [opened]
20+
issues:
21+
types: [opened]
1022
jobs:
1123
run:
1224
runs-on: ubuntu-latest
@@ -15,8 +27,8 @@ jobs:
1527
id: generate_token
1628
uses: bubkoo/use-app-token@v1
1729
with:
18-
APP_ID: ${{ secrets.APP_ID }}
19-
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
30+
app_id: ${{ secrets.APP_ID }}
31+
private_key: ${{ secrets.PRIVATE_KEY }}
2032
- name: Needs More info # Use token in other actions
2133
uses: bubkoo/needs-more-info@v1
2234
with:
@@ -25,13 +37,52 @@ jobs:
2537
CONFIG_FILE: .github/workflows/config/needs-more-info.yml
2638
```
2739
28-
### Options
40+
Or set an secret in you repo:
41+
42+
```yml
43+
name: App Token
44+
on:
45+
schedule:
46+
- cron: '0 1 * * *'
47+
jobs:
48+
run:
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: bubkoo/use-app-token@v1
52+
with:
53+
app_id: ${{ secrets.APP_ID }}
54+
private_key: ${{ secrets.PRIVATE_KEY }}
55+
# The secret name
56+
secret_name: APP_TOKEN
57+
```
58+
59+
Then we can use the secret named `'APP_TOKEN'` in other ancitons:
60+
61+
```yml
62+
name: Needs More Info
63+
on:
64+
pull_request:
65+
types: [opened]
66+
issues:
67+
types: [opened]
68+
jobs:
69+
run:
70+
runs-on: ubuntu-latest
71+
steps:
72+
- name: Needs More info
73+
uses: bubkoo/needs-more-info@v1
74+
with:
75+
GITHUB_TOKEN: ${{ secrets.APP_TOKEN }}
76+
CONFIG_FILE: .github/workflows/config/needs-more-info.yml
77+
```
78+
79+
### Inputs
2980
30-
- `APP_ID`: The ID of the GitHub App.
31-
- `PRIVATE_KEY`: The private key of the GitHub App (can be Base64 encoded).
32-
- `VARIABLE_NAME`: The name of generated token in exported variable. Specify a varable name will set an environment variable with specfiied name and valued with generated token, and can be use in next step with `${ VARIABLE_NAME }`.
33-
- `SECRET_NAME`: The secret name created on current repository. Specify a secret name will add an secret on current repository with specfiied name and valued with generated token and can be use in next step with `${{ secrets.SECRET_NAME }}`.
34-
- `CLEAN_SECRET`: Shoule clean the secret or not when the job completed. Only used when `SECRET_NAME` specfiied. Default `false`.
81+
- `app_id`: The ID of the GitHub App. [Create an secret](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets-for-a-repository) named `'APP_ID'` to store your app ID, then used by `${{ secrets.APP_ID }}`
82+
- `private_key`: The private key of the GitHub App (can be Base64 encoded). [Create an secret](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets-for-a-repository) named `'PRIVATE_KEY'` to store your app private key, then used by `${{ secrets.APP_ID }}`
83+
- `variable_name`: The name of generated token in exported variable. Specify a varable name will set an environment variable with specfiied name and valued with generated token, and can be use in next step with `${ private_key }`.
84+
- `secret_name`: The secret name created on current repository. Specify a secret name will add an secret on current repository with specfiied name and valued with generated token and can be use in next step with `${{ secrets.xxx }}`.
85+
- `clean_secret`: Shoule clean the secret or not when the job completed. Only used when `secret_name` specfiied. Default `false`.
3586

3687
## License
3788

action.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
name: Use App token
2-
description: Run a GitHub Action as a GitHub App instead of using secrets.GITHUB_TOKEN or a personal access token.
2+
description: Run a GitHub Action as a GitHub App to use the app's token.
33
author: bubkoo <[email protected]>
44
inputs:
5-
APP_ID:
5+
app_id:
66
description: The ID of the GitHub App.
77
required: true
8-
PRIVATE_KEY:
8+
private_key:
99
description: The private key of the GitHub App (can be Base64 encoded).
1010
required: true
11-
VARIABLE_NAME:
11+
variable_name:
1212
description: The name of generated token in output and exported variable.
1313
required: false
1414
default: token
15-
SECRET_NAME:
15+
secret_name:
1616
description: The secret name created on current repository.
1717
required: false
18-
CLEAN_SECRET:
18+
clean_secret:
1919
description: Shoule clean the secret or not when completed.
2020
required: false
2121
default: false
22+
2223
outputs:
2324
token:
2425
description: An installation token for the GitHub App on the current repository.
26+
2527
runs:
2628
using: node12
2729
main: dist/index.js
2830
post: dist/index.js
31+
2932
branding:
3033
icon: anchor
3134
color: orange # gray-dark purple red orange green blue yellow black white

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "use-app-token",
3-
"version": "1.0.0",
4-
"description": "Run a GitHub Action as a GitHub App instead of using secrets.GITHUB_TOKEN or a personal access token.",
3+
"version": "1.0.1",
4+
"description": "Run a GitHub Action as a GitHub App to use the app's token.",
55
"main": "dist/index.js",
66
"files": [
77
"dist",

screenshot.jpg

88 KB
Loading

src/action.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export namespace Action {
66
try {
77
const token = await Util.getAppToken()
88
core.info('Token generated!')
9-
const secretName = core.getInput('SECRET_NAME')
9+
10+
const secretName = core.getInput('secret_name')
1011
if (secretName) {
1112
await Util.saveAppTokenToSecret(secretName, token)
1213
core.info(`Token save in secret "${secretName}"`)
@@ -15,7 +16,7 @@ export namespace Action {
1516
core.setSecret(token)
1617
core.setOutput('token', token)
1718

18-
const variableName = core.getInput('VARIABLE_NAME')
19+
const variableName = core.getInput('variable_name')
1920
if (variableName) {
2021
core.exportVariable(variableName, token)
2122
}
@@ -27,7 +28,7 @@ export namespace Action {
2728

2829
export async function cleanup() {
2930
try {
30-
const secretName = core.getInput('SECRET_NAME')
31+
const secretName = core.getInput('secret_name')
3132
if (secretName) {
3233
await Util.removeAppTokenFromSecret(secretName)
3334
core.info(`Token in secret "${secretName}" was cleaned`)

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Action } from './action'
55
if (!State.isPost) {
66
Action.run()
77
} else {
8-
if (getInput('CLEAN_SECRET') === 'true') {
8+
if (getInput('clean_secret') === 'true') {
99
Action.cleanup()
1010
}
1111
}

src/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import sodium from 'tweetsodium'
77

88
export namespace Util {
99
export async function getAppToken() {
10-
const id = Number(getInput('APP_ID', { required: true }))
11-
const privateKeyInput = getInput('PRIVATE_KEY', { required: true })
10+
const id = Number(getInput('app_id', { required: true }))
11+
const privateKeyInput = getInput('private_key', { required: true })
1212
const privateKey = isBase64(privateKeyInput)
1313
? Buffer.from(privateKeyInput, 'base64').toString('utf8')
1414
: privateKeyInput

0 commit comments

Comments
 (0)