Skip to content

Commit

Permalink
ASAP-341 Team leadership and membership in Algolia (#4204)
Browse files Browse the repository at this point in the history
* ASAP-341 Team leadership and membership in Algolia
  • Loading branch information
gabiayako authored Mar 25, 2024
1 parent 96cfd56 commit d7bfef3
Show file tree
Hide file tree
Showing 37 changed files with 740 additions and 164 deletions.
51 changes: 51 additions & 0 deletions .github/actions/algolia-import-metric/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: 'Import metric'
description: 'Export analytics data from Contentful and into Algolia index'
inputs:
algolia-api-key:
description: 'Algolia api key name'
required: true
algolia-app-id:
description: 'Algolia app id name'
required: true
algolia-index:
description: 'Algolia index name'
required: true
contentful-space-id:
description: 'Contentful Space ID'
required: true
contentful-env:
description: 'Contentful environment'
required: true
contentful-access-token:
description: 'Contentful access token'
required: true
contentful-management-token:
description: 'Contentful management token'
required: true
metric:
description: 'Metric'
required: true
outputs:
algolia-app-id:
description: 'Algolia App ID'
value: '${{ steps.keys.outputs.algolia-app-id }}'
algolia-api-key:
description: 'Algolia API Key'
value: '${{ steps.keys.outputs.algolia-api-key }}'
runs:
using: 'composite'
steps:
- name: Import Metric
shell: bash
run: |
yarn export:analytics $METRIC -f $METRIC.json
jq -c '.[]' $METRIC.json | algolia objects import $ALGOLIA_INDEX -F -
env:
ALGOLIA_APPLICATION_ID: ${{ inputs.algolia-app-id }}
ALGOLIA_ADMIN_API_KEY: ${{ inputs.algolia-api-key }}
ALGOLIA_INDEX: ${{ inputs.algolia-index }}
CONTENTFUL_ACCESS_TOKEN: ${{ inputs.contentful-access-token }}
CONTENTFUL_ENV_ID: ${{ inputs.contentful-env }}
CONTENTFUL_MANAGEMENT_ACCESS_TOKEN: ${{ inputs.contentful-management-token }}
CONTENTFUL_SPACE_ID: ${{ inputs.contentful-space-id }}
METRIC: ${{ inputs.metric }}
5 changes: 5 additions & 0 deletions .github/actions/setup-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ outputs:
active-campaign-account:
description: 'Active Campaign Account'
value: ${{ steps.vars.outputs.active-campaign-account}}
crn-analytics-algolia-index:
description: 'Analytics Algolia Index'
value: ${{ steps.vars.outputs.crn-analytics-algolia-index }}
app-release:
description: 'App Release'
value: ${{ steps.vars.outputs.app-release }}
Expand Down Expand Up @@ -305,10 +308,12 @@ runs:
if [ "$CRN_CREATE_CONTENTFUL_PR_ENV" = true ]; then
echo "setting up dedicated PR env"
echo "crn-algolia-index=asap-hub_CI-$PR_NUMBER" >> $GITHUB_OUTPUT
echo "crn-analytics-algolia-index=crn-analytics_CI-$PR_NUMBER" >> $GITHUB_OUTPUT
echo "crn-contentful-env-id=crn-$PR_NUMBER" >> $GITHUB_OUTPUT
else
echo "setting up PR pointing to DEV env"
echo "crn-algolia-index=asap-hub_dev" >> $GITHUB_OUTPUT
echo "crn-analytics-algolia-index=crn-analytics_dev" >> $GITHUB_OUTPUT
echo "crn-contentful-env-id=Development" >> $GITHUB_OUTPUT
fi
Expand Down
1 change: 1 addition & 0 deletions .github/environment/Development
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
crn-analytics-algolia-index=crn-analytics_dev
contentful-environment=Development
crn-algolia-api-key-name=crn-algolia-api-key-ci-dev
crn-algolia-app-id-name=crn-algolia-app-id-dev
Expand Down
1 change: 1 addition & 0 deletions .github/environment/Production
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
active-campaign-account=asapgp2
crn-analytics-algolia-index=crn-analytics_prod
contentful-environment=Production
crn-algolia-api-key-name=crn-algolia-api-key-ci-prod
crn-algolia-app-id-name=crn-algolia-app-id-prod
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/on-demand-crn-analytics-algolia-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CRN Analytics Algolia Sync
on:
workflow_dispatch:
inputs:
metric:
required: false
type: choice
description: Choose which metric to sync
default: all
options:
- team-leadership
- all
environment-name:
required: true
type: environment
description: Choose which environment to sync
default: Branch
contentful-environment-id:
required: true
type: string
description: The contentful environment to sync from
default: Development
dedicated-contentful-environment:
required: false
type: boolean
default: false
pr-number:
required: false
type: string
description: The PR number to run for

jobs:
algolia:
uses: ./.github/workflows/reusable-crn-analytics-algolia-sync.yml
with:
environment-name: ${{ github.event.inputs.environment-name }}
metric: ${{ github.event.inputs.metric }}
pr-number: ${{ github.event.inputs.pr-number }}
dedicated-contentful-environment: ${{ inputs.dedicated-contentful-environment }}
contentful-environment-id: ${{ github.event.inputs.contentful-environment-id }}
secrets:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
CRN_CONTENTFUL_ACCESS_TOKEN: ${{ secrets.CRN_CONTENTFUL_ACCESS_TOKEN }}
CONTENTFUL_MANAGEMENT_TOKEN: ${{ secrets.CONTENTFUL_MANAGEMENT_TOKEN }}

notify_failure:
runs-on: ubuntu-latest
needs: [algolia]
if: ${{ failure() && github.event.inputs.environment-name=='Production' }}
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: ./.github/actions/slack/
with:
message: Analytics Algolia Prod Sync
webhook: ${{ env.SLACK_WEBHOOK }}
status: failure
2 changes: 2 additions & 0 deletions .github/workflows/on-remove.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,12 @@ jobs:
if: ${{ steps.setup.outputs.crn-on-branch-env == 'true'}}
run: |
yarn algolia:delete-index -a $ALGOLIA_APP_ID -k $ALGOLIA_API_KEY -n $ALGOLIA_INDEX
yarn algolia:delete-index -a $ALGOLIA_APP_ID -k $ALGOLIA_API_KEY -n $ALGOLIA_ANALYTICS_INDEX
env:
ALGOLIA_API_KEY: ${{ steps.algolia-keys.outputs.algolia-api-key }}
ALGOLIA_APP_ID: ${{ steps.algolia-keys.outputs.algolia-app-id }}
ALGOLIA_INDEX: ${{ steps.setup.outputs.crn-algolia-index }}
ALGOLIA_ANALYTICS_INDEX: ${{ steps.setup.outputs.crn-analytics-algolia-index }}

gp2-algolia-index:
if: ${{ github.event.inputs.pr-number || github.event.pull_request.head.repo.full_name == 'yldio/asap-hub' }}
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/on-schedule-analytics-algolia-sync-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: DEV - Sync CRN Analytics Algolia
on:
schedule:
- cron: '0 6 * * *' # At 06:00 UTC, everyday.
workflow_dispatch:

jobs:
setup:
runs-on: ubuntu-latest
container:
image: ghcr.io/yldio/asap-hub/node-python-sq:86a189edc900d4e1afdcf3935c697292f69d409b
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
environment: Development
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup
id: setup
uses: ./.github/actions/setup-environment
with:
environment-name: Development

sync-crn-analytics-algolia:
uses: ./.github/workflows/reusable-crn-analytics-algolia-sync.yml
with:
contentful-environment-id: Development
environment-name: Development
metric: all
secrets:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
CRN_CONTENTFUL_ACCESS_TOKEN: ${{ secrets.CRN_CONTENTFUL_ACCESS_TOKEN }}
CONTENTFUL_MANAGEMENT_TOKEN: ${{ secrets.CONTENTFUL_MANAGEMENT_TOKEN }}
35 changes: 35 additions & 0 deletions .github/workflows/on-schedule-analytics-algolia-sync-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: PROD - Sync Analytics Algolia
on:
schedule:
- cron: '0 6 * * *' # At 06:00 UTC, everyday.
workflow_dispatch:

jobs:
setup:
runs-on: ubuntu-latest
container:
image: ghcr.io/yldio/asap-hub/node-python-sq:86a189edc900d4e1afdcf3935c697292f69d409b
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
environment: Production
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup
id: setup
uses: ./.github/actions/setup-environment
with:
environment-name: Production

sync-crn-analytics-algolia:
uses: ./.github/workflows/reusable-crn-analytics-algolia-sync.yml
with:
contentful-environment-id: Production
environment-name: Production
metric: all
secrets:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
CRN_CONTENTFUL_ACCESS_TOKEN: ${{ secrets.CRN_CONTENTFUL_ACCESS_TOKEN }}
CONTENTFUL_MANAGEMENT_TOKEN: ${{ secrets.CONTENTFUL_MANAGEMENT_TOKEN }}
1 change: 1 addition & 0 deletions .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ jobs:
VITE_APP_RELEASE: ${{ steps.setup.outputs.app-release }}
VITE_APP_CRN_ALGOLIA_APP_ID: ${{ steps.crn-algolia-keys.outputs.algolia-app-id }}
VITE_APP_CRN_ALGOLIA_INDEX: ${{ steps.setup.outputs.crn-algolia-index }}
VITE_APP_CRN_ANALYTICS_ALGOLIA_INDEX: ${{ steps.setup.outputs.crn-analytics-algolia-index }}
VITE_APP_CRN_AUTH0_AUDIENCE: ${{ steps.setup.outputs.crn-auth0-audience }}
VITE_APP_CRN_AUTH0_CLIENT_ID: ${{ steps.setup.outputs.crn-auth0-client-id }}
VITE_APP_CRN_AUTH0_DOMAIN: ${{ steps.setup.outputs.crn-auth0-domain }}
Expand Down
39 changes: 29 additions & 10 deletions .github/workflows/reusable-create-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,29 +141,48 @@ jobs:
id: index-exists
shell: bash
run: |
OUTPUT=$(algolia settings get $ALGOLIA_INDEX 2>&1) || true
OUTPUT=$(algolia settings get $ENTITY_ALGOLIA_INDEX 2>&1) || true
if [[ "$OUTPUT" == *"Index does not exist"* ]]; then
echo "index-exists=false" >> $GITHUB_OUTPUT
echo "entity-index-exists=false" >> $GITHUB_OUTPUT
echo "Entity index does not exist"
else
echo "entity-index-exists=true" >> $GITHUB_OUTPUT
echo "Entity index exists"
fi
ANALYTICS_OUTPUT=$(algolia settings get $ANALYTICS_ALGOLIA_INDEX 2>&1) || true
if [[ "$ANALYTICS_OUTPUT" == *"Index does not exist"* ]]; then
echo "analytics-index-exists=false" >> $GITHUB_OUTPUT
echo "Index does not exist"
else
echo "index-exists=true" >> $GITHUB_OUTPUT
echo "analytics-index-exists=true" >> $GITHUB_OUTPUT
echo "Index exists"
fi
env:
ALGOLIA_APPLICATION_ID: ${{ steps.algolia-keys.outputs.algolia-app-id }}
ALGOLIA_ADMIN_API_KEY: ${{ steps.algolia-keys.outputs.algolia-api-key }}
ALGOLIA_INDEX: ${{ steps.setup.outputs.crn-algolia-index }}
- name: Copy index from Dev
if: ${{ inputs.environment-name=='Branch' && steps.index-exists.outputs.index-exists == 'false' && inputs.crn-on-branch-env == 'true' }}
ENTITY_ALGOLIA_INDEX: ${{ steps.setup.outputs.crn-algolia-index }}
ANALYTICS_ALGOLIA_INDEX: ${{ steps.setup.outputs.crn-analytics-algolia-index }}
- name: Copy entity index from Dev
if: ${{ inputs.environment-name=='Branch' && steps.index-exists.outputs.entity-index-exists == 'false' && inputs.crn-on-branch-env == 'true' }}
shell: bash
run: |
algolia indices copy -y -w $ALGOLIA_INDEX_DEV $ALGOLIA_INDEX
algolia indices copy -y -w $ALGOLIA_INDEX_DEV-reverse-timestamp $ALGOLIA_INDEX-reverse-timestamp
algolia indices copy -y -w $ENTITY_ALGOLIA_INDEX_DEV $ENTITY_ALGOLIA_INDEX
algolia indices copy -y -w $ENTITY_ALGOLIA_INDEX_DEV-reverse-timestamp $ENTITY_ALGOLIA_INDEX-reverse-timestamp
env:
ALGOLIA_APPLICATION_ID: ${{ steps.algolia-keys.outputs.algolia-app-id }}
ALGOLIA_ADMIN_API_KEY: ${{ steps.algolia-keys.outputs.algolia-api-key }}
ENTITY_ALGOLIA_INDEX_DEV: ${{ steps.setup-dev.outputs.crn-algolia-index }}
ENTITY_ALGOLIA_INDEX: ${{ steps.setup.outputs.crn-algolia-index }}
- name: Copy analytics index from Dev
if: ${{ inputs.environment-name=='Branch' && steps.index-exists.outputs.analytics-index-exists == 'false' && inputs.crn-on-branch-env == 'true' }}
shell: bash
run: |
algolia indices copy -y -w $ANALYTICS_ALGOLIA_INDEX_DEV $ANALYTICS_ALGOLIA_INDEX
env:
ALGOLIA_APPLICATION_ID: ${{ steps.algolia-keys.outputs.algolia-app-id }}
ALGOLIA_ADMIN_API_KEY: ${{ steps.algolia-keys.outputs.algolia-api-key }}
ALGOLIA_INDEX_DEV: ${{ steps.setup-dev.outputs.crn-algolia-index }}
ALGOLIA_INDEX: ${{ steps.setup.outputs.crn-algolia-index }}
ANALYTICS_ALGOLIA_INDEX_DEV: ${{ steps.setup-dev.outputs.crn-analytics-algolia-index }}
ANALYTICS_ALGOLIA_INDEX: ${{ steps.setup.outputs.crn-analytics-algolia-index }}

gp2-algolia-index:
runs-on: ubuntu-latest
Expand Down
Loading

0 comments on commit d7bfef3

Please sign in to comment.