From 08baf48dcbef6fe0027bfe0e1805cc8996403991 Mon Sep 17 00:00:00 2001 From: hiento09 <136591877+hiento09@users.noreply.github.com> Date: Mon, 8 Apr 2024 21:56:01 +0700 Subject: [PATCH] Feature playwright integrate report portal (#2648) * Add make script for report portual playwright agent config * Update workflow to report to report portal --------- Co-authored-by: Hien To --- .../jan-electron-linter-and-test.yml | 77 ++++++++++++++++++- Makefile | 64 +++++++++++++++ electron/package.json | 3 +- 3 files changed, 140 insertions(+), 4 deletions(-) diff --git a/.github/workflows/jan-electron-linter-and-test.yml b/.github/workflows/jan-electron-linter-and-test.yml index 033b75c395..44eca87d5d 100644 --- a/.github/workflows/jan-electron-linter-and-test.yml +++ b/.github/workflows/jan-electron-linter-and-test.yml @@ -38,11 +38,13 @@ on: jobs: test-on-macos: - if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository + if: github.event.pull_request.head.repo.full_name == github.repository runs-on: [self-hosted, macOS, macos-desktop] steps: - name: Getting the repo uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Installing node uses: actions/setup-node@v3 @@ -54,6 +56,22 @@ jobs: run: | make clean + - name: Get Commit Message for PR + if : github.event_name == 'pull_request' + run: | + MSG=$(git log --format=%B -n 1 ${{github.event.after}}) + echo "COMMIT_MESSAGE=${MSG}" >> $GITHUB_ENV + + - name: Get Commit Message for push event + if : github.event_name == 'push' + run: | + MSG=$(git log --format=%B -n 1 ${{github.sha}}) + echo "COMMIT_MESSAGE=${MSG}" >> $GITHUB_ENV + + - name: "Config report portal" + run: | + make update-playwright-config REPORT_PORTAL_URL=${{ secrets.REPORT_PORTAL_URL }} REPORT_PORTAL_API_KEY=${{ secrets.REPORT_PORTAL_API_KEY }} REPORT_PORTAL_PROJECT_NAME=${{ secrets.REPORT_PORTAL_PROJECT_NAME }} REPORT_PORTAL_LAUNCH_NAME="Jan App macos" REPORT_PORTAL_DESCRIPTION="${{env.COMMIT_MESSAGE}}" + - name: Linter and test run: | npm config set registry ${{ secrets.NPM_PROXY }} --global @@ -71,6 +89,8 @@ jobs: steps: - name: Getting the repo uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Installing node uses: actions/setup-node@v3 @@ -100,6 +120,8 @@ jobs: steps: - name: Getting the repo uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Installing node uses: actions/setup-node@v3 @@ -112,6 +134,18 @@ jobs: continue-on-error: true run: | make clean + + - name: Get Commit Message for push event + if : github.event_name == 'push' + shell: bash + run: | + MSG=$(git log --format=%B -n 1 ${{github.sha}}) + echo "COMMIT_MESSAGE=${MSG}" >> $GITHUB_ENV + + - name: "Config report portal" + shell: bash + run: | + make update-playwright-config REPORT_PORTAL_URL=${{ secrets.REPORT_PORTAL_URL }} REPORT_PORTAL_API_KEY=${{ secrets.REPORT_PORTAL_API_KEY }} REPORT_PORTAL_PROJECT_NAME=${{ secrets.REPORT_PORTAL_PROJECT_NAME }} REPORT_PORTAL_LAUNCH_NAME="Jan App Windows ${{ matrix.antivirus-tools }}" REPORT_PORTAL_DESCRIPTION="${{env.COMMIT_MESSAGE}}" - name: Linter and test shell: powershell @@ -129,6 +163,8 @@ jobs: steps: - name: Getting the repo uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Installing node uses: actions/setup-node@v1 @@ -142,6 +178,18 @@ jobs: run: | make clean + - name: Get Commit Message for PR + if : github.event_name == 'pull_request' + shell: bash + run: | + MSG=$(git log --format=%B -n 1 ${{github.event.after}}) + echo "COMMIT_MESSAGE=${MSG}" >> $GITHUB_ENV + + - name: "Config report portal" + shell: bash + run: | + make update-playwright-config REPORT_PORTAL_URL=${{ secrets.REPORT_PORTAL_URL }} REPORT_PORTAL_API_KEY=${{ secrets.REPORT_PORTAL_API_KEY }} REPORT_PORTAL_PROJECT_NAME=${{ secrets.REPORT_PORTAL_PROJECT_NAME }} REPORT_PORTAL_LAUNCH_NAME="Jan App Windows" REPORT_PORTAL_DESCRIPTION="${{env.COMMIT_MESSAGE}}" + - name: Linter and test shell: powershell run: | @@ -159,6 +207,8 @@ jobs: steps: - name: Getting the repo uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Installing node uses: actions/setup-node@v1 @@ -182,10 +232,12 @@ jobs: test-on-ubuntu: runs-on: [self-hosted, Linux, ubuntu-desktop] - if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository + if: github.event.pull_request.head.repo.full_name == github.repository steps: - name: Getting the repo uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Installing node uses: actions/setup-node@v3 @@ -196,7 +248,24 @@ jobs: continue-on-error: true run: | make clean - + + - name: Get Commit Message for PR + if : github.event_name == 'pull_request' + run: | + MSG=$(git log --format=%B -n 1 ${{github.event.after}}) + echo "COMMIT_MESSAGE=${MSG}" >> $GITHUB_ENV + + - name: Get Commit Message for push event + if : github.event_name == 'push' + run: | + MSG=$(git log --format=%B -n 1 ${{github.sha}}) + echo "COMMIT_MESSAGE=${MSG}" >> $GITHUB_ENV + + - name: "Config report portal" + shell: bash + run: | + make update-playwright-config REPORT_PORTAL_URL=${{ secrets.REPORT_PORTAL_URL }} REPORT_PORTAL_API_KEY=${{ secrets.REPORT_PORTAL_API_KEY }} REPORT_PORTAL_PROJECT_NAME=${{ secrets.REPORT_PORTAL_PROJECT_NAME }} REPORT_PORTAL_LAUNCH_NAME="Jan App Linux" REPORT_PORTAL_DESCRIPTION="${{env.COMMIT_MESSAGE}}" + - name: Linter and test run: | export DISPLAY=$(w -h | awk 'NR==1 {print $2}') @@ -215,6 +284,8 @@ jobs: steps: - name: Getting the repo uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Installing node uses: actions/setup-node@v3 diff --git a/Makefile b/Makefile index 79f33f5283..a05f14c511 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,11 @@ # Makefile for Jan Electron App - Build, Lint, Test, and Clean +REPORT_PORTAL_URL ?= "" +REPORT_PORTAL_API_KEY ?= "" +REPORT_PORTAL_PROJECT_NAME ?= "" +REPORT_PORTAL_LAUNCH_NAME ?= "Jan App" +REPORT_PORTAL_DESCRIPTION ?= "Jan App report" + # Default target, does nothing all: @echo "Specify a target to run" @@ -37,6 +43,64 @@ dev: check-file-counts lint: check-file-counts yarn lint +update-playwright-config: +ifeq ($(OS),Windows_NT) + echo -e "const RPconfig = {\n\ + apiKey: '$(REPORT_PORTAL_API_KEY)',\n\ + endpoint: '$(REPORT_PORTAL_URL)',\n\ + project: '$(REPORT_PORTAL_PROJECT_NAME)',\n\ + launch: '$(REPORT_PORTAL_LAUNCH_NAME)',\n\ + attributes: [\n\ + {\n\ + key: 'key',\n\ + value: 'value',\n\ + },\n\ + {\n\ + value: 'value',\n\ + },\n\ + ],\n\ + description: '$(REPORT_PORTAL_DESCRIPTION)',\n\ + }\n$$(cat electron/playwright.config.ts)" > electron/playwright.config.ts; + sed -i "s/^ reporter: .*/ reporter: [['@reportportal\/agent-js-playwright', RPconfig]],/" electron/playwright.config.ts + +else ifeq ($(shell uname -s),Linux) + echo "const RPconfig = {\n\ + apiKey: '$(REPORT_PORTAL_API_KEY)',\n\ + endpoint: '$(REPORT_PORTAL_URL)',\n\ + project: '$(REPORT_PORTAL_PROJECT_NAME)',\n\ + launch: '$(REPORT_PORTAL_LAUNCH_NAME)',\n\ + attributes: [\n\ + {\n\ + key: 'key',\n\ + value: 'value',\n\ + },\n\ + {\n\ + value: 'value',\n\ + },\n\ + ],\n\ + description: '$(REPORT_PORTAL_DESCRIPTION)',\n\ + }\n$$(cat electron/playwright.config.ts)" > electron/playwright.config.ts; + sed -i "s/^ reporter: .*/ reporter: [['@reportportal\/agent-js-playwright', RPconfig]],/" electron/playwright.config.ts +else + echo "const RPconfig = {\n\ + apiKey: '$(REPORT_PORTAL_API_KEY)',\n\ + endpoint: '$(REPORT_PORTAL_URL)',\n\ + project: '$(REPORT_PORTAL_PROJECT_NAME)',\n\ + launch: '$(REPORT_PORTAL_LAUNCH_NAME)',\n\ + attributes: [\n\ + {\n\ + key: 'key',\n\ + value: 'value',\n\ + },\n\ + {\n\ + value: 'value',\n\ + },\n\ + ],\n\ + description: '$(REPORT_PORTAL_DESCRIPTION)',\n\ + }\n$$(cat electron/playwright.config.ts)" > electron/playwright.config.ts; + sed -i '' "s|^ reporter: .*| reporter: [['@reportportal\/agent-js-playwright', RPconfig]],|" electron/playwright.config.ts +endif + # Testing test: lint yarn build:test diff --git a/electron/package.json b/electron/package.json index 2210fb0cfb..e76b9172ae 100644 --- a/electron/package.json +++ b/electron/package.json @@ -108,7 +108,8 @@ "eslint-plugin-react": "^7.34.0", "rimraf": "^5.0.5", "run-script-os": "^1.1.6", - "typescript": "^5.3.3" + "typescript": "^5.3.3", + "@reportportal/agent-js-playwright": "^5.1.7" }, "installConfig": { "hoistingLimits": "workspaces"