Skip to content

Commit

Permalink
feat: automatic crawler name (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
damcou committed Jul 20, 2021
1 parent df0fb3d commit d6861c2
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github_pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions/checkout@v2
with:
repository: algolia/algoliasearch-crawler-github-actions
ref: v0.6.0
ref: v0.7.3
- name: Sleep for 30s
run: sleep 30
- name: Github-pages-MAIN => Algolia crawler creation and recrawl (Push on Main branch)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/netlify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions/checkout@v2
with:
repository: algolia/algoliasearch-crawler-github-actions
ref: v0.6.0
ref: v0.7.3
- name: Sleep for 30s
run: sleep 30
- name: Netlify-PR => Algolia crawler creation and recrawl on preview (Pull Request)
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/vercel_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
uses: dorshinar/get-deployment-url@master
timeout-minutes: 1
with:
token: ${{ secrets.GIT_HUB_TOKEN }}
token: ${{ github.token }}
# checkout the private repo containing the action to run
- name: Checkout GitHub Action Repo
uses: actions/checkout@v2
with:
repository: algolia/algoliasearch-crawler-github-actions
ref: v0.6.0
ref: v0.7.3
- name: Vercel-PR => Algolia crawler creation and recrawl on preview (Pull Request)
uses: ./
id: crawler_pr
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/vercel_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions/checkout@v2
with:
repository: algolia/algoliasearch-crawler-github-actions
ref: v0.6.0
ref: v0.7.3
- name: Vercel-MAIN => Algolia crawler creation and recrawl on preview (Push on Main branch)
uses: ./
id: crawler_push
Expand Down
1 change: 1 addition & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ inputs:
crawler-name:
description: 'Name of the crawler'
required: true
default: '[Github] ${{ github.repository }} ${{ github.ref }}'
algolia-app-id:
description: 'Algolia Application ID'
required: true
Expand Down
6 changes: 3 additions & 3 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ var CRAWLER_USER_ID = core.getInput('crawler-user-id');
var CRAWLER_API_KEY = core.getInput('crawler-api-key');
var CRAWLER_API_BASE_URL = core.getInput('crawler-api-base-url');
var GITHUB_TOKEN = core.getInput('github-token');
var CRAWLER_NAME = core.getInput('crawler-name').replace(/\//g, '-');
var CRAWLER_NAME = core.getInput('crawler-name').replace(/[ /]/g, '-');
var INDEX_NAME = CRAWLER_NAME.replace(/[/~,[\]`&|;$*\\]/g, '');
var ALGOLIA_APP_ID = core.getInput('algolia-app-id');
var ALGOLIA_API_KEY = core.getInput('algolia-api-key');
var SITE_URL = core.getInput('site-url');
Expand All @@ -418,7 +419,6 @@ function getConfig() {
appId: ALGOLIA_APP_ID,
apiKey: ALGOLIA_API_KEY,
indexPrefix: 'crawler_',
maxUrls: 50,
rateLimit: 8,
startUrls: [SITE_URL],
ignoreQueryParams: ['source', 'utm_*'],
Expand All @@ -427,7 +427,7 @@ function getConfig() {
ignoreRobotsTxtRules: false,
actions: [
{
indexName: CRAWLER_NAME + "_index",
indexName: INDEX_NAME + "_index",
pathsToMatch: [SITE_URL + "**"],
recordExtractor: {
__type: 'function',
Expand Down
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ const CRAWLER_API_BASE_URL = core.getInput('crawler-api-base-url');
const GITHUB_TOKEN = core.getInput('github-token');

// CRAWLER CONFIGURATION
const CRAWLER_NAME = core.getInput('crawler-name').replace(/\//g, '-');
const CRAWLER_NAME = core.getInput('crawler-name');
const INDEX_NAME = CRAWLER_NAME.replace(/[ /]/g, '-').replace(
/[/~,[\]`&|;$*\\]/g,
''
);
const ALGOLIA_APP_ID = core.getInput('algolia-app-id');
const ALGOLIA_API_KEY = core.getInput('algolia-api-key');
const SITE_URL = core.getInput('site-url');
Expand All @@ -40,7 +44,6 @@ function getConfig(): ConfigJson {
appId: ALGOLIA_APP_ID,
apiKey: ALGOLIA_API_KEY,
indexPrefix: 'crawler_',
maxUrls: 50, // @todo TO BE REMOVED
rateLimit: 8,
startUrls: [SITE_URL],
ignoreQueryParams: ['source', 'utm_*'],
Expand All @@ -49,7 +52,7 @@ function getConfig(): ConfigJson {
ignoreRobotsTxtRules: false,
actions: [
{
indexName: `${CRAWLER_NAME}_index`,
indexName: `${INDEX_NAME}_index`,
pathsToMatch: [`${SITE_URL}**`],
recordExtractor: {
__type: 'function',
Expand Down

1 comment on commit d6861c2

@vercel
Copy link

@vercel vercel bot commented on d6861c2 Jul 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.