📜 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
🚀 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:
-
Enable the Google Apps Script API
- Navigate to your Google Apps Script dashboard.
- Go to the ⚙️ Settings page using the left menu pane.
- Click the Google Apps Script API setting. It's currently the only Google Apps Script setting available.
- Read the ℹ informative warning about enabling the API.
- Click the toggle to enable the API.
-
Get your local
clasp
credentialsYou can use
clasp login
to generate a.clasprc.json
file. You may already have one from previousclasp
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
-
Store your
clasp
credentials in a GitHub Actions secret- Navigate to the GitHub repository you want to use
clasp
with. - Go to the repository's ⚙️ Settings page.
- Find the *️⃣ Secrets and variables dropdown on the left navigation pane. Choose Actions.
- Under Repository secrets click New repository secret.
- Choose a secret name. I like to use
CLASPRC_JSON
. - Paste your
.clasprc.json
contents that you copied earlier into the Secret * textbox. - Click Add secret
- Navigate to the GitHub repository you want to use
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 }}