diff --git a/.github/workflows/crawl.yml b/.github/workflows/crawl.yml index 57ef8b9d1..5a8faa926 100644 --- a/.github/workflows/crawl.yml +++ b/.github/workflows/crawl.yml @@ -1,6 +1,9 @@ name: Get all URLs and begin crawling on: + pull_request: + branches: + - main push: branches: - main @@ -12,12 +15,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + - run: npm install - name: Run script - uses: tj-actions/puppeteer@v4 - id: puppeteer - with: - files: | - .github/workflows/crawl.js + run: npm run crawl env: ALGOLIA_CRAWLER_API_KEY: ${{secrets.ALGOLIA_CRAWLER_API_KEY}} ALGOLIA_CRAWLER_ID: ${{secrets.ALGOLIA_CRAWLER_ID}} diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..25c8fdbab --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +package-lock.json \ No newline at end of file diff --git a/.github/workflows/crawl.js b/crawl.js similarity index 94% rename from .github/workflows/crawl.js rename to crawl.js index e7f6ec963..abbf0866b 100644 --- a/.github/workflows/crawl.js +++ b/crawl.js @@ -1,4 +1,3 @@ -const fetch = require('node-fetch'); const puppeteer = require('puppeteer'); (async () => { @@ -9,6 +8,11 @@ const puppeteer = require('puppeteer'); apiKey: process.env.ALGOLIA_CRAWLER_API_KEY, } + if (!crawler.url || !crawler.id || !crawler.userId || !crawler.apiKey) { + console.log("Missing required env vars") + return + } + const updateUrls = async (urls) => { const updateResponse = await fetch(`${crawler.url}/${crawler.id}/config`, { method: "PATCH", diff --git a/package.json b/package.json new file mode 100644 index 000000000..6937873a3 --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "api-schemas", + "version": "1.0.0", + "description": "This repository contains OpenAPI schemas for the Cloudflare API.", + "main": "index.js", + "scripts": { + "crawl": "node crawl.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "puppeteer": "^19.9.0" + } +}