Skip to content

Commit

Permalink
Migrate from CircleCI to GitHubActions
Browse files Browse the repository at this point in the history
Reasons:
* lots of random failures in CircleCI
* logging/auth issues with CircleCI
* contributors don't have to leave GitHub when helping out with the project
  • Loading branch information
zupo committed Mar 23, 2023
1 parent 14c7b66 commit 0c38ece
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 41 deletions.
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

23 changes: 23 additions & 0 deletions .github/actions/nix-shell/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Prepare nix-shell"
description:
Download cache, build nix-shell and potentially upload any new
derivations to cache

inputs:
cachix_auth_token:
required: true

runs:
using: "composite"
steps:
- uses: cachix/install-nix-action@v20
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: cachix/cachix-action@v12
with:
name: pyramid-openapi3
authToken: '${{ inputs.cachix_auth_token }}'

- name: Build nix-shell
shell: bash
run: nix-shell --run "echo 'nix-shell successfully entered'"
62 changes: 62 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Run all tests, linters, code analysis and other QA tasks on
# every push to master and PRs.

name: CI

on:
workflow_dispatch:
pull_request:
push:
branches:
- main

# To SSH into the runner to debug a failure, add the following step before
# the failing step
# - uses: lhotari/action-upterm@v1
# with:
# limit-access-to-actor: true

# Prevent multiple jobs running after fast subsequent pushes
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:

test_310:
name: "Python 3.10 Tests"

runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/nix-shell
with:
cachix_auth_token: '${{ secrets.CACHIX_AUTH_TOKEN }}'

- name: Run linters and unit tests
run: |
nix-shell --run "make lint all=true"
nix-shell --run "make types"
nix-shell --run "make unit"
- name: Run tests for the singlefile example
run: |
cd examples/singlefile
nix-shell --run "python -m unittest app.py"
- name: Run tests for the todoapp example
run: |
cd examples/todoapp
nix-shell --run "python -m unittest tests.py"
- name: Run tests for the splitfile example
run: |
cd examples/splitfile
nix-shell --run "python -m unittest tests.py"
- name: Save coverage report
uses: actions/upload-artifact@v3
with:
name: htmlcov
path: htmlcov
26 changes: 17 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,69 @@ repos:
- id: isort
name: isort
description: A Python utility that sorts imports alphabetically.
entry: poetry run isort
entry: isort
language: system
types: [python]

- id: autoflake
name: autoflake
description: Removes unused imports and unused variables from Python code.
entry: poetry run autoflake
entry: autoflake
language: system
types: [python]

- id: flake8
name: Flake8
description: Python Style Guide Enforcement.
entry: poetry run flake8 --config .flake8
entry: flake8 --config .flake8
language: system
types: [python]

- id: black
name: Black
description: Uncompromising Python code formatter.
entry: poetry run black
entry: black
language: system
types: [python]

- id: trailing-whitespace
name: Trim Trailing Space
entry: poetry run trailing-whitespace-fixer
entry: trailing-whitespace-fixer
language: system
types: [file, text]

- id: end-of-file-fixer
name: Fix end of Files
description: Ensures that a file is either empty, or ends with one newline.
entry: poetry run end-of-file-fixer
entry: end-of-file-fixer
language: system
types: [file, text]

- id: check-merge-conflict
name: Check for merge conflicts
description: Check for files that contain merge conflict strings.
entry: poetry run check-merge-conflict
entry: check-merge-conflict
language: system
types: [file, text]

- id: codespell
name: Check Spelling
description: Checks for common misspellings in text files.
entry: poetry run codespell --ignore-words .aspell.en.pws
entry: codespell --ignore-words .aspell.en.pws
language: system
types: [file, text]

- id: yamllint
name: yamllint
description: Lint YAML files.
entry: poetry run yamllint
entry: yamllint
language: system
types: [yaml]

- id: nixpkg-fmt
name: Format *.nix
description: Format nix files.
entry: nixpkgs-fmt
language: system
files: .*\.nix
types: [non-executable, file, text]
17 changes: 9 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ lock:
@poetry lock --no-update
@rm -rf .venv/
@nix-shell --run true
@direnv reload

# Testing and linting targets
all = false
Expand All @@ -22,23 +23,23 @@ lint:
# 3. get all untracked files
# 4. run pre-commit checks on them
ifeq ($(all),true)
@poetry run pre-commit run --hook-stage push --all-files
@pre-commit run --hook-stage push --all-files
else
@{ git diff --name-only ./; git diff --name-only --staged ./;git ls-files --other --exclude-standard; } \
| sort -u | uniq | poetry run xargs pre-commit run --hook-stage push --files
| sort -u | uniq | xargs pre-commit run --hook-stage push --files
endif

.PHONY: type
type: types

.PHONY: types
types: .
@poetry run mypy examples/todoapp
@mypy examples/todoapp
@cat ./typecov/linecount.txt
@poetry run typecov 100 ./typecov/linecount.txt
@poetry run mypy pyramid_openapi3
@typecov 100 ./typecov/linecount.txt
@mypy pyramid_openapi3
@cat ./typecov/linecount.txt
@poetry run typecov 100 ./typecov/linecount.txt
@typecov 100 ./typecov/linecount.txt


# anything, in regex-speak
Expand Down Expand Up @@ -70,9 +71,9 @@ endif
.PHONY: unit
unit:
ifndef path
@poetry run pytest pyramid_openapi3 $(verbosity) $(full_suite_args) $(pytest_args)
@pytest pyramid_openapi3 $(verbosity) $(full_suite_args) $(pytest_args)
else
@poetry run pytest $(path)
@pytest $(path)
endif

.PHONY: test
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ The authors of pyramid_openapi3 believe that the approach of validating a manual

## Running tests

You need to have [poetry](https://python-poetry.org/) and Python 3.7 through 3.11 installed on your machine.
You need to have [poetry](https://python-poetry.org/) and Python 3.7 through 3.11 installed on your machine. All `Makefile` commands assume you have the Poetry environment activated, i.e. `poetry shell`.

Alternatively, if you use [nix](https://nix.dev/tutorials/declarative-and-reproducible-developer-environments), run `nix-shell` to drop into a shell that has everything prepared for development.

Expand Down
1 change: 1 addition & 0 deletions examples/singlefile/shell.nix
1 change: 1 addition & 0 deletions examples/splitfile/shell.nix
1 change: 1 addition & 0 deletions examples/todoapp/shell.nix
23 changes: 12 additions & 11 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ let
nixpkgs = builtins.fetchTarball {
# https://github.com/NixOS/nixpkgs/tree/nixos-22.11 on 2022-11-29
url = "https://github.com/nixos/nixpkgs/archive/ce5fe99df1f15a09a91a86be9738d68fadfbad82.tar.gz";
sha256 = "1zqyq7v1gxrg2b7zizf4npask4vqbs4s7khwffxafgm20gxngb6a";
sha256 = "1zqyq7v1gxrg2b7zizf4npask4vqbs4s7khwffxafgm20gxngb6a";
};
poetry2nixsrc = builtins.fetchTarball {
# https://github.com/nix-community/poetry2nix/commits/master on 2022-11-29
url = "https://github.com/nix-community/poetry2nix/archive/ce8425ccc2884c1065927a38d1700024f431cf0f.tar.gz";
sha256 = "07x48abw18qfxdmsz8hdd762vj8n5l2syh9xm40v851bhidbjswc";
sha256 = "07x48abw18qfxdmsz8hdd762vj8n5l2syh9xm40v851bhidbjswc";
};

# Fix for installing PasteDeploy from https://github.com/nix-community/poetry2nix/issues/750
Expand All @@ -19,9 +19,9 @@ let
pastedeploy_ = super.pastedeploy;
};
postDefaults = self: super: {
# Avoid infinite recursion
pastedeploy = super.pastedeploy_;
};
# Avoid infinite recursion
pastedeploy = super.pastedeploy_;
};

pkgs = import nixpkgs { };
poetry2nix = import poetry2nixsrc {
Expand Down Expand Up @@ -125,8 +125,8 @@ let
old: {
buildInputs = (old.buildInputs or [ ]) ++ [ self.hatchling ];
postInstall = ''
rm -f $out/lib/python3*/site-packages/LICENSE
'';
rm -f $out/lib/python3*/site-packages/LICENSE
'';
}
);
});
Expand All @@ -138,8 +138,9 @@ pkgs.mkShell {
name = "dev-shell";

buildInputs = with pkgs; [
devEnv
poetry
gitAndTools.pre-commit
];
devEnv
poetry
gitAndTools.pre-commit
nixpkgs-fmt
];
}
22 changes: 11 additions & 11 deletions shell_py37.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ let
nixpkgs = builtins.fetchTarball {
# https://github.com/NixOS/nixpkgs/tree/nixos-22.11 on 2022-11-29
url = "https://github.com/nixos/nixpkgs/archive/ce5fe99df1f15a09a91a86be9738d68fadfbad82.tar.gz";
sha256 = "1zqyq7v1gxrg2b7zizf4npask4vqbs4s7khwffxafgm20gxngb6a";
sha256 = "1zqyq7v1gxrg2b7zizf4npask4vqbs4s7khwffxafgm20gxngb6a";
};
poetry2nixsrc = builtins.fetchTarball {
# https://github.com/nix-community/poetry2nix/commits/master on 2022-11-29
url = "https://github.com/nix-community/poetry2nix/archive/ce8425ccc2884c1065927a38d1700024f431cf0f.tar.gz";
sha256 = "07x48abw18qfxdmsz8hdd762vj8n5l2syh9xm40v851bhidbjswc";
sha256 = "07x48abw18qfxdmsz8hdd762vj8n5l2syh9xm40v851bhidbjswc";
};

# Fix for installing PasteDeploy from https://github.com/nix-community/poetry2nix/issues/750
Expand All @@ -19,9 +19,9 @@ let
pastedeploy_ = super.pastedeploy;
};
postDefaults = self: super: {
# Avoid infinite recursion
pastedeploy = super.pastedeploy_;
};
# Avoid infinite recursion
pastedeploy = super.pastedeploy_;
};

pkgs = import nixpkgs { };
poetry2nix = import poetry2nixsrc {
Expand Down Expand Up @@ -125,8 +125,8 @@ let
old: {
buildInputs = (old.buildInputs or [ ]) ++ [ self.hatchling ];
postInstall = ''
rm -f $out/lib/python3*/site-packages/LICENSE
'';
rm -f $out/lib/python3*/site-packages/LICENSE
'';
}
);
});
Expand All @@ -138,8 +138,8 @@ pkgs.mkShell {
name = "dev-shell";

buildInputs = with pkgs; [
devEnv
poetry
gitAndTools.pre-commit
];
devEnv
poetry
gitAndTools.pre-commit
];
}

0 comments on commit 0c38ece

Please sign in to comment.