add auto-format-code (#1142)

* add auto-format-code
* add github remote
* add GITHUB_TOKEN to the remove url
* select Yunohost:dev
* force push as it's only a code format
* pull before running black
* working on a clean directory
* pull before push? /o\
* do not clone single branch
* a last one?
* only on dev branch
This commit is contained in:
Kayou 2021-01-23 00:21:02 +01:00 committed by GitHub
parent 75ebadfcff
commit 4a302dc786
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

View file

@ -24,4 +24,24 @@ format-check:
needs: []
allow_failure: true
script:
- tox -e py37-black
- tox -e py37-black-check
format-run:
stage: lint
image: "before-install"
needs: []
before_script:
- apt-get update -y && apt-get install git hub -y
- git config --global user.email "yunohost@yunohost.org"
- git config --global user.name "$GITHUB_USER"
- hub clone --branch ${CI_COMMIT_REF_NAME} "https://$GITHUB_TOKEN:x-oauth-basic@github.com/YunoHost/yunohost.git" github_repo
- cd github_repo
script:
# checkout or create and checkout the branch
- hub checkout "ci-format-${CI_COMMIT_REF_NAME}" || hub checkout -b "ci-format-${CI_COMMIT_REF_NAME}"
- tox -e py37-black-run
- hub commit -am "[CI] Format code" || true
- hub pull-request -m "[CI] Format code" -b Yunohost:dev -p || true # GITHUB_USER and GITHUB_TOKEN registered here https://gitlab.com/yunohost/yunohost/-/settings/ci_cd
only:
refs:
- dev

View file

@ -1,12 +1,13 @@
[tox]
envlist = py37-{lint,invalidcode},py37-black
envlist = py37-{lint,invalidcode},py37-black-{run,check}
[testenv]
skip_install=True
deps =
py37-{lint,invalidcode}: flake8
py37-black: black
py37-black-{run,check}: black
commands =
py37-lint: flake8 src doc data tests --ignore E402,E501 --exclude src/yunohost/vendor
py37-invalidcode: flake8 src data --exclude src/yunohost/tests,src/yunohost/vendor --select F
py37-black: black --check --diff src doc data tests
py37-black-check: black --check --diff src doc data tests
py37-black-run: black src doc data tests