Skip to content

Commit

Permalink
improve CI linter
Browse files Browse the repository at this point in the history
Signed-off-by: Eric <[email protected]>
  • Loading branch information
mengweieric committed Dec 21, 2023
1 parent febe215 commit 775dd54
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Lint
name: Linter

on: [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,7 @@ jobs:
- name: Checkout dashboards observability
uses: actions/checkout@v2
with:
path: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}
path: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}

- name: Get node and yarn versions
working-directory: ${{ env.WORKING_DIR }}
Expand All @@ -35,7 +35,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 +44,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=d origin/main | grep -E "\.(js|ts|tsx)$")) || true
if [ -n "$CHANGED_FILES" ]; then
CHANGED_FILES="${{ steps.files.outputs.changed }}"
if [[ -n "$CHANGED_FILES" && "$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 matching files changed."
fi
echo "No matching files to lint."
fi
working-directory: OpenSearch-Dashboards/plugins/${{ env.PLUGIN_NAME }}

0 comments on commit 775dd54

Please sign in to comment.