Add monitoring to coveo token generation workflow #595
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Refresh coveo searchToken for docs dev/staging/production | |
on: | |
pull_request: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 */23 * * *" | |
jobs: | |
generate-coveo-search-token: | |
name: Generate Coveo Search Tokens | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- env_name: dev | |
env_api_key: "COVEO_API_DEV" | |
env_coveo_org_id: "f5networkx1h1607h" | |
- env_name: staging | |
env_api_key: "COVEO_API_STAGING" | |
env_coveo_org_id: "f5networksnonproduction1xqykzabw" | |
- env_name: prod | |
env_api_key: "COVEO_API_PROD" | |
env_coveo_org_id: "f5networksproduction5vkhn00h" | |
steps: | |
- name: Install jq | |
run: sudo apt-get install jq | |
- name: Generating token for ${{matrix.env_name}} ... | |
id: generate-token | |
continue-on-error: true | |
env: | |
COVEO_API_KEY: "<NOTHING_BURGER>" | |
COVEO_SEARCH_HUB: "HUB_ES_Nginx_Docs_And_Org" | |
run: | | |
RESPONSE=$(curl -w "\nHTTP_CODE: %{http_code}" -s -X POST "https://platform.cloud.coveo.com/rest/search/v2/token?organizationId=${{matrix.env_coveo_org_id}}" \ | |
-H "Accept: application/json" \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: Bearer ${COVEO_API_KEY}" \ | |
-d '{ | |
"searchHub": "'${COVEO_SEARCH_HUB}'", | |
"organization": "'${{matrix.env_coveo_org_id}}'", | |
"userIds": [ | |
{ | |
"type": "User", | |
"name": "anonymous", | |
"provider": "Email Security Provider" | |
} | |
] | |
}') | |
STATUS_CODE=$(echo "$RESPONSE" | grep HTTP_ | awk '{print $2}') | |
SEARCH_TOKEN=$(echo "$RESPONSE" | sed '$d' | jq -r '.token') | |
if [ $STATUS_CODE -ne 200 ]; then | |
echo "Error: HTTP request failed with status $STATUS_CODE" | |
echo "$RESPONSE" | |
exit 1 | |
fi | |
if [ "$SEARCH_TOKEN" == "null" ]; then | |
echo "Error: Failed to extract search token from response" | |
exit 1 | |
fi | |
mkdir coveo/ | |
echo "{\"token\": \"$SEARCH_TOKEN\", \"org_id\": \"${{matrix.env_coveo_org_id}}\"}" > coveo/search_token.json | |
- name: Upload token for ${{matrix.env_name}} | |
if: ${{ steps.generate-token.outcome == 'success' }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{matrix.env_name}} | |
path: "./" | |
- name: Send a notification if token generation step failed | |
if: ${{ steps.generate-token.outcome == 'failure' }} | |
uses: 8398a7/action-slack@77eaa4f1c608a7d68b38af4e3f739dcd8cba273e # v3.19.0 | |
with: | |
status: custom | |
custom_payload: | | |
{ | |
username: 'Github', | |
mention: 'channel', | |
attachments: [{ | |
title: '[${{ github.event.repository.full_name }}] Coveo Token Generation Failed: environment ${{matrix.env_name}}', | |
color: 'danger', | |
fields: [{ | |
title: 'Pipeline URL', | |
value: '<https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.run_id }}>', | |
short: false | |
}] | |
}] | |
} | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_DOCS_INCIDENT }} |