Skip to content

Commit 7536254

Browse files
committed
feat: ✨ fallback token when failed
1 parent 0d11695 commit 7536254

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ jobs:
108108
109109
- `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 }}`
110110
- `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 }}`
111+
- `fallback`: The fallback token when app token generate failed.
111112
- `env_name`: The name of generated token in exported environment 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 `${{ env.env_name }}`.
112113
- `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 }}`.
113114
- `clean_secret`: Shoule clean the secret or not when the job completed. Only used when `secret_name` specfiied. Default `false`.

action.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ author: bubkoo <[email protected]>
44
inputs:
55
app_id:
66
description: The ID of the GitHub App.
7-
required: true
7+
required: false
88
private_key:
99
description: The private key of the GitHub App (can be Base64 encoded).
10-
required: true
10+
required: false
11+
fallback:
12+
description: The fallback token when bot token generate failed.
13+
required: false
1114
variable_name:
1215
description: The name of generated token in exported environment variable.
1316
required: false

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "use-app-token",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "Run a GitHub Action as a GitHub App to use the app's token.",
55
"main": "dist/index.js",
66
"files": [

src/util.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ 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 fallback = getInput('fallback')
11+
const required = fallback == null
12+
const appId = Number(getInput('app_id', { required }))
13+
const privateKeyInput = getInput('private_key', { required })
14+
if (appId == null || privateKeyInput == null) {
15+
return Promise.resolve(fallback)
16+
}
17+
18+
const id = Number(appId)
1219
const privateKey = isBase64(privateKeyInput)
1320
? Buffer.from(privateKeyInput, 'base64').toString('utf8')
1421
: privateKeyInput

0 commit comments

Comments
 (0)