Skip to content

Commit

Permalink
Merge pull request #3238 from responsible-ai-collaborative/staging
Browse files Browse the repository at this point in the history
Deploy to Production
  • Loading branch information
cesarvarela authored Nov 27, 2024
2 parents 6f659bd + 3386d1d commit f78a48f
Show file tree
Hide file tree
Showing 29 changed files with 4,189 additions and 1,408 deletions.
1 change: 0 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ jobs:
ROLLBAR_POST_SERVER_ITEM_ACCESS_TOKEN: ${{ secrets.GATSBY_ROLLBAR_TOKEN }}
API_MONGODB_CONNECTION_STRING: ${{ secrets.API_MONGODB_CONNECTION_STRING }}
SITE_URL: ${{ inputs.site-url || vars.SITE_URL }}
PROCESS_NOTIFICATIONS_SECRET: ${{ secrets.PROCESS_NOTIFICATIONS_SECRET }}

- name: Build size
run: |
Expand Down
67 changes: 38 additions & 29 deletions .github/workflows/process-notifications.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,50 @@
name: Process Notifications

on:
workflow_call:
inputs:
environment:
description: The Github environment to load secrets from
type: string
required: true
environment:
description: The Github environment to load secrets from
type: string
required: true
force-deploy:
description: Skip processing notifications if force deploy is true
type: boolean
required: false
default: false

jobs:
execute-mutation:
execute-process:
if: ${{ inputs.force-deploy != true }}
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Call GraphQL API
env:
SITE_URL: ${{ vars.SITE_URL }}
PROCESS_NOTIFICATIONS_SECRET: ${{ secrets.PROCESS_NOTIFICATIONS_SECRET }}
run: |
RESPONSE=$(curl -s -o response.json -w "%{http_code}" -X POST "$SITE_URL/api/graphql" \
-H "Content-Type: application/json" \
-H "PROCESS_NOTIFICATIONS_SECRET: $PROCESS_NOTIFICATIONS_SECRET" \
-d '{"query":"mutation { processNotifications }"}')
- name: Checkout code
uses: actions/checkout@v4

HTTP_STATUS=$RESPONSE
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
cache-dependency-path: site/gatsby-site/package-lock.json

if [ "$HTTP_STATUS" -ne 200 ]; then
echo "GraphQL mutation failed with HTTP status: $HTTP_STATUS"
cat response.json
exit 1
fi
- name: Install dependencies
working-directory: site/gatsby-site
run: npm ci

if jq -e 'has("errors") or has("errorType")' response.json > /dev/null; then
echo "GraphQL mutation failed with the following response:"
jq '.' response.json
exit 1
fi
echo "GraphQL mutation succeeded!"
jq '.' response.json
- name: Process Notifications
working-directory: site/gatsby-site
env:
REALM_API_APP_ID: ${{ vars.REALM_API_APP_ID }}
REALM_API_GROUP_ID: ${{ vars.REALM_API_GROUP_ID }}
REALM_API_PRIVATE_KEY: ${{ secrets.REALM_API_PRIVATE_KEY }}
REALM_API_PUBLIC_KEY: ${{ secrets.REALM_API_PUBLIC_KEY }}
REALM_GRAPHQL_API_KEY: ${{ secrets.REALM_GRAPHQL_API_KEY }}
REALM_APP_ID: ${{ vars.REALM_APP_ID }}
API_MONGODB_CONNECTION_STRING: ${{ secrets.API_MONGODB_CONNECTION_STRING }}
ROLLBAR_POST_SERVER_ITEM_ACCESS_TOKEN: ${{ secrets.ROLLBAR_POST_SERVER_ITEM_ACCESS_TOKEN }}
MAILERSEND_API_KEY: ${{ secrets.MAILERSEND_API_KEY }}
NOTIFICATIONS_SENDER_NAME: ${{ vars.NOTIFICATIONS_SENDER_NAME }}
NOTIFICATIONS_SENDER: ${{ vars.NOTIFICATIONS_SENDER }}
SITE_URL: ${{ vars.SITE_URL }}
run: npm run process-notifications:ci
14 changes: 11 additions & 3 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ jobs:
call-deploy:
if: (inputs.force-deploy == true || success()) && !cancelled()
uses: ./.github/workflows/deploy.yml
needs: [cache-modifier, call-test-api, call-test-playwright, call-test-playwright-full]
needs:
[
cache-modifier,
call-test-api,
call-test-playwright,
call-test-playwright-full,
]
secrets: inherit
permissions:
pull-requests: write
Expand All @@ -85,10 +91,12 @@ jobs:
netlify-alias:
runner-label: ${{ vars.PRODUCTION_RUNNER_LABEL }}
cache-modifier: ${{ needs.cache-modifier.outputs.cache-modifier }}

call-process-notifications:
needs: call-deploy
uses: ./.github/workflows/process-notifications.yml
secrets: inherit
with:
environment: production
environment: production
# inputs from the workflow_dispatch event come as strings even if they are explicitly defined as boolean
force-deploy: ${{ inputs.force-deploy == 'true' }}
4 changes: 3 additions & 1 deletion .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ jobs:
netlify-alias:
runner-label: ${{ vars.STAGING_RUNNER_LABEL }}
cache-modifier: ${{ needs.cache-modifier.outputs.cache-modifier }}

call-process-notifications:
needs: call-deploy
uses: ./.github/workflows/process-notifications.yml
secrets: inherit
with:
environment: staging
# inputs from the workflow_dispatch event come as strings even if they are explicitly defined as boolean
force-deploy: ${{ inputs.force-deploy == 'true' }}
3 changes: 0 additions & 3 deletions .github/workflows/test-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,10 @@ jobs:
REALM_API_PRIVATE_KEY: dummy
REALM_GRAPHQL_API_KEY: dummy
API_MONGODB_CONNECTION_STRING: "" # dinamically set by globalSetup.ts
E2E_ADMIN_USERNAME: ""
E2E_ADMIN_PASSWORD: ""
ROLLBAR_POST_SERVER_ITEM_ACCESS_TOKEN: sarasa
MAILERSEND_API_KEY: something
NOTIFICATIONS_SENDER_NAME: Test Preview
NOTIFICATIONS_SENDER: [email protected]
PROCESS_NOTIFICATIONS_SECRET: sarasa
SITE_URL: http://localhost:8000

- name: Upload coverage reports to Codecov
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test-playwright-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ jobs:
MAILERSEND_API_KEY: something
NOTIFICATIONS_SENDER_NAME: Test Preview
NOTIFICATIONS_SENDER: [email protected]
PROCESS_NOTIFICATIONS_SECRET: sarasa
SITE_URL: http://localhost:8000

- name: Upload Playwright traces
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test-playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ jobs:
MAILERSEND_API_KEY: something
NOTIFICATIONS_SENDER_NAME: Test Preview
NOTIFICATIONS_SENDER: [email protected]
PROCESS_NOTIFICATIONS_SECRET: sarasa
SITE_URL: http://localhost:8000

- uses: actions/upload-artifact@v4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const config = require('../config');

/** @type {import('umzug').MigrationFn<any>} */
exports.up = async ({ context: { client } }) => {
const db = client.db(config.realm.production_db.db_custom_data);

const notifications = db.collection('notifications');

// Mark all pending notifications as processed
const result = await notifications.updateMany(
{ processed: false },
{ $set: { processed: true } }
);

console.log(`All pending notifications marked as processed. Total: ${result.modifiedCount}`);
};
Loading

0 comments on commit f78a48f

Please sign in to comment.