From 14e66df37576abeb1e18973dd3520eeef35a125c Mon Sep 17 00:00:00 2001 From: Arman Jahanpour <77515879+rmanaem@users.noreply.github.com> Date: Mon, 13 Jan 2025 13:37:38 -0500 Subject: [PATCH] [MNT] Automated generation of result examples (#434) * Added submodules * Updated submodules * Added `UpdateExamples` e2e test * Added `Update examples` workflow * Included the submodules in the checkout step * Fixed typo in the file format * Added `update-query-tool-results` job * Fixed the open condition * Try checking out the examples repo directly * Fixed the oopsie * Let's try this * Removed commit step * Made a few small changes * Removed the debug step * Added permissions * Added pull-request permissions * Updated a few things * Fixed the oopsie * Let's use the latest version * Removed the label * Maybe we need to configure git user idk * A bit of cleaning up * Updated component-test workflow * Updated e2e-test workflow * bumped download-artifact to v4 * Set the specPattern for cypress tests * Bumped create-pull-request to v7 * Revert download-artifact to v3 thanks codeQL * Revert download-artifact to v3 thanks codeQL 2nd round * Bumped artifact version * Try using gh cli * Set git user * Set the owner * Set the committer --- .github/workflows/component-test.yaml | 2 + .github/workflows/e2e-test.yaml | 2 + .github/workflows/updated_examples.yaml | 77 +++++++++++++++++++++++++ cypress.config.ts | 2 + cypress/e2e/UpdateExamples.cy.ts | 18 ++++++ neurobagel_examples | 1 + recipes | 1 + 7 files changed, 103 insertions(+) create mode 100644 .github/workflows/updated_examples.yaml create mode 100644 cypress/e2e/UpdateExamples.cy.ts create mode 160000 neurobagel_examples create mode 160000 recipes diff --git a/.github/workflows/component-test.yaml b/.github/workflows/component-test.yaml index 457e694a..b52b4edb 100644 --- a/.github/workflows/component-test.yaml +++ b/.github/workflows/component-test.yaml @@ -13,6 +13,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + submodules: true - name: Create .env file run: | diff --git a/.github/workflows/e2e-test.yaml b/.github/workflows/e2e-test.yaml index 869abdcf..b96165d8 100644 --- a/.github/workflows/e2e-test.yaml +++ b/.github/workflows/e2e-test.yaml @@ -13,6 +13,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + submodules: true - name: Set up node env uses: actions/setup-node@v4 diff --git a/.github/workflows/updated_examples.yaml b/.github/workflows/updated_examples.yaml new file mode 100644 index 00000000..e4144e01 --- /dev/null +++ b/.github/workflows/updated_examples.yaml @@ -0,0 +1,77 @@ +name: update examples + +on: + pull_request: + workflow_dispatch: + +jobs: + generate-example-files: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: true + + - name: Set up node env + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Create .env file + run: | + echo -e "NB_API_QUERY_URL=https://federate.neurobagel.org/\nNB_ENABLE_AUTH=true\nNB_QUERY_CLIENT_ID=mockclientid" > .env + + - name: build + run: npm install && npm run build + + - name: Run end to end tests + uses: cypress-io/github-action@v6 + with: + wait-on: http://localhost:5173 + start: npm run preview + spec: cypress/e2e/UpdateExamples.cy.ts + component: false + + - name: Upload test artifacts + uses: actions/upload-artifact@v4 + with: + name: query-tool-results + path: cypress/downloads/* + + update-query-tool-results: + runs-on: ubuntu-latest + needs: generate-example-files + steps: + - name: Generate a token + id: generate-token + uses: actions/create-github-app-token@v1 + with: + app-id: ${{ vars.NB_BOT_ID }} + private-key: ${{ secrets.NB_BOT_KEY }} + owner: ${{ github.repository_owner }} + + - name: Checkout neurobagel_examples repository + uses: actions/checkout@v4 + with: + repository: neurobagel/neurobagel_examples + token: ${{ steps.generate-token.outputs.token }} + + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + name: query-tool-results + path: neurobagel_examples/query-tool-results + + - name: Create Pull Request + id: create_pr + uses: peter-evans/create-pull-request@v7 + with: + token: ${{ steps.generate-token.outputs.token }} + commit-message: Update `query-tool-results` files + title: Update `query-tool-results` files + body: "This PR updates the `query-tool-results` files with the latest changes." + base: main + branch: update-query-tool-results + committer: NeuroBagel Bot + labels: _bot \ No newline at end of file diff --git a/cypress.config.ts b/cypress.config.ts index 37902fc5..94b8d4ab 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -3,11 +3,13 @@ import { defineConfig } from 'cypress'; export default defineConfig({ e2e: { + specPattern: 'cypress/e2e/*', experimentalStudio: true, baseUrl: 'http://localhost:5173', }, component: { + specPattern: 'cypress/component/*', devServer: { framework: 'react', bundler: 'vite', diff --git a/cypress/e2e/UpdateExamples.cy.ts b/cypress/e2e/UpdateExamples.cy.ts new file mode 100644 index 00000000..3e50da44 --- /dev/null +++ b/cypress/e2e/UpdateExamples.cy.ts @@ -0,0 +1,18 @@ +import fapiQuerySuccess200 from '../../neurobagel_examples/api-responses/fapi_query_success_200.json'; + +describe('Update Examples', () => { + it('Removes a newline character from a dataset name in the downloaded dataset-level results file', () => { + cy.intercept('GET', 'query*', (req) => { + req.reply(fapiQuerySuccess200); + }).as('call'); + cy.visit('/'); + cy.get('[data-cy="close-auth-dialog-button"]').click(); + cy.get('[data-cy="submit-query-button"]').click(); + cy.wait('@call'); + cy.get('[data-cy="select-all-checkbox"]').find('input').check(); + cy.get('[data-cy="download-results-button"]').click(); + cy.get('[data-cy="download-results-dropdown-button"]').click(); + cy.contains('URIs').click(); + cy.get('[data-cy="download-results-button"]').click(); + }); +}); diff --git a/neurobagel_examples b/neurobagel_examples new file mode 160000 index 00000000..5690cd4f --- /dev/null +++ b/neurobagel_examples @@ -0,0 +1 @@ +Subproject commit 5690cd4f42ca9df9651e93d488b9acad3cdf3213 diff --git a/recipes b/recipes new file mode 160000 index 00000000..f52d2f27 --- /dev/null +++ b/recipes @@ -0,0 +1 @@ +Subproject commit f52d2f27dab581ceae43f5873de649a8cf5c329b