Skip to content

Commit

Permalink
install package, env vars, and remove gh action step
Browse files Browse the repository at this point in the history
  • Loading branch information
szeckirjr committed Jul 18, 2023
1 parent 49ccbe1 commit 5e355fb
Show file tree
Hide file tree
Showing 4 changed files with 284 additions and 30 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/update-algolia.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,6 @@ on:
description: Academic term to execute the script with. ie 202009, 202001
required: true
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./functions
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 14
- name: Cache npm dependencies
uses: actions/cache@v2
with:
key: npm-${{ hashFiles('package-lock.json') }}
path: ~/.npm
restore-keys: |
npm-
- name: Install dependencies
run: npm ci --ignore-scripts --no-audit --no-progress
- name: Lint
run: npm run lint
update-algolia:
name: Update Algolia index
needs: [lint]
Expand All @@ -55,10 +32,5 @@ jobs:
npm-
- name: Install dependencies
run: npm ci --ignore-scripts --no-audit --no-progress
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0
with:
service_account_key: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }}
export_default_credentials: true
- name: Run Update Algolia Script
run: npx ts-node ./scripts/update-algolia-index.ts ${{ github.event.inputs.term }}
273 changes: 273 additions & 0 deletions functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"main": "lib/src/index.js",
"dependencies": {
"@vikelabs/uvic-course-scraper": "^1.0.0-alpha.8",
"algoliasearch": "^4.18.0",
"async": "^3.2.1",
"express": "^4.17.2",
"firebase-admin": "^10.0.1",
Expand Down
12 changes: 10 additions & 2 deletions functions/scripts/update-algolia-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ if (!/20\d{2}0[1,5,9]/.test(term.trim()))

const BASE = 'https://courseup.vikelabs.ca/api';

const client = algoliasearch('ALGOLIA_APP_ID', 'ALGOLIA_ADMIN_KEY');
const index = client.initIndex('ALGOLIA_INDEX_NAME');
const ALGOLIA_APP_ID = process.env.ALGOLIA_APP_ID;
const ALGOLIA_ADMIN_KEY = process.env.ALGOLIA_ADMIN_KEY;
const ALGOLIA_INDEX_NAME = process.env.ALGOLIA_INDEX_NAME;

if (!ALGOLIA_APP_ID || !ALGOLIA_ADMIN_KEY || !ALGOLIA_INDEX_NAME) {
throw Error('Algolia environment variables not found.');
}

const client = algoliasearch(ALGOLIA_APP_ID, ALGOLIA_ADMIN_KEY);
const index = client.initIndex(ALGOLIA_INDEX_NAME);

interface Course {
subject: string;
Expand Down

0 comments on commit 5e355fb

Please sign in to comment.