Skip to content

Commit

Permalink
fix: handle ci credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
stdavis committed Mar 22, 2024
1 parent 1430ec9 commit 8860331
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/schedule.sgid-index-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions src/scripts/validate-sgid-index.mjs
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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'];

Expand Down

0 comments on commit 8860331

Please sign in to comment.