Skip to content

Commit

Permalink
ECOPROJECT-2327: Add Github action to validate PRs before merge it to…
Browse files Browse the repository at this point in the history
… main (#40)

* Add Github action to validate PRs before merge it to main

Signed-off-by: Montse Ortega <[email protected]>

* Solving lint problems

Signed-off-by: Montse Ortega <[email protected]>

* Order of checks in PR

Signed-off-by: Montse Ortega <[email protected]>

---------

Signed-off-by: Montse Ortega <[email protected]>
  • Loading branch information
ammont82 authored Nov 13, 2024
1 parent 95b5737 commit f8ff6f1
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 2 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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 [email protected] --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:
# Execute lint and build when a PR is ready
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 [email protected] --activate
- run: yarn install --immutable
- run: yarn all:lint
- run: yarn all:build

3 changes: 2 additions & 1 deletion apps/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"react-use": "^17.5.1"
},
"devDependencies": {
"@types/humanize-plus": "^1"
"@types/humanize-plus": "^1",
"@types/node": "^22.9.0"
}
}
3 changes: 2 additions & 1 deletion apps/demo/src/common/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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.',
Expand Down Expand Up @@ -56,6 +58,7 @@ export const DiscoverySourceSetupModal: React.FC<DiscoverySourceSetupModalProps>
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<HTMLTextAreaElement>) => {
const value = event.target.value;
setSshKey(value);
Expand Down
17 changes: 17 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit f8ff6f1

Please sign in to comment.