Skip to content

Commit

Permalink
[CI/CD] Add eslint workflow (#316)
Browse files Browse the repository at this point in the history
* Add eslint workflow

Signed-off-by: Ryan Liang <[email protected]>

* Correct the plugin name

Signed-off-by: Ryan Liang <[email protected]>

* Correct the plugin name2

Signed-off-by: Ryan Liang <[email protected]>

* change the linting running dir

Signed-off-by: Ryan Liang <[email protected]>

* Fix some comments

Signed-off-by: Ryan Liang <[email protected]>

* Add stylelint back

Signed-off-by: Ryan Liang <[email protected]>

---------

Signed-off-by: Ryan Liang <[email protected]>
  • Loading branch information
RyanL1997 authored Jan 16, 2024
1 parent d1551b7 commit 09ef7f9
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 10 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Lint

on: [pull_request]

env:
PLUGIN_NAME: dashboards-visualizations
OPENSEARCH_DASHBOARDS_VERSION: "main"

jobs:
build:
name: Lint
runs-on: ubuntu-latest

steps:
- name: Checkout Plugin
uses: actions/checkout@v2

- name: Checkout OpenSearch Dashboards
uses: actions/checkout@v2
with:
repository: opensearch-project/Opensearch-Dashboards
ref: ${{ env.OPENSEARCH_DASHBOARDS_VERSION }}
path: OpenSearch-Dashboards

- name: Install Gantt Chart to Opensearch Dashboards Plugins Dir
run: |
mv gantt-chart ./OpenSearch-Dashboards/plugins
- name: Get node and yarn versions
working-directory: ${{ env.WORKING_DIR }}
id: versions_step
run: |
echo "::set-output name=node_version::$(cat ./OpenSearch-Dashboards/.nvmrc | cut -d"." -f1)"
echo "::set-output name=yarn_version::$(node -p "(require('./OpenSearch-Dashboards/package.json').engines.yarn).match(/[.0-9]+/)[0]")"
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: ${{ steps.versions_step.outputs.node_version }}
registry-url: "https://registry.npmjs.org"

- name: Install correct yarn version for OpenSearch Dashboards
run: |
npm uninstall -g yarn
echo "Installing yarn ${{ steps.versions_step.outputs.yarn_version }}"
npm i -g yarn@${{ steps.versions_step.outputs.yarn_version }}
- name: Bootstrap the plugin
working-directory: OpenSearch-Dashboards/plugins/gantt-chart
run: yarn osd bootstrap

- name: Get list of changed files using GitHub Action
uses: lots0logs/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Check Changes of Files
run: |
echo "FILES_MODIFIED=$(cat ${HOME}/files_modified.json)"
echo "FILES_ADDED=$(cat ${HOME}/files_added.json)"
echo "FILES_RENAMED=$(cat ${HOME}/files_renamed.json)"
echo "FILES_DELETED=$(cat ${HOME}/files_deleted.json)"
- name: Lint Changed Files
run: |
jq -r '.[]' ${HOME}/files_modified.json ${HOME}/files_added.json | sort | uniq > /tmp/changed_files.txt
CHANGED_FILES=$(cat /tmp/changed_files.txt)
echo "These are the changed files: $CHANGED_FILES"
if [[ -n "$CHANGED_FILES" ]]; then
echo "Linting changed files..."
while IFS= read -r file; do
if [[ $file =~ ^gantt-chart/.+\.(js|ts|tsx)$ ]]; then
echo "linting file $file"
yarn lint "../$file"
fi
done < /tmp/changed_files.txt
else
echo "No matched files to lint."
fi
working-directory: OpenSearch-Dashboards/plugins/gantt-chart
17 changes: 17 additions & 0 deletions gantt-chart/.cypress/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
root: true,
extends: ['plugin:cypress/recommended'],
env: {
'cypress/globals': true,
},
plugins: ['cypress'],
rules: {
// Add cypress specific rules here
'cypress/no-assigning-return-values': 'error',
'cypress/no-unnecessary-waiting': 'error',
'cypress/assertion-before-screenshot': 'warn',
'cypress/no-force': 'warn',
'cypress/no-async-tests': 'error',
},
};

7 changes: 7 additions & 0 deletions gantt-chart/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
/data
/build
/target
/.eslintrc.js
/cypress.config.js
!.cypress/
59 changes: 59 additions & 0 deletions gantt-chart/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

const LICENSE_HEADER = `/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/`;

module.exports = {
root: true,
extends: [
'@elastic/eslint-config-kibana',
'plugin:@elastic/eui/recommended',
'plugin:react-hooks/recommended',
'plugin:jest/recommended',
'plugin:prettier/recommended',
],

rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
'@osd/eslint/no-restricted-paths': [
'error',
{
basePath: __dirname,
zones: [
{
target: ['(public|server)/**/*'],
from: ['../../packages/**/*','packages/**/*'],
},
],
},
],
},
overrides: [
{
files: ['**/*.{js,ts,tsx}'],
rules: {
'@typescript-eslint/no-explicit-any': 'warn',
'no-console': 0,
'@osd/eslint/require-license-header': [
'error',
{
licenses: [LICENSE_HEADER],
},
],
},
},
],
"ignorePatterns": ["**/*.d.ts"]
};
9 changes: 0 additions & 9 deletions gantt-chart/.eslintrc.yaml

This file was deleted.

3 changes: 2 additions & 1 deletion gantt-chart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"scripts": {
"osd": "node ../../scripts/osd",
"opensearch": "node ../../scripts/opensearch",
"lint": "eslint .",
"lint:style": "node ../../scripts/stylelint",
"lint:es": "node ../../scripts/eslint",
"lint": "yarn lint:es",
"build": "yarn plugin-helpers build",
"plugin-helpers": "node ../../scripts/plugin_helpers",
"test": "../../node_modules/.bin/jest --config ./test/jest.config.js",
Expand Down

0 comments on commit 09ef7f9

Please sign in to comment.