Skip to content

Commit

Permalink
feat: ✨ fallback token when failed
Browse files Browse the repository at this point in the history
  • Loading branch information
bubkoo committed Dec 16, 2020
1 parent 0d11695 commit 7536254
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ jobs:
- `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 }}`
- `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 }}`
- `fallback`: The fallback token when app token generate failed.
- `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 }}`.
- `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 }}`.
- `clean_secret`: Shoule clean the secret or not when the job completed. Only used when `secret_name` specfiied. Default `false`.
Expand Down
7 changes: 5 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ author: bubkoo <bubkoo.wy@gmail.com>
inputs:
app_id:
description: The ID of the GitHub App.
required: true
required: false
private_key:
description: The private key of the GitHub App (can be Base64 encoded).
required: true
required: false
fallback:
description: The fallback token when bot token generate failed.
required: false
variable_name:
description: The name of generated token in exported environment variable.
required: false
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "use-app-token",
"version": "1.1.1",
"version": "1.1.2",
"description": "Run a GitHub Action as a GitHub App to use the app's token.",
"main": "dist/index.js",
"files": [
Expand Down
11 changes: 9 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ import sodium from 'tweetsodium'

export namespace Util {
export async function getAppToken() {
const id = Number(getInput('app_id', { required: true }))
const privateKeyInput = getInput('private_key', { required: true })
const fallback = getInput('fallback')
const required = fallback == null
const appId = Number(getInput('app_id', { required }))
const privateKeyInput = getInput('private_key', { required })
if (appId == null || privateKeyInput == null) {
return Promise.resolve(fallback)
}

const id = Number(appId)
const privateKey = isBase64(privateKeyInput)
? Buffer.from(privateKeyInput, 'base64').toString('utf8')
: privateKeyInput
Expand Down

0 comments on commit 7536254

Please sign in to comment.