LoginSignup
3
2

More than 3 years have passed since last update.

GitLab CIでPythonコードの静的解析

Last updated at Posted at 2020-05-23

GitLab CIを使ってPythonコードの静的解析を行ったのでメモです。微妙に簡単な導入記事が見つからなかったので誰かのお役に立てれば。

目的

  • GitLabはSaaS版、つまりWebブラウザ版をつかう
  • しかも無課金
  • Python
  • とりあえずコードの静的解析さえできればいい
  • 無料ではグループあたり2000分/月なのでマージリクエスト発行時だけをトリガーにする

ymlファイル作成

ルートディレクトリに .gitlab-ci.yml を作成します。

.gitlab-ci.yml
# Docker Imageを指定
image: python:latest

# キャッシュの保存先
variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"

# pip installしたものをキャッシュするためにvirtualenvを導入
cache:
  paths:
    - .cache/pip
    - venv/

# 実行前スクリプト
before_script:
  - python -V
  - pip install virtualenv
  - virtualenv venv
  - source venv/bin/activate

# testというstageを使う
# 長さが79文字以下はちょっといやだったので無視
test:
  script:
    # - python setup.py test
    - pip install flake8
    - flake8 *.py --exclude venv/,.cache --ignore E501
  only:
    refs:
      - merge_requests

実行

このファイルが含まれたマージリクエストを作成してください。くるくるテストが回り始めます。テストに通るとマージできるようになります。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2