diff --git a/.github/workflows/eslint.yml b/.github/workflows/eslint.yml index 95c619969c..38954d9028 100644 --- a/.github/workflows/eslint.yml +++ b/.github/workflows/eslint.yml @@ -11,42 +11,40 @@ name: ESLint on: pull_request: - branches: - - 'master' - - '[345].[0-9]+' # Minor branches - - '[345].[0-9]+.[0-9]+' # Patch branches - - '[345].[0-9]+.[0-9]+-7.[0-9]+' # Minor branches - Kibana jobs: - eslint: - name: Run eslint scanning + linter: + name: Ensure the code format on the changed files runs-on: ubuntu-latest - permissions: - contents: read - security-events: write - actions: read - steps: - # https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs - name: Checkout code uses: actions/checkout@v3 # - https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#node-version-file - - name: Install ESLint + - name: Install NodeJS uses: actions/setup-node@v3 with: node-version-file: '.nvmrc' - - run: yarn - - name: Run ESLint - run: yarn lint >> eslint-results.log - continue-on-error: true - - # https://github.com/marketplace/actions/upload-a-build-artifact - - name: Upload analysis results to GitHub - uses: actions/upload-artifact@v3 - with: - name: eslint-results - path: eslint-results.log - retention-days: 5 + - name: Verify the changed files + run: | + REMOTE_NAME=origin + echo "Base ref: $GITHUB_BASE_REF" + echo "Head ref: $GITHUB_HEAD_REF" + echo "Fetching branch: $GITHUB_BASE_REF" + git fetch origin $GITHUB_BASE_REF + echo "Fetching branch: $GITHUB_HEAD_REF" + git fetch origin $GITHUB_HEAD_REF + echo "Listing branches" + git branch -a + echo "Getting diff files ignoring deleted and getting the changed or renamed files" + CHANGED_FILES=$(git diff --name-status --diff-filter d ${REMOTE_NAME}/${GITHUB_BASE_REF}..${REMOTE_NAME}/${GITHUB_HEAD_REF} | awk '{print $2}') + echo "Changed files:" + echo "${CHANGED_FILES}" + git checkout $GITHUB_HEAD_REF + plugin_package_json=$(ls -d plugins/* | head -n1) + echo "Installing dependencies from plugin: ${plugin_package_json}" + yarn --cwd "${plugin_package_json}" --modules-folder ../../node_modules + echo "Running eslint on the changed files" + npx eslint ${CHANGED_FILES} diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml new file mode 100644 index 0000000000..9c1748cd4b --- /dev/null +++ b/.github/workflows/prettier.yml @@ -0,0 +1,41 @@ +name: Prettier + +on: + pull_request: + +jobs: + prettier: + name: Ensure the code format on the changed files + runs-on: ubuntu-latest + steps: + # https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs + - name: Checkout code + uses: actions/checkout@v3 + + # - https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#node-version-file + - name: Install NodeJS + uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + + - name: Verify the changed files + run: | + REMOTE_NAME=origin + echo "Base ref: $GITHUB_BASE_REF" + echo "Head ref: $GITHUB_HEAD_REF" + echo "Fetching branch: $GITHUB_BASE_REF" + git fetch origin $GITHUB_BASE_REF + echo "Fetching branch: $GITHUB_HEAD_REF" + git fetch origin $GITHUB_HEAD_REF + echo "Listing branches" + git branch -a + echo "Getting diff files ignoring deleted and getting the changed or renamed files" + CHANGED_FILES=$(git diff --name-status --diff-filter d ${REMOTE_NAME}/${GITHUB_BASE_REF}..${REMOTE_NAME}/${GITHUB_HEAD_REF} | awk '{print $2}') + echo "Changed files:" + echo "${CHANGED_FILES}" + git checkout $GITHUB_HEAD_REF + plugin_package_json=$(ls -d plugins/* | head -n1) + echo "Installing dependencies from plugin: ${plugin_package_json}" + yarn --cwd "${plugin_package_json}" --modules-folder ../../node_modules + echo "Running prettier on the changed files" + npx prettier ${CHANGED_FILES} --check --ignore-unknown