From c9e6351cac8b0aa4253bee7e5fb4837d216df147 Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Mon, 13 Nov 2023 11:41:12 -0300 Subject: [PATCH 1/4] Revert list style none for text editor preview --- site/gatsby-site/src/custom.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/site/gatsby-site/src/custom.css b/site/gatsby-site/src/custom.css index 3303b1a086..8f226f797b 100644 --- a/site/gatsby-site/src/custom.css +++ b/site/gatsby-site/src/custom.css @@ -9,3 +9,7 @@ a { appearance: none; -webkit-appearance: none; } + +.bytemd-preview ul, .bytemd-preview ol { + list-style: revert; +} From d4b27a06e788af12d0ec297975542e7cff90024b Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Mon, 13 Nov 2023 13:02:55 -0300 Subject: [PATCH 2/4] Add list styles back to editor preview --- site/gatsby-site/src/custom.css | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/site/gatsby-site/src/custom.css b/site/gatsby-site/src/custom.css index 8f226f797b..14888e8cbf 100644 --- a/site/gatsby-site/src/custom.css +++ b/site/gatsby-site/src/custom.css @@ -10,6 +10,10 @@ a { -webkit-appearance: none; } -.bytemd-preview ul, .bytemd-preview ol { - list-style: revert; +.bytemd-preview ul { + list-style: inside disc; +} + +.bytemd-preview ol { + list-style: inside auto; } From 05f36504f8504ec93d2c806763f0f9cc5c6817de Mon Sep 17 00:00:00 2001 From: Cesar Varela Date: Tue, 14 Nov 2023 17:50:28 -0300 Subject: [PATCH 3/4] Feature GitHub tests (#2414) * Add Cypress e2e tests as Github action * Add folder path to `cypress.yml` Github action * Add npm install step * Move to the site directory * Set working directory * Use npm install instead of yarn * add --legacy-peer-deps * `install: false` on cypress action * add github token * remove install-command from cypress step * Print Cypress record key * Increase query timeout to 15000 ms * Move checkout step to the top * Add custom install-command * Fix Cypress config file name * Add wait-on: http://localhost:8000/ * Add npm start and increase timeout to 2 mins * Add ENV vars from Github secrets * Remove unused npm install step * Add projectId to Cypress * Add missing env variables on Cypress tests * Increase query timeout from 15000 to 30000 * Record tests on Cypress dashboard * Add parallel tests * Add 10 parallel jobs * Split install and tests * Add working-directory * Add `install` job as initial job * Upload and download artifacts * Add cache to node_modules * Remove dependency * Touch to trigger deploy * Add cache to install job * Add npm list to check npm modules * Add echo for cache hit * Remove step IF condition * Fix typo on step syntax * Use relative path to cache node_modules * Cache `~/.cache/Cypress` folder * Change `npm install` to `npm ci` * Change Cypress group name * Start the Gatsby server in a separate job * Add env vars to `npm start` * Add wait-on on `npm start` * Add `RUNNER_TRACKING_ID="" && ` * Change `npm start` to `npm serve` * Add `run` on `npm` scripts * Change Cypress port to `9000` * Fix cache folder paths * Upload and download `public` and `.cache` folders as artifacts * Change upload/download artifact to cache * Add jobs' name * Remove unused `serve` script from `package.json` * Add Github secrets documentation in the README file * Remove timeout from `query` command * Change `wait-on-timeout` to 5mins * Remove `netlify.toml` file. Netlify won't run the Cypress tests anymore. * Remove just the `netlify-plugin-cypress` plugin from `netlify.toml` * Comment `.cache` and `public` folder cache * Add 10 mins timeout for `gatsby develop` * Rename job accordingly * Increase temporary `defaultCommandTimeout` to 1 min * Add `GATSBY_REALM_APP_GRAPHQL_URL` new env variable since Realm GraphQL service url changed * Add missing `GATSBY_REALM_APP_GRAPHQL_URL` variable to `cypress.yml` job * Fix typo on `cypress.yml` * Reduce `defaultCommandTimeout` to 30s * Touch README * touch README * Add `Deploy to Netlify` job * Increase temporary `defaultCommandTimeout` to 1 min * Comment job dependency to test Netlify deploy * Add `npm run build` * Add `--legacy-peer-deps` flag * Separate `npm install` and `npm run build` * change `netlify.toml` file path * change `netlify.toml` file path * Change `publish-dir` path * Set deploy timeout to 10 mins * Remove `Deploy to Netlify` job from GH action * Set the commit message to the pull request title * Add more info on a comment * Trigger deploy * Only process videos in the case that tests fail (`videoUploadOnPasses`: `false`) * Add `MONGODB_MIGRATIONS_CONNECTION_STRING` to cypress step * Tag cypress record with branch name * Add `https://pablo-staging-aiid.netlify.app` to Realm allowed origins * Add `npm run build` step * add `env` variables to `npm run build` step * cache `public` folder * Remove unused step id * Set `commit` echo output * Use `gatsby serve` * Change serve port to use `8000` * Cypress to wait for port 8000 * Change `public` folder cache name * Increase parallel machines from 5 to 10 * Undo unnecessary graphql api url change * only run actions against specific branches * Move cypress workflow into reusable one * Fix test name * Make realm staging deploy reusable * Enable cypress videos * Add test workflow * tmp delete netlify config * undo tests * cleanup diff * moar cleanup --------- Co-authored-by: Pablo Costa --- .github/workflows/deploy.yml | 206 ++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 19 ++++ site/gatsby-site/package.json | 2 +- 3 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000000..7bdfcb5030 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -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/cache@v3.0.5 + 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/cache@v3.0.5 + 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/cache@v3.0.5 + 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/cache@v3.0.5 + 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 }} + diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000000..daedff44dc --- /dev/null +++ b/.github/workflows/test.yml @@ -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 diff --git a/site/gatsby-site/package.json b/site/gatsby-site/package.json index 1d966b8c06..b2a1fd3cf8 100644 --- a/site/gatsby-site/package.json +++ b/site/gatsby-site/package.json @@ -154,4 +154,4 @@ "minimist": "1.2.8", "d3-color": "3.1.0" } -} +} \ No newline at end of file From 5248f98747da11cd0f7b214d620bce756a8f2d28 Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Wed, 15 Nov 2023 15:29:46 -0300 Subject: [PATCH 4/4] Remove submission notification/subscription when parent incidents (#2411) * Remove submission notification/subscription when parent incidents * Check for subscriptions to submissionPromoted --- .../functions/promoteSubmissionToReport.cy.js | 12 ++++++++++++ site/realm/functions/promoteSubmissionToReport.js | 15 +-------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/site/gatsby-site/cypress/e2e/unit/functions/promoteSubmissionToReport.cy.js b/site/gatsby-site/cypress/e2e/unit/functions/promoteSubmissionToReport.cy.js index cad7a52f5b..bc100dea5b 100644 --- a/site/gatsby-site/cypress/e2e/unit/functions/promoteSubmissionToReport.cy.js +++ b/site/gatsby-site/cypress/e2e/unit/functions/promoteSubmissionToReport.cy.js @@ -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 @@ -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', + }); }); }); @@ -414,6 +422,8 @@ describe('Functions', () => { ...expectedReport, modifiedBy: submission_with_embedding.user, }); + + expect(subscriptionsCollection.insertOne.called).to.be.false; }); }); @@ -565,6 +575,8 @@ describe('Functions', () => { ...expectedReport, modifiedBy: submission.user, }); + + expect(subscriptionsCollection.insertOne.called).to.be.false; }); }); diff --git a/site/realm/functions/promoteSubmissionToReport.js b/site/realm/functions/promoteSubmissionToReport.js index 02e2b9de98..0029dde991 100644 --- a/site/realm/functions/promoteSubmissionToReport.js +++ b/site/realm/functions/promoteSubmissionToReport.js @@ -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