From 9901d8a63d2c6bce37c54b87db77be5c32361fee Mon Sep 17 00:00:00 2001 From: Yaron Dayagi Date: Sun, 31 Dec 2023 17:03:23 +0200 Subject: [PATCH] add integration tests to BE FLPATH-799 https://issues.redhat.com/browse/FLPATH-799 Signed-off-by: Yaron Dayagi --- .github/actions/test/action.yaml | 22 ++++-- .github/workflows/pr-semantic.yaml | 73 ------------------- .github/workflows/push.yaml | 23 +----- app-config.yaml | 25 ++++++- packages/backend/src/index.ts | 5 ++ packages/backend/src/plugins/notifications.ts | 18 +++++ plugins/notifications-backend/users.yaml | 1 + 7 files changed, 63 insertions(+), 104 deletions(-) delete mode 100644 .github/workflows/pr-semantic.yaml create mode 100644 packages/backend/src/plugins/notifications.ts diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index 05788dd2d10..85cbd4339b8 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -8,7 +8,7 @@ runs: using: 'composite' steps: - name: Setup Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version-file: '.nvmrc' cache: 'yarn' @@ -20,14 +20,22 @@ runs: shell: bash run: yarn --prefer-offline --frozen-lockfile - - name: Run prettier + - name: Build all packages shell: bash - run: yarn prettier:check + run: yarn build --filter=${{ inputs.args }} --concurrency=1 - - name: Run lint + - name: Start backstage shell: bash - run: yarn lint --filter=${{ inputs.args }} + run: yarn install - - name: Run tests + - name: Start backstage shell: bash - run: yarn test --filter=${{ inputs.args }} + run: ls;yarn start:backstage + + - name: Wait for backstage + shell: bash + run: timeout 15 bash -c 'until echo > /dev/tcp/localhost/7007; do sleep 3; done' + + - name: Test get notifications + shell: bash + run: curl http://localhost:7007/api/notifications/notifications diff --git a/.github/workflows/pr-semantic.yaml b/.github/workflows/pr-semantic.yaml deleted file mode 100644 index f29b897d046..00000000000 --- a/.github/workflows/pr-semantic.yaml +++ /dev/null @@ -1,73 +0,0 @@ -name: 'Semantic Release' - -on: - pull_request_target: - types: - - opened - - edited - - synchronize - - labeled - - unlabeled - -jobs: - title: - name: Conventional Commits - runs-on: ubuntu-latest - steps: - - uses: amannn/action-semantic-pull-request@c3cd5d1ea3580753008872425915e343e351ab54 # v5 - id: lint_pr_title - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - # Since we use `conventionalcommits` preset for - # `@semantic-release/commit-analyzer`, this list has to match allowed types - # Ref: https://github.com/conventional-changelog/conventional-changelog-config-spec/blob/master/versions/2.2.0/README.md#types - types: | - feat - fix - chore - docs - style - refactor - perf - test - revert - requireScope: false - subjectPattern: ^(?![A-Z]).+$ - subjectPatternError: | - The subject "{subject}" found in the pull request title "{title}" - didn't match the configured pattern. Please ensure that the subject - doesn't start with an uppercase character. - ignoreLabels: | - ignore-semantic-pull-request - # For work-in-progress PRs you can typically use draft pull requests - # from GitHub. However, private repositories on the free plan don't have - # this option and therefore this action allows you to opt-in to using the - # special "[WIP]" prefix to indicate this state. This will avoid the - # validation of the PR title and the pull request checks remain pending. - # Note that a second check will be reported if this is enabled. - wip: true - - - uses: marocchino/sticky-pull-request-comment@efaaab3fd41a9c3de579aba759d2552635e590fd # v2 - # When the previous steps fails, the workflow would stop. By adding this - # condition you can continue the execution with the populated error message. - if: always() && (steps.lint_pr_title.outputs.error_message != null) - with: - header: pr-title-lint-error - message: | - Hey there and thank you for opening this pull request! 👋🏼 - - We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted. - - Details: - - ``` - ${{ steps.lint_pr_title.outputs.error_message }} - ``` - - # Delete a previous comment when the issue has been resolved - - if: ${{ steps.lint_pr_title.outputs.error_message == null }} - uses: marocchino/sticky-pull-request-comment@efaaab3fd41a9c3de579aba759d2552635e590fd # v2 - with: - header: pr-title-lint-error - delete: true diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index a79cd11da4a..6a104969bb8 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -3,7 +3,7 @@ name: Push on: push: branches: - - main + - flpath799 concurrency: group: push @@ -19,24 +19,3 @@ jobs: - name: Test uses: ./.github/actions/test - - release: - name: Release - needs: - - test - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Build all packages - uses: ./.github/actions/build - - - name: Release via semantic-release - run: | - npm config set workspaces-update false - yarn release --ignore-private-packages - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - NODE_OPTIONS: '--max-old-space-size=8192' diff --git a/app-config.yaml b/app-config.yaml index cd01d53707c..2f0654283b5 100644 --- a/app-config.yaml +++ b/app-config.yaml @@ -28,7 +28,25 @@ backend: # This is for local development only, it is not recommended to use this in production # The production database configuration is stored in app-config.production.yaml database: - connection: ':memory:' + client: better-sqlite3 + connection: + ':memory:' + #directory: ./mydb.sqlite + useNullAsDefault: true + #plugin: + #notifications: + #connection: + #filename: ./mydb.sqlite/thedb.sqlite + #host: 127.0.0.1 + #port: 5432 + #user: postgres + #password: secret + #knexConfig: + # pool: + # min: 3 + # max: 12 + # acquireTimeoutMillis: 60000 + # idleTimeoutMillis: 60000 cache: store: memory # workingDirectory: /tmp # Use this to configure a working directory for the scaffolder, defaults to the OS temp-dir @@ -84,8 +102,11 @@ catalog: entityFilename: catalog-info.yaml pullRequestBranchName: backstage-integration rules: - - allow: [Component, System, API, Resource, Location] + - allow: [Component, System, API, Resource, Location, User, Group] locations: + - type: file + # *** Here is new change, referes to a file stored in the root of the Backstage: + target: /home/ydayagi/work/src/github.com/ydayagi/backstage-plugins/plugins/notifications-backend/users.yaml # Local example data, file locations are relative to the backend process, typically `packages/backend` - type: file target: ../../examples/entities.yaml diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts index a15ad6bc792..ebaba1b8db4 100644 --- a/packages/backend/src/index.ts +++ b/packages/backend/src/index.ts @@ -28,6 +28,7 @@ import Router from 'express-promise-router'; import app from './plugins/app'; import auth from './plugins/auth'; import catalog from './plugins/catalog'; +import notifications from './plugins/notifications'; import permission from './plugins/permissions'; import proxy from './plugins/proxy'; import scaffolder from './plugins/scaffolder'; @@ -104,6 +105,10 @@ async function main() { getPluginIds: () => ['catalog', 'scaffolder', 'permission'], }), ); + const notificationsEnv = useHotMemoize(module, () => + createEnv('notifications'), + ); + apiRouter.use('/notifications', await notifications(notificationsEnv)); // Add backends ABOVE this line; this 404 handler is the catch-all fallback apiRouter.use(notFoundHandler()); diff --git a/packages/backend/src/plugins/notifications.ts b/packages/backend/src/plugins/notifications.ts new file mode 100644 index 00000000000..f64d7b3dcae --- /dev/null +++ b/packages/backend/src/plugins/notifications.ts @@ -0,0 +1,18 @@ +import { CatalogClient } from '@backstage/catalog-client'; +import { createRouter } from '@backstage/plugin-notifications-backend'; + +import { Router } from 'express'; + +import { PluginEnvironment } from '../types'; + +export default async function createPlugin( + env: PluginEnvironment, +): Promise { + const catalogClient = new CatalogClient({ discoveryApi: env.discovery }); + const dbConfig = env.config.getConfig('backend.database'); + return await createRouter({ + logger: env.logger, + dbConfig, + catalogClient, + }); +} diff --git a/plugins/notifications-backend/users.yaml b/plugins/notifications-backend/users.yaml index 60fb810885a..288e52c6f45 100644 --- a/plugins/notifications-backend/users.yaml +++ b/plugins/notifications-backend/users.yaml @@ -1,6 +1,7 @@ apiVersion: backstage.io/v1alpha1 kind: User metadata: + namespace: default name: guest spec: profile: