From f227c96d435290fb1e80c5e7d2cdea1c21745846 Mon Sep 17 00:00:00 2001 From: Montse Ortega Date: Wed, 13 Nov 2024 11:10:55 +0100 Subject: [PATCH 1/3] Add Github action to validate PRs before merge it to main Signed-off-by: Montse Ortega --- .github/workflows/pull-request.yaml | 67 +++++++++++++++++++++++++++++ apps/demo/package.json | 3 +- yarn.lock | 17 ++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/pull-request.yaml diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml new file mode 100644 index 0000000..70b4521 --- /dev/null +++ b/.github/workflows/pull-request.yaml @@ -0,0 +1,67 @@ +name: Pull request + +on: + pull_request: + types: + - opened + - reopened + - synchronize + - ready_for_review + branches: + - main + - releases/* + +env: + NODE_OPTIONS: '--max-old-space-size=8192' + # See https://github.com/cypress-io/cypress/issues/25357 + ELECTRON_EXTRA_LAUNCH_ARGS: --disable-gpu +jobs: + preflight-check: + # Prevents running the workflow when a PR is marked as draft. + runs-on: ubuntu-latest + outputs: + skip: ${{ steps.check.outputs.skip }} + steps: + - uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Enable Corepack + run: | + corepack enable + corepack prepare yarn@4.5.0 --activate + + - name: Check if PR is draft + id: check + run: | + if [[ "${{ github.event.pull_request.draft }}" == "true" ]]; then + skip=true + else + skip=false + fi + echo "skip=${skip}" >> $GITHUB_OUTPUT + echo "skip=${skip}" + lint-and-build: + needs: preflight-check + if: needs.preflight-check.outputs.skip == 'false' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Enable Corepack + run: | + corepack enable + corepack prepare yarn@4.5.0 --activate + + - run: yarn install --immutable + - run: yarn all:lint + - run: yarn all:build + diff --git a/apps/demo/package.json b/apps/demo/package.json index d575be8..f298b61 100644 --- a/apps/demo/package.json +++ b/apps/demo/package.json @@ -32,6 +32,7 @@ "react-use": "^17.5.1" }, "devDependencies": { - "@types/humanize-plus": "^1" + "@types/humanize-plus": "^1", + "@types/node": "^22.9.0" } } diff --git a/yarn.lock b/yarn.lock index c1ae585..df777dd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1401,6 +1401,15 @@ __metadata: languageName: node linkType: hard +"@types/node@npm:^22.9.0": + version: 22.9.0 + resolution: "@types/node@npm:22.9.0" + dependencies: + undici-types: "npm:~6.19.8" + checksum: 10c0/3f46cbe0a49bab4ba30494025e4c8a6e699b98ac922857aa1f0209ce11a1313ee46e6808b8f13fe5b8b960a9d7796b77c8d542ad4e9810e85ef897d5593b5d51 + languageName: node + linkType: hard + "@types/parse-json@npm:^4.0.0": version: 4.0.2 resolution: "@types/parse-json@npm:4.0.2" @@ -2511,6 +2520,7 @@ __metadata: "@patternfly/react-table": "npm:^5.4.0" "@redhat-cloud-services/frontend-components": "npm:^4.2.13" "@types/humanize-plus": "npm:^1" + "@types/node": "npm:^22.9.0" dotenv: "npm:^16.4.5" humanize-plus: "npm:^1.8.2" lodash: "npm:^4.17.21" @@ -6262,6 +6272,13 @@ __metadata: languageName: node linkType: hard +"undici-types@npm:~6.19.8": + version: 6.19.8 + resolution: "undici-types@npm:6.19.8" + checksum: 10c0/078afa5990fba110f6824823ace86073b4638f1d5112ee26e790155f481f2a868cc3e0615505b6f4282bdf74a3d8caad715fd809e870c2bb0704e3ea6082f344 + languageName: node + linkType: hard + "unique-filename@npm:^3.0.0": version: 3.0.0 resolution: "unique-filename@npm:3.0.0" From 9ed7e1856d3acc2ca4b9c0bfac425caef22fb88e Mon Sep 17 00:00:00 2001 From: Montse Ortega Date: Wed, 13 Nov 2024 11:25:02 +0100 Subject: [PATCH 2/3] Solving lint problems Signed-off-by: Montse Ortega --- .github/workflows/pull-request.yaml | 3 ++- apps/demo/src/common/version.ts | 3 ++- .../sources-table/empty-state/DiscoverySourceSetupModal.tsx | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index 70b4521..3f4da84 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -45,6 +45,7 @@ jobs: echo "skip=${skip}" >> $GITHUB_OUTPUT echo "skip=${skip}" lint-and-build: + # Execute lint and build when a PR is ready needs: preflight-check if: needs.preflight-check.outputs.skip == 'false' runs-on: ubuntu-latest @@ -60,7 +61,7 @@ jobs: run: | corepack enable corepack prepare yarn@4.5.0 --activate - + - run: yarn install --immutable - run: yarn all:lint - run: yarn all:build diff --git a/apps/demo/src/common/version.ts b/apps/demo/src/common/version.ts index f17b9c6..6c4cc07 100644 --- a/apps/demo/src/common/version.ts +++ b/apps/demo/src/common/version.ts @@ -4,7 +4,8 @@ import buildManifest from 'demo/package.json'; * The function returns the build-time generated version. * It can be overriden via the MIGRATION_PLANNER_UI_VERSION environment variable. */ +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export const getMigrationPlannerUiVersion = () => { - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return + return process.env.MIGRATION_PLANNER_UI_VERSION || buildManifest.version; }; \ No newline at end of file diff --git a/apps/demo/src/migration-wizard/steps/connect/sources-table/empty-state/DiscoverySourceSetupModal.tsx b/apps/demo/src/migration-wizard/steps/connect/sources-table/empty-state/DiscoverySourceSetupModal.tsx index ddd6b8e..3a27764 100644 --- a/apps/demo/src/migration-wizard/steps/connect/sources-table/empty-state/DiscoverySourceSetupModal.tsx +++ b/apps/demo/src/migration-wizard/steps/connect/sources-table/empty-state/DiscoverySourceSetupModal.tsx @@ -20,6 +20,7 @@ import * as Yup from 'yup'; const SSH_PUBLIC_KEY_REGEX = /^(ssh-rsa AAAAB3NzaC1yc2|ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNT|ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzOD|ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1Mj|ssh-ed25519 AAAAC3NzaC1lZDI1NTE5|ssh-dss AAAAB3NzaC1kc3)[0-9A-Za-z+/]+[=]{0,3}( .*)?$/; +// eslint-disable-next-line react-refresh/only-export-components, @typescript-eslint/explicit-function-return-type export const trimSshPublicKey = (key: string) => key .split('\n') @@ -28,6 +29,7 @@ export const trimSshPublicKey = (key: string) => .join('\n'); // Define your validation schema +// eslint-disable-next-line react-refresh/only-export-components export const sshPublicKeyValidationSchema = Yup.string().test( 'ssh-public-key', 'SSH public key must consist of "[TYPE] key [[EMAIL]]", supported types are: ssh-rsa, ssh-ed25519, ecdsa-[VARIANT]. A single key can be provided only.', @@ -56,6 +58,7 @@ export const DiscoverySourceSetupModal: React.FC const [sshKeyErrorMessage, setSshKeyErrorMessage] = useState(""); // Validate SSH key when it changes + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type const handleSshKeyChange = async (event: React.ChangeEvent) => { const value = event.target.value; setSshKey(value); From 21a282b6cc3766503295c71582f96de0b64b1a70 Mon Sep 17 00:00:00 2001 From: Montse Ortega Date: Wed, 13 Nov 2024 11:34:57 +0100 Subject: [PATCH 3/3] Order of checks in PR Signed-off-by: Montse Ortega --- .github/workflows/pull-request.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index 3f4da84..9bdae6d 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -17,7 +17,7 @@ env: ELECTRON_EXTRA_LAUNCH_ARGS: --disable-gpu jobs: preflight-check: - # Prevents running the workflow when a PR is marked as draft. + # Prevents running the workflow when a PR is marked as draft. runs-on: ubuntu-latest outputs: skip: ${{ steps.check.outputs.skip }} @@ -44,6 +44,7 @@ jobs: fi echo "skip=${skip}" >> $GITHUB_OUTPUT echo "skip=${skip}" + lint-and-build: # Execute lint and build when a PR is ready needs: preflight-check