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

Refactoring #190

Merged
merged 34 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
457e818
Switch to Poetry for dependency management
Sep 18, 2024
0a5a8f8
Update container configuration with registry credentials
Sep 18, 2024
cfbf42b
Fix syntax error in GitHub Actions build.yml
Sep 18, 2024
b65bfcf
Format Dockerfile and clean up temporary files
Sep 18, 2024
119e791
Update test commands for poetry to use 'python -m pytest'
Sep 18, 2024
6613156
Add concurrency settings to GitHub Actions workflows
Sep 18, 2024
f444db9
Adjust workflow triggers to include 'main' and 'develop' branches.
Sep 18, 2024
9526df9
Switch workflows to self-hosted runners
Sep 18, 2024
20dd3a9
Add paths filter for workflows
Sep 18, 2024
2e89ce4
Rename workflow for better clarity
Sep 18, 2024
160ae0d
Upgrade grpcio-tools and protobuf versions
Sep 18, 2024
f7d30fd
Merge remote-tracking branch 'origin/develop' into refactoring
Sep 18, 2024
84d9ba2
Update commands to use 'python -m' with Poetry
Sep 18, 2024
98d8c69
Merge remote-tracking branch 'origin/develop' into refactoring
Sep 18, 2024
198b52d
Update Dockerfile with concise ENV syntax and robust unzipping
Sep 18, 2024
492495f
Merge remote-tracking branch 'origin/develop' into refactoring
Sep 18, 2024
4091610
Update Go version and fix unzip commands in Dockerfile
Sep 18, 2024
7dfa6ef
Update Docker base image and Go module dependencies
Sep 18, 2024
55559e2
Update URLs for epicbox-go dependencies
Sep 18, 2024
4a40ffb
Update Python version in Dockerfile to 3.12.5
Sep 18, 2024
f093fae
Update Python version to 3.12.5
Sep 18, 2024
ceec850
Update dependencies and remove obsolete packages
Sep 18, 2024
c0fd7a4
Merge remote-tracking branch 'origin/develop' into refactoring
Sep 18, 2024
e319b7d
Add linters to .dockerignore
Sep 18, 2024
057f173
Update Python version in base image to 3.11.9
Sep 18, 2024
18c35bf
Update dependencies in pyproject.toml
Sep 18, 2024
72adb02
Update wps-light to version 0.15.3
Sep 19, 2024
480bd61
Update Dockerfile CMD to run all pytest tests by default
Sep 19, 2024
f3e4dcf
Downgrade Python to version 3.10.14
Sep 19, 2024
379046a
Update default Python version in build_base_image.yml
Sep 19, 2024
a8b40a0
Add directory change before running tests
Sep 19, 2024
f9ecb30
Refactor build workflow for consistency
Sep 19, 2024
736ef08
Update test command in GitHub Actions workflow
Sep 19, 2024
8a51697
Use sys.executable and refactor Dockerfile for venv
Sep 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ venv
build
**/*.egg-info
**/model_pb2*
linters
118 changes: 66 additions & 52 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,83 +1,97 @@
name: Python build

on: [ push, pull_request ]
on:
push:
branches:
- main
- develop
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build_image:
name: Build Image
runs-on: [ self-hosted, small ]
steps:
- uses: actions/checkout@v4

build:
runs-on: ubuntu-latest
# Consistent with base image in Dockerfile
# container: stepik/hyperstyle-base:py3.8.11-java11.0.11-node14.17.3-go1.18.5
container: nastyabirillo/hyperstyle:1.4.4
- uses: docker/login-action@v3
with:
registry: hyperskill.azurecr.io
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}

- uses: docker/setup-buildx-action@v3

- name: Build and push server image
uses: docker/build-push-action@v6
with:
context: .
pull: true
push: true
tags: hyperskill.azurecr.io/hyperstyle:${{ github.sha }}
cache-from: |
type=gha
type=gha,scope=main
cache-to: type=gha,mode=max

tests:
name: Tests
needs:
- build_image
runs-on: [ self-hosted, small ]
container:
image: hyperskill.azurecr.io/hyperstyle:${{ github.sha }}
credentials:
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
steps:
- name: Install git
- name: Run tests
run: |
apt-get update
apt-get -y install git
cd /review
/hyperstyle/bin/pytest

build:
runs-on: [ self-hosted, small ]
needs:
- build_image
container:
image: hyperskill.azurecr.io/hyperstyle:${{ github.sha }}
credentials:
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
steps:
- name: Check env variables
run: |
echo $DETEKT_DIRECTORY && echo $DETEKT_VERSION
echo $CHECKSTYLE_DIRECTORY && echo $CHECKSTYLE_VERSION
echo $PMD_DIRECTORY && echo $PMD_VERSION
echo $GOLANG_LINT_DIRECTORY && echo $GOLANG_LINT_VERSION

- name: Checkout
uses: actions/checkout@v3

- name: Install development requirements
run: |
pip install --no-cache-dir -r requirements-dev.txt

- name: Install the tool
run: |
pip install --no-cache-dir . --use-feature=in-tree-build

- name: Set up git rights
run: |
git config --global --add safe.directory '*'

- name: Lint with flake8
run: |
cd /review
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=.git,__pycache__,docs/source/conf.py,old,build,dist,venv,test/resources,.eggs,review.egg-info,.pytest_cache,node_modules,hyperstyle/src/python/review/inspectors/common/inspector/proto
/hyperstyle/bin/flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=.git,__pycache__,docs/source/conf.py,old,build,dist,venv,test/resources,.eggs,review.egg-info,.pytest_cache,node_modules,hyperstyle/src/python/review/inspectors/common/inspector/proto

# TODO: change max-complexity into 10 after refactoring
# TODO: remove R504, A003, E800, E402, WPS1, WPS2, WPS3, WPS4, WPS5, WPS6, H601
flake8 . --count --max-complexity=11 --max-line-length=120 --max-doc-length=120 --ignore=R504,A003,E800,E402,W503,WPS,H601,N400,I100,I201,I202, --statistics --exclude=.git,__pycache__,docs/source/conf.py,old,build,dist,venv,test/resources,.eggs,review.egg-info,.pytest_cache,node_modules,hyperstyle/src/python/review/inspectors/common/inspector/proto


- name: Sort whitelists
run: |
for file in "whitelist.txt" "hyperstyle/src/python/review/inspectors/flake8/whitelist.txt"
do
LC_ALL=C sort $file -o $file
done

- name: Commit sorted whitelists
uses: EndBug/add-and-commit@v7.2.1
with:
add: "['whitelist.txt', 'hyperstyle/src/python/review/inspectors/flake8/whitelist.txt']"
message: 'Sort whitelists (Github Actions)'

- name: Set up Eslint
run: |
# Consistent with eslint version in Dockerfile
npm install eslint@7.5.0 -g && eslint --init
/hyperstyle/bin/flake8 . --count --max-complexity=11 --max-line-length=120 --max-doc-length=120 --ignore=R504,A003,E800,E402,W503,WPS,H601,N400,I100,I201,I202, --statistics --exclude=.git,__pycache__,docs/source/conf.py,old,build,dist,venv,test/resources,.eggs,review.egg-info,.pytest_cache,node_modules,hyperstyle/src/python/review/inspectors/common/inspector/proto

- name: Check installed module can run python linters
run: |
review test/resources/inspectors/python/case39_no_issues.py
cd /review
/hyperstyle/bin/python -m hyperstyle.src.python.review.run_tool test/resources/inspectors/python/case39_no_issues.py

- name: Check installed module can run java linters
run: |
review test/resources/inspectors/java/test_algorithm_with_scanner.java
cd /review
/hyperstyle/bin/python -m hyperstyle.src.python.review.run_tool test/resources/inspectors/java/test_algorithm_with_scanner.java

- name: Check installed module can run js linters
run: |
review test/resources/inspectors/js/case0_no_issues.js

- name: Test with pytest
run: |
pytest -vv
cd /review
/hyperstyle/bin/python -m hyperstyle.src.python.review.run_tool test/resources/inspectors/js/case0_no_issues.js
2 changes: 1 addition & 1 deletion .github/workflows/build_base_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
type: string
description: 'Image tag'
required: true
default: 'py3.12.5-java11.0.11-node14.17.3-go1.18.5'
default: 'py3.10.14-java11.0.11-node14.17.3-go1.18.5'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/build_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build Image after Release

on:
workflow_dispatch:
inputs:
image_tag:
description: 'Image tag'
required: true
default: 'latest'
release:
types:
- released

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
build_image:
name: Build Image
runs-on: [ self-hosted, small ]
steps:
- uses: actions/checkout@v4

- uses: docker/login-action@v3
with:
registry: hyperskill.azurecr.io
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}

- uses: docker/setup-buildx-action@v3

- name: Build and push server image
uses: docker/build-push-action@v6
with:
context: .
pull: true
push: true
tags: hyperskill.azurecr.io/hyperstyle:${{ inputs.image_tag || github.event.release.tag_name }}
cache-from: |
type=gha
type=gha,scope=main
cache-to: type=gha,mode=max
16 changes: 10 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
# Publish to PyPI in case of releasing
name: Publish to PyPI in case of releasing

on:
push:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI
runs-on: ubuntu-latest
runs-on: [ self-hosted, small ]

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version-file: .python-version
- name: Install pypa/build
run: |
python -m pip install build --user
Expand All @@ -24,4 +28,4 @@ jobs:
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.SECRETS_TEST_PYPI_API_TOKEN }}
password: ${{ secrets.SECRETS_TEST_PYPI_API_TOKEN }}
39 changes: 39 additions & 0 deletions .github/workflows/sort_whitespaces.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Sort whitespaces

on:
push:
branches:
- main
- develop
paths:
- 'whitelist.txt'
- 'hyperstyle/src/python/review/inspectors/flake8/whitelist.txt'
pull_request:
paths:
- 'whitelist.txt'
- 'hyperstyle/src/python/review/inspectors/flake8/whitelist.txt'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
sort_whitespaces:
name: Sort whitespaces
runs-on: [ self-hosted, small ]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Sort whitelists
run: |
for file in "whitelist.txt" "hyperstyle/src/python/review/inspectors/flake8/whitelist.txt"
do
LC_ALL=C sort $file -o $file
done

- name: Commit sorted whitelists
uses: EndBug/add-and-commit@v7.2.1
with:
add: "['whitelist.txt', 'hyperstyle/src/python/review/inspectors/flake8/whitelist.txt']"
message: 'Sort whitelists (Github Actions)'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ __pycache__/
/.intellij_inspector/out/

lightweight.Dockerfile
linters

node_modules
.eslintrc.js
package-lock.json

hyperstyle/src/python/review/inspectors/common/inspector/proto/model_pb2*
.env
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10.14
Loading
Loading