From 35434d97c871e20dd898ef583190a28ba7aef959 Mon Sep 17 00:00:00 2001 From: Mike Downes Date: Wed, 6 Sep 2023 16:48:30 -0400 Subject: [PATCH] Prod deploy script --- .github/workflows/prod-env-deploy.yml | 74 +++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 .github/workflows/prod-env-deploy.yml diff --git a/.github/workflows/prod-env-deploy.yml b/.github/workflows/prod-env-deploy.yml new file mode 100644 index 0000000..d329f50 --- /dev/null +++ b/.github/workflows/prod-env-deploy.yml @@ -0,0 +1,74 @@ +name: Prod Env Deploy Script + +on: + workflow_dispatch: + push: + branches: [main] + +jobs: + build_and_deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Setup Node + uses: actions/setup-node@v3 + + - name: Install dependencies + uses: bahmutov/npm-install@v1 + + - name: Install clasp + id: install-clasp + run: sudo npm install @google/clasp@2.4.1 -g + + - name: Write CLASPRC_JSON secret to .clasprc.json file + id: write-clasprc + run: echo "$CLASPRC_JSON_SECRET" >> ~/.clasprc.json + env: + CLASPRC_JSON_SECRET: ${{ secrets.CLASPRC_JSON }} + + - name: Check clasp login status + id: clasp_login + run: clasp login --status + + - name: Save current .clasprc.json contents to CLASPRC_JSON_FILE environment variable + id: save-clasprc + run: | + echo ::add-mask::$(tr -d '\n\r' < ~/.clasprc.json) + echo "CLASPRC_JSON_FILE=$(tr -d '\n\r' < ~/.clasprc.json)" >> $GITHUB_ENV + + - name: Save CLASPRC_JSON_FILE environment variable to CLASPRC_JSON repo secret + id: set-clasprc-secret + if: ${{ env.CLASPRC_JSON_FILE != env.CLASPRC_JSON_SECRET }} + uses: hmanzur/actions-set-secret@v2.0.0 + env: + CLASPRC_JSON_SECRET: ${{ secrets.CLASPRC_JSON }} + with: + name: "CLASPRC_JSON" + value: ${{ env.CLASPRC_JSON_FILE }} + repository: ${{ github.repository }} + token: ${{ secrets.REPO_ACCESS_TOKEN }} + + - name: Set scriptId in .clasp.json file + id: set-script-id + run: jq '.scriptId = "${{env.PROD_SCRIPT_ID}}"' .clasp.json > /tmp/.clasp.json && mv /tmp/.clasp.json .clasp.json + env: + TEST_SCRIPT_ID: ${{secrets.PROD_SCRIPT_ID}} + + ## Build & push + + - name: Build project + run: npm run build + + - name: Push script to scripts.google.com + id: clasp-push + run: clasp push -f + + - name: Deploy Script + id: clasp-deploy + if: github.ref == 'refs/heads/test' + run: clasp deploy -i "${{ secrets.PROD_DEPLOYMENT_ID }}" -d ${{github.run_number}} + env: + TEST_SCRIPT_ID: ${{ secrets.PROD_SCRIPT_ID }} \ No newline at end of file