Skip to content

Commit

Permalink
feature: support fetching github token from github app (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xWOF authored Jun 25, 2024
2 parents 5d9d0de + 4fbdbdb commit b4dabc9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
31 changes: 29 additions & 2 deletions .github/workflows/gitflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,18 @@ on:
default: 'changelog.md'
required: false
secrets:
TOKEN:
GITHUB_TOKEN:
description: 'GitHub token (Default: GitHub Action token)'
required: false
GITHUB_APP_ID:
description: 'GitHub app id for fetching GitHub token'
required: false
GITHUB_APP_PRIVATE_KEY:
description: 'GitHub app private key for fetching GitHub token'
required: false
GITHUB_APP_OWNER:
description: 'GitHub app owner for fetching GitHub token'
required: false

env:
MAIN_BRANCH: ${{ inputs.MAIN_BRANCH || 'main' }}
Expand All @@ -66,7 +75,10 @@ env:
VERSION_EXPRESSION: ${{ inputs.VERSION_EXPRESSION || '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*' }}
VERSION_HEADER: ${{ inputs.VERSION_HEADER || '## ' }}
CHANGELOG: ${{ inputs.CHANGELOG || 'changelog.md' }}
GITHUB_TOKEN: ${{ secrets.TOKEN || github.token }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN || github.token }}
GITHUB_APP_ID: ${{ secrets.GITHUB_APP_ID }}
GITHUB_APP_PRIVATE_KEY: ${{ secrets.GITHUB_APP_PRIVATE_KEY }}
GITHUB_APP_OWNER: ${{ secrets.GITHUB_APP_OWNER }}
SOURCE_BRANCH: ${{ github.event.pull_request.head.ref }}
SOURCE_COMMIT: ${{ github.event.pull_request.head.sha }}
DESTINATION_BRANCH: ${{ github.event.pull_request.base.ref }}
Expand All @@ -76,6 +88,21 @@ jobs:
gitflow:
runs-on: ubuntu-latest
steps:
- name: Fetching GitHub Token
id: fetching-github-token
if: ${{ env.GITHUB_APP_ID && env.GITHUB_APP_PRIVATE_KEY && env.GITHUB_APP_OWNER }}
uses: actions/create-github-app-token@v1
with:
app-id: ${{ env.GITHUB_APP_ID }}
private-key: ${{ env.GITHUB_APP_PRIVATE_KEY }}
owner: ${{ env.GITHUB_APP_OWNER }}

- name: Using GitHub Token
if: ${{ env.GITHUB_APP_ID && env.GITHUB_APP_PRIVATE_KEY && env.GITHUB_APP_OWNER }}
run: |
echo '::add-mask::${{ steps.fetching-github-token.outputs.token }}'
echo 'GITHUB_TOKEN=${{ steps.fetching-github-token.outputs.token }}' >> $GITHUB_ENV
- name: Check branch
id: check-branch
run: |
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.2.0

- feature: support fetching github token from github app

## 2.1.2

- fix: solve issue that DEVELOP_BRANCH input is not used
Expand Down
5 changes: 4 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ A implementation of workflows of GitHub Actions to support using gitflow on GitH
# VERSION_HEADER: ... # Default: '## '
# CHANGELOG: ... # Default: 'changelog.md'
# secrets:
# TOKEN: ... # Default: Github Action token
# GITHUB_TOKEN: ... # Default: GitHub Action token
# GITHUB_APP_ID: ... # Default: GitHub App ID for fetching GitHub token
# GITHUB_APP_PRIVATE_KEY: ... # Default: GitHub App ID for fetching GitHub token
# GITHUB_APP_OWNER: ... # Default: GitHub App ID for fetching GitHub token
```
4. Set `Workflow permissions` as checking `Read and write permissions` and `Allow GitHub Actions to create and approve pull requests`.
5. Do not check `Automatically delete head branches`.
Expand Down

0 comments on commit b4dabc9

Please sign in to comment.