From 74db326b55d400af74972e172bcfe02b75d94de8 Mon Sep 17 00:00:00 2001 From: Benjamin Wohlwend Date: Wed, 5 Oct 2022 18:30:34 +0200 Subject: [PATCH] use github actions for pre-commit checks (#1658) * use github actions for pre-commit checks * remove pre-commit run from Jenkins * remove linting CI job * use correct repo and newest version of flake8 thanks @basepi for the heads-up --- .ci/jobs/apm-agent-python-linting-mbp.yml | 44 ------------------ .ci/linting.groovy | 55 ----------------------- .github/workflows/pre-commit.yml | 14 ++++++ .pre-commit-config.yaml | 9 ++-- Jenkinsfile | 29 ------------ 5 files changed, 19 insertions(+), 132 deletions(-) delete mode 100644 .ci/jobs/apm-agent-python-linting-mbp.yml delete mode 100644 .ci/linting.groovy create mode 100644 .github/workflows/pre-commit.yml diff --git a/.ci/jobs/apm-agent-python-linting-mbp.yml b/.ci/jobs/apm-agent-python-linting-mbp.yml deleted file mode 100644 index 731512b0e..000000000 --- a/.ci/jobs/apm-agent-python-linting-mbp.yml +++ /dev/null @@ -1,44 +0,0 @@ ---- -- job: - name: apm-agent-python/apm-agent-python-linting-mbp - display-name: APM Agent Python Linting - description: APM Agent Python Linting - view: APM-CI - project-type: multibranch - concurrent: true - node: linux - script-path: .ci/linting.groovy - scm: - - github: - branch-discovery: no-pr - discover-pr-forks-strategy: merge-current - discover-pr-forks-trust: permission - discover-pr-origin: merge-current - discover-tags: false - notification-context: 'apm-ci/linting' - head-filter-regex: '^PR-.*$' - repo: apm-agent-python - repo-owner: elastic - credentials-id: 2a9602aa-ab9f-4e52-baf3-b71ca88469c7-UserAndToken - ssh-checkout: - credentials: f6c7695a-671e-4f4f-a331-acdce44ff9ba - build-strategies: - - change-request: - ignore-target-only-changes: false - clean: - after: true - before: true - prune: true - shallow-clone: true - depth: 3 - do-not-fetch-tags: true - submodule: - disable: false - recursive: true - parent-credentials: true - timeout: 100 - reference-repo: /var/lib/jenkins/.git-references/apm-agent-python.git - timeout: '15' - use-author: true - wipe-workspace: 'True' - prune-dead-branches: true diff --git a/.ci/linting.groovy b/.ci/linting.groovy deleted file mode 100644 index fd4d0aa7e..000000000 --- a/.ci/linting.groovy +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env groovy -@Library('apm@current') _ - -pipeline { - agent { label 'linux && immutable' } - environment { - BASE_DIR = "src" - HOME = "${env.WORKSPACE}/${env.BASE_DIR}" - } - options { - buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30')) - timestamps() - ansiColor('xterm') - disableResume() - durabilityHint('PERFORMANCE_OPTIMIZED') - rateLimitBuilds(throttle: [count: 60, durationName: 'hour', userBoost: true]) - quietPeriod(10) - } - triggers { - issueCommentTrigger('(?i)(/test).linters.*') - } - stages { - stage('Checkout') { - options { skipDefaultCheckout() } - steps { - runCheckout() - } - } - stage('Sanity checks') { - options { skipDefaultCheckout() } - steps { - dir("${BASE_DIR}") { - runPreCommit() - } - } - } - } -} - -def runCheckout() { - // Use gitCheckout to prepare the context - try { - gitCheckout(basedir: "${BASE_DIR}", githubNotifyFirstTimeContributor: false) - } catch (err) { - // NOOP: avoid failing if non-elasticians, this will avoid issues when PRs comming - // from non elasticians since the validation will not fail - } -} - -def runPreCommit() { - docker.image('python:3.7-stretch').inside(){ - // registry: '' will help to disable the docker login - preCommit(commit: "${GIT_BASE_COMMIT}", junit: true, registry: '') - } -} diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 000000000..c2f7e71fc --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,14 @@ +name: pre-commit + +on: + pull_request: + push: + branches: [main] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - uses: pre-commit/action@v3.0.0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dec850ab6..13e03cc57 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,15 +1,16 @@ repos: - repo: https://github.com/pycqa/isort - rev: 5.7.0 + rev: 5.10.1 hooks: - id: isort - repo: https://github.com/ambv/black - rev: 22.3.0 + rev: 22.8.0 hooks: - id: black language_version: python3 -- repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.4 + exclude: elasticapm\/utils\/wrapt +- repo: https://github.com/PyCQA/flake8 + rev: 5.0.4 hooks: - id: flake8 exclude: elasticapm\/utils\/wrapt|build|src|tests|dist|conftest.py|setup.py diff --git a/Jenkinsfile b/Jenkinsfile index 6e7e3820a..76088b991 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -67,35 +67,6 @@ pipeline { } } } - stage('Sanity checks') { - when { - beforeAgent true - allOf { - expression { return env.ONLY_DOCS == "false" } - anyOf { - not { changeRequest() } - expression { return params.Run_As_Main_Branch } - } - } - } - environment { - PATH = "${env.WORKSPACE}/.local/bin:${env.WORKSPACE}/bin:${env.PATH}" - } - steps { - withGithubNotify(context: 'Sanity checks', tab: 'tests') { - deleteDir() - unstash 'source' - script { - docker.image('python:3.7-stretch').inside(){ - dir("${BASE_DIR}"){ - // registry: '' will help to disable the docker login - preCommit(commit: "${GIT_BASE_COMMIT}", junit: true, registry: '') - } - } - } - } - } - } /** Execute unit tests. */