name: "[Bot] update TOR binary" permissions: contents: read on: schedule: - cron: "0 0 1 * *" workflow_dispatch: jobs: update-tor: if: github.repository == 'trezor/trezor-suite' runs-on: macos-latest env: UPDATE_FILE: suite/app-assets/files/bin/tor/update.sh steps: - name: Checkout repo uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - name: Set up Node.js uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v6 with: node-version: 20 - name: Get current TOR versions id: versions run: | content=$(cat $UPDATE_FILE) crx_exists () { curl --fail --silent --head "https://tor.bravesoftware.com/release/$1/extension_$2.crx" | grep "content-type: application/x-chrome-extension" > /dev/null } newer_version () { local version=$(echo "$content" | grep "^$1=" | cut -d= -f2) local major=$(echo "$version" | cut -d_ -f1-2)_ local patch=$(echo "$version" | cut -d_ -f3) local next=$((patch+1)) # Brave may publish several versions between our runs of this workflow, so skip ahead to the newest one. # Whether $next itself exists is verified by the check_* steps below. while crx_exists "$2" "${major}$((next+1))"; do next=$((next+1)) done echo "${major}${next}" } # CRX_VER is probed on the macOS extension only; assumes Brave publishes macOS, Windows and Linux x64 together. crx_next=$(newer_version CRX_VER cldoidikboihgcjfkhdeidbpclkineef) arm_next=$(newer_version CRX_LINUX_ARM_VER monolafkoghdlanndjfeebmdfkbklejg) echo "crx_next=$crx_next" >> $GITHUB_OUTPUT echo "arm_next=$arm_next" >> $GITHUB_OUTPUT - name: Check if new CRX binary exists id: check_crx run: | url="https://tor.bravesoftware.com/release/cldoidikboihgcjfkhdeidbpclkineef/extension_${{ steps.versions.outputs.crx_next }}.crx" echo "Checking $url" if curl --fail --silent --head "$url" | grep "content-type: application/x-chrome-extension" > /dev/null; then echo "new_crx=true" >> $GITHUB_OUTPUT echo "crx_url=$url" >> $GITHUB_OUTPUT else echo "new_crx=false" >> $GITHUB_OUTPUT fi - name: Check if new Linux ARM binary exists id: check_arm run: | url="https://tor.bravesoftware.com/release/monolafkoghdlanndjfeebmdfkbklejg/extension_${{ steps.versions.outputs.arm_next }}.crx" echo "Checking $url" if curl --fail --silent --head "$url" | grep "content-type: application/x-chrome-extension" > /dev/null; then echo "new_arm=true" >> $GITHUB_OUTPUT echo "arm_url=$url" >> $GITHUB_OUTPUT else echo "new_arm=false" >> $GITHUB_OUTPUT fi - name: Update update.sh if: steps.check_crx.outputs.new_crx == 'true' || steps.check_arm.outputs.new_arm == 'true' run: | if [ "${{ steps.check_crx.outputs.new_crx }}" = "true" ]; then sed -i '' "s/^CRX_VER=.*/CRX_VER=${{ steps.versions.outputs.crx_next }}/" "$UPDATE_FILE" fi if [ "${{ steps.check_arm.outputs.new_arm }}" = "true" ]; then sed -i '' "s/^CRX_LINUX_ARM_VER=.*/CRX_LINUX_ARM_VER=${{ steps.versions.outputs.arm_next }}/" "$UPDATE_FILE" fi - name: Run update.sh if: steps.check_crx.outputs.new_crx == 'true' || steps.check_arm.outputs.new_arm == 'true' run: | bash "$UPDATE_FILE" - name: Build PR body id: pr_body if: steps.check_crx.outputs.new_crx == 'true' || steps.check_arm.outputs.new_arm == 'true' run: | body="## Description\n\nNew TOR binaries available:\n" if [ "${{ steps.check_crx.outputs.new_crx }}" = "true" ]; then body+="\n- CRX: ${{ steps.versions.outputs.crx_next }} (${{ steps.check_crx.outputs.crx_url }})" fi if [ "${{ steps.check_arm.outputs.new_arm }}" = "true" ]; then body+="\n- Linux ARM: ${{ steps.versions.outputs.arm_next }} (${{ steps.check_arm.outputs.arm_url }})" fi body+="\n\n### :eyes: Review instructions\n\n" body+="Works fully only on macOS. On Linux, remove all mentions of \`lipo\` and check at least Linux+Windows binaries.\n\`\`\`\n" body+="git fetch origin chore/update-tor-binaries\n" body+="git checkout chore/update-tor-binaries\n" body+="git checkout HEAD~1\n" body+="git restore --source origin/chore/update-tor-binaries suite/app-assets/files/bin/tor/update.sh\n" body+="./suite/app-assets/files/bin/tor/update.sh\n" body+="git reset --soft chore/update-tor-binaries\n" body+="git add .\n" body+="git status -s\n" body+="# should be no diff if binaries match\n\`\`\`\n\n" body+="## Notes for QA\n\n" body+="Verify that Tor works on all platforms; can be tested as part of the RC checks.\n" echo "body<> $GITHUB_OUTPUT echo -e "$body" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT - name: Generate GitHub App token if: steps.check_crx.outputs.new_crx == 'true' || steps.check_arm.outputs.new_arm == 'true' id: trezor-bot-token uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3 with: client-id: ${{ secrets.TREZOR_BOT_APP_ID }} private-key: ${{ secrets.TREZOR_BOT_PRIVATE_KEY }} permission-contents: write permission-pull-requests: write permission-issues: write - name: Create Pull Request if: steps.check_crx.outputs.new_crx == 'true' || steps.check_arm.outputs.new_arm == 'true' uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8 with: token: ${{ steps.trezor-bot-token.outputs.token }} commit-message: "chore(app-assets): update TOR binaries" branch: chore/update-tor-binaries title: "Update TOR binaries" body: ${{ steps.pr_body.outputs.body }} base: ${{ github.ref_name }} delete-branch: true labels: tor, ci