Skip to content

Merge pull request #6 from mikedownesdev/develop #12

Merge pull request #6 from mikedownesdev/develop

Merge pull request #6 from mikedownesdev/develop #12

name: Test Env Deploy Script
on:
workflow_dispatch:
push:
branches: [test]
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.TEST_SCRIPT_ID}}"' .clasp.json > /tmp/.clasp.json && mv /tmp/.clasp.json .clasp.json
env:
TEST_SCRIPT_ID: ${{secrets.TEST_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.TEST_DEPLOYMENT_ID }}" -d ${{github.run_number}}
env:
TEST_SCRIPT_ID: ${{ secrets.TEST_SCRIPT_ID }}