diff --git a/.github/workflows/schedule.sgid-index-validation.yml b/.github/workflows/schedule.sgid-index-validation.yml index 233c006d4..6070db0e3 100644 --- a/.github/workflows/schedule.sgid-index-validation.yml +++ b/.github/workflows/schedule.sgid-index-validation.yml @@ -21,7 +21,7 @@ jobs: run: working-directory: ./src/scripts env: - GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.SA }} + GOOGLE_PRIVATE_KEY: ${{ secrets.SA }} steps: - name: ⬇️ Set up code diff --git a/src/scripts/validate-sgid-index.mjs b/src/scripts/validate-sgid-index.mjs index 38ea9c8db..ef0e31bc3 100644 --- a/src/scripts/validate-sgid-index.mjs +++ b/src/scripts/validate-sgid-index.mjs @@ -1,4 +1,4 @@ -import { GoogleAuth } from 'google-auth-library'; +import { GoogleAuth, auth } from 'google-auth-library'; import { GoogleSpreadsheet } from 'google-spreadsheet'; import ky from 'ky'; import ProgressBar from 'progress'; @@ -7,12 +7,20 @@ import { validateOpenDataUrl, validateOpenSgidTableName, validateUrl } from './u const spreadsheetId = '11ASS7LnxgpnD0jN4utzklREgMf1pcvYjcXcIcESHweQ'; -const auth = new GoogleAuth({ - scopes: ['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive'], -}); +const scopes = ['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive']; +let client; +if (process.env.GITHUB_ACTIONS) { + console.log('using ci credentials'); + client = auth.fromJSON(JSON.parse(import.meta.env.GOOGLE_PRIVATE_KEY)); + client.scopes = scopes; +} else { + client = new GoogleAuth({ + scopes, + }); +} console.log('loading spreadsheet'); -const spreadsheet = new GoogleSpreadsheet(spreadsheetId, auth); +const spreadsheet = new GoogleSpreadsheet(spreadsheetId, client); await spreadsheet.loadInfo(); const worksheet = spreadsheet.sheetsByTitle['SGID Index'];