Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: [Actions] CodeQL, flake8, black, and regression tests #3

Merged
merged 1 commit into from Oct 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .flake8
@@ -0,0 +1,7 @@
[flake8]
max-line-length = 120
inline-quotes = double

# We use 'black' for coding style; these next two warnings are not PEP-8
# compliant.
ignore = E203, W503
44 changes: 44 additions & 0 deletions .github/workflows/commit-checker.yml
@@ -0,0 +1,44 @@
name: Commit checker

on:
pull_request:

jobs:
commit-checker:
name: Commit checker
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 4

- name: Get pull-request commits
run: |
# actions/checkout did a merge checkout of the pull-request. As such, the first
# commit is the merge commit. This means that on HEAD^ is the base branch, and
# on HEAD^2 are the commits from the pull-request. We now check if those trees
# have a common parent. If not, we fetch a few more commits till we do. In result,
# the log between HEAD^ and HEAD^2 will be the commits in the pull-request.
DEPTH=4
while [ -z "$(git merge-base HEAD^ HEAD^2)" ]; do
git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --deepen=${DEPTH} origin HEAD
DEPTH=$(( ${DEPTH} * 4 ))
done

# Just to show which commits we are going to evaluate.
echo "Commits in this pull-request:"
git log --oneline HEAD^..HEAD^2

- name: Checkout commit-checker
uses: actions/checkout@v2
with:
repository: OpenTTD/OpenTTD-git-hooks
path: git-hooks
ref: master

- name: Check commits
run: |
HOOKS_DIR=./git-hooks/hooks GIT_DIR=.git ./git-hooks/hooks/check-commits.sh HEAD^..HEAD^2
echo "Commit checks passed"
82 changes: 82 additions & 0 deletions .github/workflows/testing.yml
@@ -0,0 +1,82 @@
name: Testing

on:
push:
branches:
- master
pull_request:

jobs:
codeql:
name: Security and Quality
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
# Must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head of the pull request.
fetch-depth: 2
# If this run was triggered by a pull request event then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Install dependencies
run: python -m pip install -e .
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: python
queries: security-and-quality
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1

flake8:
name: Flake8
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Flake8
uses: TrueBrain/actions-flake8@master
with:
path: examples openttd_helpers regression_runner

black:
name: Black
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Black
run: |
python -m pip install --upgrade pip
pip install black
black -l 120 --check examples openttd_helpers regression_runner

regression:
name: Regression
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Set up packages
run: |
python -m pip install --upgrade pip
pip install -e .
pip install -r regression_runner/requirements.txt
- name: Regression
run: |
make regression