Schwab Token Auto Refresher #110
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Schwab Token Auto Refresher | |
| on: | |
| schedule: | |
| - cron: '0 13 */3 * *' | |
| workflow_dispatch: | |
| inputs: | |
| proxy_mode: | |
| description: 'Optional Schwab primary mode for manual runs' | |
| required: true | |
| default: direct | |
| type: choice | |
| options: | |
| - direct | |
| - proxy | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref_name }} | |
| cancel-in-progress: false | |
| jobs: | |
| refresh-token: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: '20' | |
| - name: Resolve Schwab primary mode | |
| shell: bash | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.proxy_mode }}" = "proxy" ]; then | |
| printf 'SCHWAB_FORCE_PROXY_FIRST=true\n' >> "$GITHUB_ENV" | |
| echo "Resolved Schwab primary mode: proxy-first" | |
| else | |
| printf 'SCHWAB_FORCE_PROXY_FIRST=false\n' >> "$GITHUB_ENV" | |
| echo "Resolved Schwab primary mode: direct-first" | |
| fi | |
| - name: Install Pinned Google Chrome & Dependencies | |
| run: | | |
| sudo apt-get update | |
| CHROME_VERSION="147.0.7727.137-1" | |
| CHROME_DEB="google-chrome-stable_${CHROME_VERSION}_amd64.deb" | |
| curl -fsSLo "$CHROME_DEB" "https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/${CHROME_DEB}" | |
| sudo apt install -y --allow-downgrades "./${CHROME_DEB}" | |
| google-chrome --version | |
| npm ci | |
| - name: Run Refresh Script | |
| run: npm start | |
| env: | |
| GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }} | |
| SCHWAB_PROXY_URL: ${{ secrets.SCHWAB_PROXY_URL }} | |
| SCHWAB_USERNAME: ${{ secrets.SCHWAB_USERNAME }} | |
| SCHWAB_PASSWORD: ${{ secrets.SCHWAB_PASSWORD }} | |
| SCHWAB_TOTP_SECRET: ${{ secrets.SCHWAB_TOTP_SECRET }} | |
| SCHWAB_API_KEY: ${{ secrets.SCHWAB_API_KEY }} | |
| SCHWAB_APP_SECRET: ${{ secrets.SCHWAB_APP_SECRET }} | |
| GCP_PROJECT_ID: ${{ vars.GCP_PROJECT_ID }} | |
| GCP_SECRET_ID: ${{ vars.GCP_SECRET_ID }} | |
| SCHWAB_REDIRECT_URI: ${{ vars.SCHWAB_REDIRECT_URI }} | |
| - name: Upload Error Screenshot | |
| if: failure() | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: debug-screenshots | |
| path: | | |
| *.png | |
| *_diagnostics.json | |
| retention-days: 3 | |
| - name: Update Log (Bash Version) | |
| if: success() | |
| run: | | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| echo "Last successful refresh: $(date '+%Y-%m-%d %H:%M:%S')" > last_run.txt | |
| git checkout -B logs | |
| git add last_run.txt | |
| git commit -m "chore: update token refresh log [skip ci]" | |
| git push "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" logs --force |