jcbhmr / configure-clasp

πŸ“œ Setup the clasp Google Apps Script CLI tool and authenticate it

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Configure clasp

πŸ“œ Authenticate the clasp Google Apps Script CLI tool

- run: echo "$CLASPRC_JSON" > ~/.clasprc.json
  env:
    CLASPRC_JSON: ${{ secrets.CLASPRC_JSON }}
- run: clasp push

πŸ™… No need for a GitHub Action, just copy ~/.clasprc.json!
β„Ή Uses your OAuth2 credentials to login on GitHub Actions runner
πŸ’» Acts just like clasp login on a dev machine

Usage

GitHub Actions Google Apps Script

πŸš€ Here's what you're after:

on:
  release:
    types: [released]
concurrency: ${{ github.workflow }}
jobs:
  clasp-push:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm install --global @google/clasp
      - run: echo "$CLASPRC_JSON" > ~/.clasprc.json
        env:
          CLASPRC_JSON: ${{ secrets.CLASPRC_JSON }}
      - run: clasp push

You'll need to have some pre-authenticated credentials from ~/.clasprc.json stored in GitHub Actions secrets. Here's a step-by-step guide to doing that:

  1. Enable the Google Apps Script API

    1. Navigate to your Google Apps Script dashboard.
    2. Go to the βš™οΈ Settings page using the left menu pane.
    3. Click the Google Apps Script API setting. It's currently the only Google Apps Script setting available.
    4. Read the β„Ή informative warning about enabling the API.
    5. Click the toggle to enable the API.
  2. Get your local clasp credentials

    You can use clasp login to generate a .clasprc.json file. You may already have one from previous clasp usage.

    clasp login

    This .clasprc.json file contains all the necessary information to issue authorized requests to the Google Apps Script API on your behalf. You should now copy it to use in the next step.

    cat ~/.clasprc.json # Copy the output to your clipboard
  3. Store your clasp credentials in a GitHub Actions secret

    1. Navigate to the GitHub repository you want to use clasp with.
    2. Go to the repository's βš™οΈ Settings page.
    3. Find the *️⃣ Secrets and variables dropdown on the left navigation pane. Choose Actions.
    4. Under Repository secrets click New repository secret.
    5. Choose a secret name. I like to use CLASPRC_JSON.
    6. Paste your .clasprc.json contents that you copied earlier into the Secret * textbox.
    7. Click Add secret

Now you can inject your GitHub Actions secret into ~/.clasprc.json using a step like this:

- run: echo "$CLASPRC_JSON" > ~/.clasprc.json
  env:
    CLASPRC_JSON: ${{ secrets.CLASPRC_JSON }}

About

πŸ“œ Setup the clasp Google Apps Script CLI tool and authenticate it