Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix no matching issue corner case for lint CI #1317

Merged
merged 5 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check warning on line 1 in .eslintrc.js

View workflow job for this annotation

GitHub Actions / Lint

File ignored by default.
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -14,10 +14,9 @@
'@elastic/eslint-config-kibana',
'plugin:@elastic/eui/recommended',
'plugin:react-hooks/recommended',
"eslint:recommended",
"plugin:cypress/recommended",
"plugin:import/recommended",
"prettier"
'plugin:jest/recommended',
'plugin:prettier/recommended',
],
env: {
'cypress/globals': true,
Expand All @@ -26,6 +25,14 @@
'cypress',
],
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 🔥

varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
'@osd/eslint/no-restricted-paths': [
'error',
{
Expand All @@ -49,6 +56,7 @@
{
files: ['**/*.{js,ts,tsx}'],
rules: {
'@typescript-eslint/no-explicit-any': 'warn',
'no-console': 0,
'@osd/eslint/require-license-header': [
'error',
Expand Down
39 changes: 25 additions & 14 deletions .github/workflows/lint.yml
mengweieric marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Lint

on: [push, pull_request]
on: [pull_request]

env:
PLUGIN_NAME: dashboards-observability
OPENSEARCH_DASHBOARDS_VERSION: 'main'
OPENSEARCH_DASHBOARDS_VERSION: "main"

jobs:
build:
Expand All @@ -22,7 +22,8 @@ jobs:
- name: Checkout dashboards observability
uses: actions/checkout@v2
with:
path: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
path: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
fetch-depth: 0

- name: Get node and yarn versions
working-directory: ${{ env.WORKING_DIR }}
Expand All @@ -35,7 +36,7 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: ${{ steps.versions_step.outputs.node_version }}
registry-url: 'https://registry.npmjs.org'
registry-url: "https://registry.npmjs.org"

- name: Install correct yarn version for OpenSearch Dashboards
run: |
Expand All @@ -44,18 +45,28 @@ jobs:
npm i -g yarn@${{ steps.versions_step.outputs.yarn_version }}

- name: Bootstrap the plugin
working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
run:
yarn osd bootstrap
working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
run: yarn osd bootstrap

- name: lint code base
- name: Get list of changed files
id: files
run: |
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
git fetch origin $BASE_SHA
git diff --name-only $BASE_SHA...$HEAD_SHA > changed_files.txt
CHANGED_FILES=$(cat changed_files.txt | grep -E '\.(js|ts|tsx)$' || true)
echo "::set-output name=changed::${CHANGED_FILES}"
working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}

- name: Lint Changed Files
run: |
git fetch origin main
CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRTUXB origin/main | grep -E "\.(js|ts|tsx)$")
if [ -n "$CHANGED_FILES" ]; then
CHANGED_FILES="${{ steps.files.outputs.changed }}"
if [[ -n "$CHANGED_FILES" ]]; then
echo "Linting changed files..."
yarn lint $CHANGED_FILES
IFS=$'\n' read -r -a FILES_TO_LINT <<< "$CHANGED_FILES"
yarn lint "${FILES_TO_LINT[@]}"
else
echo "No JavaScript/TypeScript files changed."
fi
echo "No matched files to lint."
fi
working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
Loading