diff --git a/.github/workflows/pr-cleanup.yaml b/.github/workflows/pr-cleanup.yaml new file mode 100644 index 000000000..10d342307 --- /dev/null +++ b/.github/workflows/pr-cleanup.yaml @@ -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}}- diff --git a/mon-entreprise/package.json b/mon-entreprise/package.json index 4860cdbb5..d0fc5b3a7 100644 --- a/mon-entreprise/package.json +++ b/mon-entreprise/package.json @@ -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" } } diff --git a/mon-entreprise/scripts/search/clean.js b/mon-entreprise/scripts/search/clean.js new file mode 100644 index 000000000..3ca853c04 --- /dev/null +++ b/mon-entreprise/scripts/search/clean.js @@ -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()