🤖 Supprime les index Algolia temporaires lorsque les PR sont fermées

fix/algolia-rm-temp-index-on-closed-pr
Alexandre Valsamou-Stanislawski 2021-09-22 17:41:05 +02:00
parent ba76056e37
commit f46ae851fd
3 changed files with 43 additions and 1 deletions

24
.github/workflows/pr-cleanup.yaml vendored Normal file
View File

@ -0,0 +1,24 @@
name: PR clean up
on:
pull_request:
types: [closed]
jobs:
deploy-context:
runs-on: ubuntu-18.04
outputs:
env-name: ${{ steps.deploy-env.outputs.name }}
steps:
- id: deploy-env
run: echo "::set-output name=name::${{ github.event.number || '${GITHUB_REF#refs/*/}' }}"
algolia-rm-temp-index:
needs: deploy-context
runs-on: ubuntu-18.04
steps:
- name: Remove temporary algolia index
run: yarn workspace mon-entreprise algolia:clean
env:
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
ALGOLIA_ADMIN_KEY: ${{ secrets.ALGOLIA_ADMIN_KEY }}
ALGOLIA_INDEX_PREFIX: monentreprise-${{needs.deploy-context.outputs.env-name}}-

View File

@ -134,6 +134,7 @@
"serve:dev:mon-entreprise": "PORT=5000 serve --config serve.mon-entreprise.json --no-clipboard",
"serve:dev:publicodes": "PORT=5002 serve --config serve.publicodes.json --no-clipboard",
"serve:dev:mycompanyinfrance": "PORT=5001 serve --config serve.infrance.json --no-clipboard",
"algolia:update": "node scripts/search/update-data.js"
"algolia:update": "node scripts/search/update-data.js",
"algolia:clean": "node scripts/search/clean.js"
}
}

View File

@ -0,0 +1,17 @@
require('dotenv').config()
const algoliasearch = require('algoliasearch')
const {
ALGOLIA_APP_ID,
ALGOLIA_ADMIN_KEY,
ALGOLIA_INDEX_PREFIX = '',
} = process.env
const client = algoliasearch(ALGOLIA_APP_ID, ALGOLIA_ADMIN_KEY)
const rulesIndex = client.initIndex(`${ALGOLIA_INDEX_PREFIX}rules`)
const simulateursIndex = client.initIndex(`${ALGOLIA_INDEX_PREFIX}simulateurs`)
rulesIndex.delete()
simulateursIndex.delete()