From ebe548d2301d0b320c3cf7d5ac99ba122cff001b Mon Sep 17 00:00:00 2001 From: juliusdw Date: Tue, 9 Apr 2024 20:11:23 +0200 Subject: [PATCH 01/13] Feature/create test job (#8) * add initial example workflow * update testing steps to yarn test * add checkout repo * add setup node js * add yarn install * rename test * change test text to correct value * add end to end tests * add playwright url for test env * add install playwright browser * fix: typo in localhost * test: add some logging * test: ci env variable * fix: make CI env variable empty * fix: unset CI env var, set by default in GithHub Actions * try without playwright browser * add pre commit tests * this is a test commit * change test comand * change when test runs * add initial example workflow * update testing steps to yarn test * add checkout repo * add setup node js * add yarn install * rename test * change test text to correct value * add end to end tests * add playwright url for test env * add install playwright browser * fix: typo in localhost * test: add some logging * test: ci env variable * fix: make CI env variable empty * fix: unset CI env var, set by default in GithHub Actions * try without playwright browser * add pre commit tests * this is a test commit * change test comand * change when test runs * change backstage url port in e2e test * Update test command in run-tests.yml * add testing section to readme --- .github/workflows/run-tests.yml | 38 ++++++++++++++++++++++++++++++ README.md | 14 +++++++++++ package.json | 7 +++++- packages/app/e2e-tests/app.test.ts | 2 +- packages/app/src/App.test.tsx | 2 +- yarn.lock | 12 ++-------- 6 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/run-tests.yml diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..2427e31 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,38 @@ +name: Test and E2E tests +run-name: Run tests and E2E tests + +on: + push: + pull_request: + branches: + - main +jobs: + run-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + - run: yarn install + - run: yarn backstage-cli repo test + + run-e2e-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 #chekcout te repository + - name: Use Node.js + uses: actions/setup-node@v3 #setup node version 20 + with: + node-version: '20' + + - name: Install dependencies #install dependencies + run: yarn install + + - name: Run E2E tests + env: + PLAYWRIGHT_URL: http://localhost:3000 # set the URL of the app to test with playwright + CI: # unset CI because it is set by default in Github actions + run: | + yarn test:e2e diff --git a/README.md b/README.md index 6324793..e07510c 100644 --- a/README.md +++ b/README.md @@ -298,3 +298,17 @@ This file changes some base values that are necessary to build the correct image **`app-config.production.yaml`:**
This file adds one line to the kubernetes plugin setup, which is only needed if the app is hosted inside of a kubernetes cluster. + +# Testing + +Before committing your changes, run the tests pls. ✨ + +```sh +yarn test +``` + +to run tests without end to end testing run: + +```sh +yarn backstage-cli repo test +``` \ No newline at end of file diff --git a/package.json b/package.json index 09c3be2..2ec8570 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "tsc": "tsc", "tsc:full": "tsc --skipLibCheck false --incremental false", "clean": "backstage-cli repo clean", - "test": "backstage-cli repo test", + "test": "backstage-cli repo test && playwright test", "test:all": "backstage-cli repo test --coverage", "test:e2e": "playwright test", "fix": "backstage-cli repo fix", @@ -31,6 +31,10 @@ "docker:remove-all": "docker compose down", "new": "backstage-cli new --scope internal" }, + "pre-commit": [ + "yarn test", + "yarn e2e-test" + ], "workspaces": { "packages": [ "packages/*", @@ -62,4 +66,5 @@ "prettier --write" ] } + } diff --git a/packages/app/e2e-tests/app.test.ts b/packages/app/e2e-tests/app.test.ts index d45bc0d..9807ea2 100644 --- a/packages/app/e2e-tests/app.test.ts +++ b/packages/app/e2e-tests/app.test.ts @@ -19,5 +19,5 @@ import { test, expect } from '@playwright/test'; test('App should render the welcome page', async ({ page }) => { await page.goto('/'); - await expect(page.getByText('My Company Catalog')).toBeVisible(); + await expect(page.getByText('Scaffolded Backstage App')).toBeVisible(); }); diff --git a/packages/app/src/App.test.tsx b/packages/app/src/App.test.tsx index ec8ba1d..824bc54 100644 --- a/packages/app/src/App.test.tsx +++ b/packages/app/src/App.test.tsx @@ -10,7 +10,7 @@ describe('App', () => { { data: { app: { title: 'Test' }, - backend: { baseUrl: 'http://localhost:7007' }, + backend: { baseUrl: 'http://localhost:3000' }, techdocs: { storageUrl: 'http://localhost:7007/api/techdocs/static/docs', }, diff --git a/yarn.lock b/yarn.lock index 8ec8567..0d6459f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8915,7 +8915,8 @@ resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.7.tgz#50ae4353eaaddc04044279812f52c8c65857dbcb" integrity sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ== -"@types/react-dom@*", "@types/react-dom@^18.0.0": +"@types/react-dom@*", "@types/react-dom@^18", "@types/react-dom@^18.0.0": +"@types/react-dom@*", "@types/react-dom@^18", "@types/react-dom@^18.0.0": version "18.2.19" resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.2.19.tgz#b84b7c30c635a6c26c6a6dfbb599b2da9788be58" integrity sha512-aZvQL6uUbIJpjZk4U8JZGbau9KDeAwMfmhyWorxgBkqDIEf6ROjRozcmPIicqsUwPUjbkDfHKgGee1Lq65APcA== @@ -8953,15 +8954,6 @@ dependencies: "@types/react" "*" -"@types/react@*", "@types/react@^16.13.1 || ^17.0.0 || ^18.0.0": - version "18.2.56" - resolved "https://registry.yarnpkg.com/@types/react/-/react-18.2.56.tgz#2d3e9021a0b6eb5bfc227761cc61b1c6dc6e0cd8" - integrity sha512-NpwHDMkS/EFZF2dONFQHgkPRwhvgq/OAvIaGQzxGSBmaeR++kTg6njr15Vatz0/2VcCEwJQFi6Jf4Q0qBu0rLA== - dependencies: - "@types/prop-types" "*" - "@types/scheduler" "*" - csstype "^3.0.2" - "@types/react@^16.13.1 || ^17.0.0": version "17.0.75" resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.75.tgz#cffbc76840a12fcadaf5a3cf14878bb06efcf73d" From 992bd8251ea0a9b4cf797d00eaf113f7795bd3e2 Mon Sep 17 00:00:00 2001 From: juliusdw Date: Thu, 11 Apr 2024 18:06:42 +0200 Subject: [PATCH 02/13] add initial gcloud comands --- .github/workflows/create-user-db.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/workflows/create-user-db.yml diff --git a/.github/workflows/create-user-db.yml b/.github/workflows/create-user-db.yml new file mode 100644 index 0000000..d881459 --- /dev/null +++ b/.github/workflows/create-user-db.yml @@ -0,0 +1,13 @@ +jobs: + job_id: + steps: + - id: 'auth' + uses: 'google-github-actions/auth@v2' + with: + credentials_json: '${{ secrets.GCP_CREDENTIALS }}' + - id: 'Set up Cloud SDK' + uses: 'google-github-actions/setup-gcloud@v2' + - name: 'Use gcloud CLI' + run: 'gcloud info' + - name: 'Use gcloud CLI to create DB' + run: 'gcloud sql databases create TEST-DB23 --instance=idp-postgres-db --project=code-idp' From 5f9a35a5b099ced71210b7ee3626cfa4896477ee Mon Sep 17 00:00:00 2001 From: juliusdw Date: Thu, 11 Apr 2024 18:16:05 +0200 Subject: [PATCH 03/13] add run on none --- .github/workflows/create-user-db.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/create-user-db.yml b/.github/workflows/create-user-db.yml index d881459..928a37d 100644 --- a/.github/workflows/create-user-db.yml +++ b/.github/workflows/create-user-db.yml @@ -1,3 +1,6 @@ + +on: [none] + jobs: job_id: steps: From c7db7d6fbf623fe6d333a31a9af8b4138da8bc7b Mon Sep 17 00:00:00 2001 From: juliusdw Date: Thu, 11 Apr 2024 18:16:53 +0200 Subject: [PATCH 04/13] change run on workflow --- .github/workflows/create-user-db.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/create-user-db.yml b/.github/workflows/create-user-db.yml index 928a37d..c5713df 100644 --- a/.github/workflows/create-user-db.yml +++ b/.github/workflows/create-user-db.yml @@ -1,6 +1,6 @@ -on: [none] - +on: + workflow_dispatch: jobs: job_id: steps: From 28d2cf3e8b20cc509de7d3266e5baeed214a494c Mon Sep 17 00:00:00 2001 From: juliusdw Date: Thu, 11 Apr 2024 18:24:04 +0200 Subject: [PATCH 05/13] add runs on --- .github/workflows/create-user-db.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/create-user-db.yml b/.github/workflows/create-user-db.yml index c5713df..e268c89 100644 --- a/.github/workflows/create-user-db.yml +++ b/.github/workflows/create-user-db.yml @@ -1,14 +1,18 @@ +name: Create User DB on: workflow_dispatch: + jobs: - job_id: + create-db: + runs-on: ubuntu-latest + steps: - - id: 'auth' + - name: 'auth' uses: 'google-github-actions/auth@v2' with: credentials_json: '${{ secrets.GCP_CREDENTIALS }}' - - id: 'Set up Cloud SDK' + - name: 'Set up Cloud SDK' uses: 'google-github-actions/setup-gcloud@v2' - name: 'Use gcloud CLI' run: 'gcloud info' From 7ffea201a00965ce3755dfb313b705e43da221ac Mon Sep 17 00:00:00 2001 From: juliusdw Date: Mon, 15 Apr 2024 22:30:53 +0200 Subject: [PATCH 06/13] push to re rn jobs --- .github/workflows/create-user-db.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/create-user-db.yml b/.github/workflows/create-user-db.yml index e268c89..c56277b 100644 --- a/.github/workflows/create-user-db.yml +++ b/.github/workflows/create-user-db.yml @@ -1,5 +1,5 @@ -name: Create User DB +name: Create User DB test on: workflow_dispatch: From d32732905cf7253211cdf3f2f38e695ef682d597 Mon Sep 17 00:00:00 2001 From: juliusdw Date: Mon, 15 Apr 2024 22:37:12 +0200 Subject: [PATCH 07/13] button now? --- .github/workflows/create-user-db.yml | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/.github/workflows/create-user-db.yml b/.github/workflows/create-user-db.yml index c56277b..9cadd88 100644 --- a/.github/workflows/create-user-db.yml +++ b/.github/workflows/create-user-db.yml @@ -3,18 +3,11 @@ name: Create User DB test on: workflow_dispatch: + jobs: create-db: runs-on: ubuntu-latest - + steps: - - name: 'auth' - uses: 'google-github-actions/auth@v2' - with: - credentials_json: '${{ secrets.GCP_CREDENTIALS }}' - - name: 'Set up Cloud SDK' - uses: 'google-github-actions/setup-gcloud@v2' - - name: 'Use gcloud CLI' - run: 'gcloud info' - - name: 'Use gcloud CLI to create DB' - run: 'gcloud sql databases create TEST-DB23 --instance=idp-postgres-db --project=code-idp' + - name: hello world + run: echo "Hello World" From 71cd4780ed835a19d50c3d7bd1fae7b540965a2a Mon Sep 17 00:00:00 2001 From: juliusdw Date: Mon, 15 Apr 2024 22:41:00 +0200 Subject: [PATCH 08/13] do we now get the button --- .github/workflows/create-user-db.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/create-user-db.yml b/.github/workflows/create-user-db.yml index 9cadd88..0099717 100644 --- a/.github/workflows/create-user-db.yml +++ b/.github/workflows/create-user-db.yml @@ -1,6 +1,9 @@ name: Create User DB test on: + push: + branches: + - main # remove this line later workflow_dispatch: From 70d905aa10dd4a59e7c4345db8f90b70ce7c7fe7 Mon Sep 17 00:00:00 2001 From: juliusdw Date: Tue, 16 Apr 2024 11:41:32 +0200 Subject: [PATCH 09/13] simple workflow with workflow_dispatch --- .github/workflows/create-user-db.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/create-user-db.yml b/.github/workflows/create-user-db.yml index 0099717..a5ac37f 100644 --- a/.github/workflows/create-user-db.yml +++ b/.github/workflows/create-user-db.yml @@ -1,14 +1,11 @@ -name: Create User DB test +name: Create User DB on: - push: - branches: - - main # remove this line later workflow_dispatch: jobs: - create-db: + placeholder-job: runs-on: ubuntu-latest steps: From 088c838f5c52af6dc6392e40a06b25cd58d23a71 Mon Sep 17 00:00:00 2001 From: juliusdw Date: Mon, 29 Apr 2024 16:00:14 +0200 Subject: [PATCH 10/13] 10 feature add no e2e test script (#11) * add no e2e script * update no e2e test comand --- README.md | 4 ++-- package.json | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e07510c..d1c5a19 100644 --- a/README.md +++ b/README.md @@ -310,5 +310,5 @@ yarn test to run tests without end to end testing run: ```sh -yarn backstage-cli repo test -``` \ No newline at end of file +yarn test:no-e2e +``` diff --git a/package.json b/package.json index 2ec8570..3af2822 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "test": "backstage-cli repo test && playwright test", "test:all": "backstage-cli repo test --coverage", "test:e2e": "playwright test", + "test:no-e2e": "backstage-cli repo test", "fix": "backstage-cli repo fix", "lint": "backstage-cli repo lint --since origin/master", "lint:all": "backstage-cli repo lint", From a00ccd4644bf907978d047e40084932866bfcfd8 Mon Sep 17 00:00:00 2001 From: juliusdw Date: Tue, 30 Apr 2024 18:21:08 +0200 Subject: [PATCH 11/13] FIX: wrong branch name (#14) * ADD: initial mongo db creation action from example * DEL: example code * FIX: wrong branch name --- .github/workflows/create-user-mongo-db.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .github/workflows/create-user-mongo-db.yml diff --git a/.github/workflows/create-user-mongo-db.yml b/.github/workflows/create-user-mongo-db.yml new file mode 100644 index 0000000..0d48e3a --- /dev/null +++ b/.github/workflows/create-user-mongo-db.yml @@ -0,0 +1,10 @@ +name: Create User Mongo DB +on: + push: + branches: + - feat/atlas-mongo-db-gh-action + workflow_dispatch: + inputs: + email: + description: where to send the email + required: true From 7abfdb2beb283c5fdf57e9525b88d4f10ca294d0 Mon Sep 17 00:00:00 2001 From: Menna Tullah Magdy Taha Date: Wed, 8 May 2024 11:36:57 +0200 Subject: [PATCH 12/13] UPD: update initial-deployment.yml template to contain update option in addition to create. UPD: update the initial-deployment.yml template to contain an update option in addition to creating. --- app-config.yaml | 16 ++++--- .../src/templates/initiate-deployment.yaml | 48 +++++++++++++++++++ 2 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 packages/backend/src/templates/initiate-deployment.yaml diff --git a/app-config.yaml b/app-config.yaml index ad0e38e..432bc21 100644 --- a/app-config.yaml +++ b/app-config.yaml @@ -19,8 +19,8 @@ backend: client: pg connection: host: ${POSTGRES_HOST} - port: ${POSTGRES_PORT} - user: ${POSTGRES_USER} + port: ${POSTGRES_PORT} + user: ${POSTGRES_USER} password: ${POSTGRES_PASSWORD} integrations: @@ -35,7 +35,6 @@ techdocs: publisher: type: 'local' # Alternatives - 'googleGcs' or 'awsS3'. Read documentation for using alternatives. - catalog: import: entityFilename: catalog-info.yaml @@ -64,13 +63,18 @@ catalog: rules: - allow: [Template] + - type: file + target: ../../packages/backend/src/templates/initiate-deployment.yaml + rules: + - allow: [Template] + auth: # see https://backstage.io/docs/auth/ to learn about auth providers environment: development - providers: + providers: github: development: - clientId: ${GITHUB_CLIENT_ID} + clientId: ${GITHUB_CLIENT_ID} clientSecret: ${GITHUB_CLIENT_SECRET} kubernetes: @@ -80,7 +84,7 @@ kubernetes: - type: config clusters: - url: ${K8S_URL} - name: "k8s" + name: 'k8s' authProvider: serviceAccount skipTLSVerify: false skipMetricsLookup: true diff --git a/packages/backend/src/templates/initiate-deployment.yaml b/packages/backend/src/templates/initiate-deployment.yaml new file mode 100644 index 0000000..40c09a5 --- /dev/null +++ b/packages/backend/src/templates/initiate-deployment.yaml @@ -0,0 +1,48 @@ +apiVersion: scaffolder.backstage.io/v1beta3 +# https://backstage.io/docs/features/software-catalog/descriptor-format#kind-template +kind: Template +metadata: + name: GKE-cluster + title: Initiate Deployment. + description: Deploy application to google cloud for the first time or update an existing deployment. +spec: + owner: user:guest + type: service + + # These parameters are used to generate the input form in the frontend, and are + # used to gather input data for the execution of the template. + parameters: + - title: Public github repo link to deploy + required: + - repoUrl + properties: + repoUrl: + title: Public github Repo to deploy + description: Provide the github repository link in the following format + pattern: ^https:\/\/github\.com\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-] + type: string + ui:options: + allowedHosts: + - github.com + action: + title: Action + default: create + # Note changing these paramters will lead to not triggering the github actions, it must be create or update. + description: Action to perform (create new deployment for application/Update for updating an already deployed application) + enum: + - create + - update + + # These steps are executed in the scaffolder backend, using data that we gathered + # via the parameters above. + steps: + # Start a github Action to build a GKE cluster with Terraform + - id: github-action + name: Trigger Github Action + action: github:actions:dispatch + input: + workflowId: ${{parameters.action}}-image.yml + repoUrl: 'github.com?repo=idp-hosted-projects&owner=codeuniversity' + branchOrTagName: 'main' + workflowInputs: + githubRepo: ${{ parameters.repoUrl }} From 0793e9a3e325c95347238a1170ce7a301a849ca7 Mon Sep 17 00:00:00 2001 From: Chloe <79200944+AGiljanovic@users.noreply.github.com> Date: Wed, 8 May 2024 11:53:55 +0200 Subject: [PATCH 13/13] Feature/ci workflow --- .github/workflows/ci-workflow.yaml | 95 ++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 .github/workflows/ci-workflow.yaml diff --git a/.github/workflows/ci-workflow.yaml b/.github/workflows/ci-workflow.yaml new file mode 100644 index 0000000..372fd60 --- /dev/null +++ b/.github/workflows/ci-workflow.yaml @@ -0,0 +1,95 @@ +name: CI Workflow + +on: + push: + branches: + - '**' + pull_request: + branches: + - '**' + +jobs: + setup_and_test: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: ['18.x', '20.x'] + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + cache: 'yarn' + + - name: Check Node.js version + run: node -v + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Lint code + run: yarn lint:all + + - name: Build projects + run: yarn build:all + + - name: Test projects + run: yarn test:all + + validate_commit_messages: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Ensure full git history + run: | + if [ -f $(git rev-parse --git-dir)/shallow ]; then + git fetch --prune --unshallow + else + git fetch --prune origin + fi + - name: Validate Commit Messages + run: | + commit_messages=$(git log --format=%B origin/main..HEAD) + echo "Checking commit messages: $commit_messages" + IFS=$'\n' + for message in $commit_messages; do + if [[ "$message" =~ ^Merge ]]; then + echo "Skipping merge commit: $message" + elif ! echo "$message" | grep -Pq '^(ADD:|FIX:|DEL:|UPD:) .+'; then + echo "Invalid commit message: '$message'" + echo "Commit messages must start with ADD:, FIX:, DEL:, or UPD:" + exit 1 + fi + done + echo "All commit messages adhere to the format." + + validate_branch_names: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Validate Branch Names + run: | + if [ "${{ github.event_name }}" == "pull_request" ]; then + if [ -z "${{ github.head_ref }}" ]; then + branch_name=$(echo $GITHUB_REF | sed -n 's/refs\/heads\/\([^/]*\)/\1/p') + echo "Extracted branch name from ref: $branch_name" + else + branch_name=${{ github.head_ref }} + echo "Running in a fork pull request with branch: $branch_name" + fi + else + branch_name=$(git rev-parse --abbrev-ref HEAD) + echo "Current branch: $branch_name" + fi + if ! echo "$branch_name" | grep -Eq '^(main|feature/.+|hotfix/.+)$'; then + echo "Error: Branch name $branch_name does not fit the naming convention." + exit 1 + fi + echo "Branch name fits the naming convention."