Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staging into re-send-verification #30

Merged
merged 7 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
206 changes: 206 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
name: Deploy
on:
workflow_call:
inputs:
environment:
type: string
description: Environment to deploy to
required: true

jobs:
install-and-build:
name: NPM install and build site
environment: ${{ inputs.environment }}
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: site/gatsby-site
steps:
- name: Checkout
uses: actions/checkout@v2

# Cache 'node_modules' and '~/.cache/Cypress' folder
- name: Cache node modules
id: cache-nodemodules
uses: actions/[email protected]
env:
cache-name: cache-install-folder
with:
# caching node_modules
path: |
site/gatsby-site/node_modules
~/.cache/Cypress
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-

# Install NPM dependencies
- name: Install NPM dependencies
if: steps.cache-nodemodules.outputs.cache-hit != 'true'
uses: cypress-io/github-action@v4
with:
working-directory: site/gatsby-site
# just perform install
runTests: false
install-command: npm ci --legacy-peer-deps

# Build Gatbsy site
- name: Build site
run: npm run build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CYPRESS_PROJECT_ID: ${{ secrets.CYPRESS_PROJECT_ID }}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
E2E_ADMIN_USERNAME: ${{ secrets.E2E_ADMIN_USERNAME }}
E2E_ADMIN_PASSWORD: ${{ secrets.E2E_ADMIN_PASSWORD }}
ALGOLIA_ADMIN_KEY: ${{ secrets.ALGOLIA_ADMIN_KEY }}
GATSBY_ALGOLIA_APP_ID: ${{ secrets.GATSBY_ALGOLIA_APP_ID }}
GATSBY_ALGOLIA_SEARCH_KEY: ${{ secrets.GATSBY_ALGOLIA_SEARCH_KEY }}
GATSBY_AVAILABLE_LANGUAGES: ${{ secrets.GATSBY_AVAILABLE_LANGUAGES }}
GATSBY_REALM_APP_ID: ${{ secrets.GATSBY_REALM_APP_ID }}
GOOGLE_TRANSLATE_API_KEY: ${{ secrets.GOOGLE_TRANSLATE_API_KEY }}
MONGODB_CONNECTION_STRING: ${{ secrets.MONGODB_CONNECTION_STRING }}
MONGODB_REPLICA_SET: ${{ secrets.MONGODB_REPLICA_SET }}
MONGODB_TRANSLATIONS_CONNECTION_STRING: ${{ secrets.MONGODB_TRANSLATIONS_CONNECTION_STRING }}
MONGODB_MIGRATIONS_CONNECTION_STRING: ${{ secrets.MONGODB_MIGRATIONS_CONNECTION_STRING }}
GATSBY_REALM_APP_GRAPHQL_URL: ${{ secrets.GATSBY_REALM_APP_GRAPHQL_URL }}

# Extract commit hash to use as a cache key
- name: Extract commit hash
shell: bash
run: echo "##[set-output name=commit;]$(echo ${GITHUB_SHA})"
id: extract_commit_hash

# Cache 'public' folder
- name: Cache public folder
uses: actions/[email protected]
env:
cache-name: cache-public
with:
path: |
site/gatsby-site/public
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ steps.extract_commit_hash.outputs.commit }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-

test:
name: Run Cypress tests
environment: ${{ inputs.environment }}
runs-on: ubuntu-latest
needs: install-and-build
defaults:
run:
shell: bash
working-directory: site/gatsby-site
strategy:
# when one test fails, DO NOT cancel the other
# containers, because this will kill Cypress processes
# leaving the Dashboard hanging ...
# https://github.com/cypress-io/github-action/issues/48
fail-fast: false
matrix:
# run 10 copies of the current job in parallel
containers: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# stop the job if it runs over 20 minutes
# to prevent a hanging process from using all your CI minutes
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@v2

# Cache node_modules folder
- name: Cache node modules
id: cache-nodemodules-2
uses: actions/[email protected]
env:
cache-name: cache-install-folder
with:
# caching node_modules
path: |
site/gatsby-site/node_modules
~/.cache/Cypress
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-

# Install NPM dependencies
- name: Install NPM dependencies
if: steps.cache-nodemodules-2.outputs.cache-hit != 'true'
uses: cypress-io/github-action@v4
with:
working-directory: site/gatsby-site
# just perform install
runTests: false
install-command: npm ci --legacy-peer-deps

# Extract commit hash to use as a cache key
- name: Extract commit hash
shell: bash
run: echo "##[set-output name=commit;]$(echo ${GITHUB_SHA})"
id: extract_commit_hash

# Cache 'public' folder
- name: Cache public folder
uses: actions/[email protected]
env:
cache-name: cache-public
with:
path: |
site/gatsby-site/public
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ steps.extract_commit_hash.outputs.commit }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-

# Extract branch name
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch

# Run all Cypress tests
- name: Cypress run
uses: cypress-io/github-action@v4
with:
working-directory: site/gatsby-site
# we have already installed all dependencies above
install: false
config-file: cypress.config.js
record: true
parallel: true
group: "Cypress e2e tests"
tag: ${{ steps.extract_branch.outputs.branch }}
start: npm run serve
wait-on: http://localhost:8000/
# wait for 10 minutes for the server to respond
wait-on-timeout: 600
env:
# Recommended: pass the GitHub token lets this action correctly
# determine the unique run id necessary to re-run the checks
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CYPRESS_PROJECT_ID: ${{ secrets.CYPRESS_PROJECT_ID }}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
E2E_ADMIN_USERNAME: ${{ secrets.E2E_ADMIN_USERNAME }}
E2E_ADMIN_PASSWORD: ${{ secrets.E2E_ADMIN_PASSWORD }}
ALGOLIA_ADMIN_KEY: ${{ secrets.ALGOLIA_ADMIN_KEY }}
GATSBY_ALGOLIA_APP_ID: ${{ secrets.GATSBY_ALGOLIA_APP_ID }}
GATSBY_ALGOLIA_SEARCH_KEY: ${{ secrets.GATSBY_ALGOLIA_SEARCH_KEY }}
GATSBY_AVAILABLE_LANGUAGES: ${{ secrets.GATSBY_AVAILABLE_LANGUAGES }}
GATSBY_REALM_APP_ID: ${{ secrets.GATSBY_REALM_APP_ID }}
GOOGLE_TRANSLATE_API_KEY: ${{ secrets.GOOGLE_TRANSLATE_API_KEY }}
MONGODB_CONNECTION_STRING: ${{ secrets.MONGODB_CONNECTION_STRING }}
MONGODB_REPLICA_SET: ${{ secrets.MONGODB_REPLICA_SET }}
MONGODB_TRANSLATIONS_CONNECTION_STRING: ${{ secrets.MONGODB_TRANSLATIONS_CONNECTION_STRING }}
MONGODB_MIGRATIONS_CONNECTION_STRING: ${{ secrets.MONGODB_MIGRATIONS_CONNECTION_STRING }}
GATSBY_REALM_APP_GRAPHQL_URL: ${{ secrets.GATSBY_REALM_APP_GRAPHQL_URL }}
# Since this is triggered on a pull request, we set the commit message to the pull request title
COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }}

19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Deploy Staging

on:
push:
branches:
- feature-github-tests

jobs:
# call-realm:
# uses: ./.github/workflows/realm.yml
# secrets: inherit
# with:
# environment: staging
call-deploy:
uses: ./.github/workflows/deploy.yml
secrets: inherit
with:
environment: staging
# needs: call-realm
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { SUBSCRIPTION_TYPE } = require('../../../../src/utils/subscriptions');

const promoteSubmissionToReport = require('../../../../../realm/functions/promoteSubmissionToReport');

//should be on its own /cypress/unit folder or something
Expand Down Expand Up @@ -257,6 +259,12 @@ describe('Functions', () => {
...expectedReport,
modifiedBy: submission.user,
});

expect(subscriptionsCollection.insertOne.firstCall.args[0]).to.deep.equal({
type: SUBSCRIPTION_TYPE.submissionPromoted,
incident_id: 2,
userId: 'user1',
});
});
});

Expand Down Expand Up @@ -414,6 +422,8 @@ describe('Functions', () => {
...expectedReport,
modifiedBy: submission_with_embedding.user,
});

expect(subscriptionsCollection.insertOne.called).to.be.false;
});
});

Expand Down Expand Up @@ -565,6 +575,8 @@ describe('Functions', () => {
...expectedReport,
modifiedBy: submission.user,
});

expect(subscriptionsCollection.insertOne.called).to.be.false;
});
});

Expand Down
2 changes: 1 addition & 1 deletion site/gatsby-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@
"minimist": "1.2.8",
"d3-color": "3.1.0"
}
}
}
8 changes: 8 additions & 0 deletions site/gatsby-site/src/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ a {
appearance: none;
-webkit-appearance: none;
}

.bytemd-preview ul {
list-style: inside disc;
}

.bytemd-preview ol {
list-style: inside auto;
}
15 changes: 1 addition & 14 deletions site/realm/functions/promoteSubmissionToReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,7 @@ exports = async (input) => {
{ incident_id: BSON.Int32(parentIncident.incident_id) },
{ $set: { ...parentIncident, embedding } }
);

if (submission.user) {
await subscriptionsCollection.insertOne({
type: 'submission-promoted',
incident_id: BSON.Int32(parentIncident.incident_id),
userId: submission.user
});

await notificationsCollection.insertOne({
type: 'submission-promoted',
incident_id: BSON.Int32(parentIncident.incident_id),
processed: false
});
}

let incidentValues = parentIncident;

delete incidentValues._id; // Otherwise Mongo complains about duplicate _id in incidentsHistory
Expand Down