From 1aedfefced0cb431632f0869cce7448881789b78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=E1=BB=93ng=20Ph=C3=A1t?= Date: Mon, 7 Aug 2023 22:27:07 +0700 Subject: [PATCH] refresh token in cron job --- .github/workflows/zalo-mini-app.yml | 46 ++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/.github/workflows/zalo-mini-app.yml b/.github/workflows/zalo-mini-app.yml index 461eeeb..351e7ae 100644 --- a/.github/workflows/zalo-mini-app.yml +++ b/.github/workflows/zalo-mini-app.yml @@ -2,21 +2,27 @@ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs name: Zalo Mini App +run-name: ${{ github.event_name == 'schedule' && '✨ Refresh token' || '🚀 Deploy' }} + +concurrency: zalo-mini-app on: push: - branches: ["main"] + branches: + - main + - "feat/**" pull_request: - branches: ["main"] + branches: + - main + - "feat/**" + schedule: + - cron: "0 0 * * *" jobs: - deploy: + refresh_token: + if: ${{ github.event_name == 'schedule' }} runs-on: ubuntu-latest - strategy: - matrix: - mini-app-id: ["194839900003483517"] - steps: - uses: actions/checkout@v3 - name: Use Node.js 18.x @@ -25,14 +31,40 @@ jobs: node-version: 18.x cache: "npm" - run: npx zmp-developer-token login ${{ secrets.ZALO_APP_ID }} ${{ secrets.ZALO_APP_SECRET }} ${{ secrets.ZALO_REFRESH_TOKEN }} >> $GITHUB_ENV + - uses: hmanzur/actions-set-secret@v2.0.0 + with: + name: "ZALO_ACCESS_TOKEN" + value: ${{ env.NEW_ACCESS_TOKEN }} + token: ${{ secrets.REPO_ACCESS_TOKEN }} - uses: hmanzur/actions-set-secret@v2.0.0 with: name: "ZALO_REFRESH_TOKEN" value: ${{ env.NEW_REFRESH_TOKEN }} token: ${{ secrets.REPO_ACCESS_TOKEN }} + - name: Report + run: | + echo "### Token renewal success! :sparkles:" >> $GITHUB_STEP_SUMMARY + + deploy: + if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }} + runs-on: ubuntu-latest + + strategy: + matrix: + mini-app-id: ["194839900003483517"] + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js 18.x + uses: actions/setup-node@v3 + with: + node-version: 18.x + cache: "npm" - run: npm install - run: npm install -g zmp-cli - run: npx zmp-developer-token deploy ${{ matrix.mini-app-id }} + env: + NEW_ACCESS_TOKEN: ${{ secrets.ZALO_ACCESS_TOKEN }} - name: Report run: | echo "### Deployment success! :rocket:" >> $GITHUB_STEP_SUMMARY