Skip to content

GITBOOK-199: Audit-2 #79

GITBOOK-199: Audit-2

GITBOOK-199: Audit-2 #79

name: "[Bot] Update GitBook revision in Suite"
on:
workflow_dispatch:
push:
branches:
- master
- develop
jobs:
update-revision-in-suite:
if: github.event_name == 'workflow_dispatch' || github.event.head_commit.committer.username == 'gitbook-bot'
name: Update GitBook revision in Suite
runs-on: ubuntu-latest
environment: suite-public
env:
SUITE_REPO: "trezor/trezor-suite"
SUITE_BRANCH: "develop"
FILEPATH: "./packages/suite-data/src/guide/constants.ts"
PR_BRANCH: "chore/update-suite-guide"
GITHUB_TOKEN: ${{ secrets.TREZOR_BOT_TOKEN }}
steps:
- name: Generate GitHub App token
id: trezor-bot-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.TREZOR_BOT_APP_ID }}
private-key: ${{ secrets.TREZOR_BOT_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: |
trezor-suite
- name: Check if PR already exists
id: pr_exists
env:
GITHUB_TOKEN: ${{ steps.trezor-bot-token.outputs.token }}
run: |
PR_NUMBER=$(gh pr list --repo ${{ env.SUITE_REPO }} --head ${{ env.PR_BRANCH }} --state open --json number --jq '.[0].number')
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
- name: Close existing PR if found
if: steps.pr_exists.outputs.pr_number != ''
env:
GITHUB_TOKEN: ${{ steps.trezor-bot-token.outputs.token }}
run: gh pr close ${{ steps.pr_exists.outputs.pr_number }} --repo ${{ env.SUITE_REPO }} --comment "Closing PR as newer revision exists." --delete-branch
- name: Checkout trezor-suite repo
uses: actions/checkout@v3
with:
repository: ${{ env.SUITE_REPO }}
ref: ${{ env.SUITE_BRANCH }}
fetch-depth: 0
token: ${{ steps.trezor-bot-token.outputs.token }}
- name: Create a new branch and switch to it
run: git switch -c ${{ env.PR_BRANCH }}
- name: Update GitBook revision
run: sed -i "s/^export const GITBOOK_REVISION = .*/export const GITBOOK_REVISION = '${{ github.sha }}';/" ${{ env.FILEPATH }}
- name: Stage and commit
run: |
git config user.name "${{ steps.trezor-bot-token.outputs.app-slug }}[bot]"
git config user.email "<${{ steps.trezor-bot-token.outputs.app-slug }}[bot]@users.noreply.github.com>"
git add ${{ env.FILEPATH }}
git commit -m "chore(suite-data): update guide revision"
- name: Push branch
run: git push --set-upstream origin ${{ env.PR_BRANCH }}
- name: Create pull request
env:
GITHUB_TOKEN: ${{ steps.trezor-bot-token.outputs.token }}
if: github.ref == 'refs/heads/master'
run: gh pr create --repo ${{ env.SUITE_REPO }} --base ${{ env.SUITE_BRANCH }} --head ${{ env.PR_BRANCH }} --title "GitBook revision update" --label "guide" --body "Automatically generated PR to update GitBook revision, i.e. to sync the latest [trezor-suite-guide](https://github.com/${{ github.repository }}) content to Suite. Before merging, check its [commit history](https://github.com/${{ github.repository }}/commits/master). Once the pipeline finishes, you can check the result [here](https://dev.suite.sldev.cz/suite-web/${{ env.PR_BRANCH }}/web/)."