Skip to content

Commit

Permalink
feat: update CI ad pre-commit configurations
Browse files Browse the repository at this point in the history
Refactor pre-commit hooks to use local entries
and integrate them with Poetry.
Simplify and enhance CI workflow with Poetry caching,
and update the CodeQL workflow to include custom setups.
  • Loading branch information
Septimus4 committed Oct 26, 2024
1 parent 5425e05 commit fd9cb88
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 96 deletions.
9 changes: 0 additions & 9 deletions .pre-commit-config.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Refer to the [Contribution Guidelines](CONTRIBUTING.md) for more details.
- [ ] `poetry run pytest` passes locally with my changes
- [ ] Tests have been added or updated to cover the changes
- [ ] Documentation has been updated as needed
- [ ] Code style checks pass (`poetry run flake8` and `poetry run black --check .`)
- [ ] Code style checks pass
- [ ] Commit messages follow the [Conventional Commits](https://www.conventionalcommits.org/) guidelines

## Affected Components
Expand Down
26 changes: 9 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# .github/workflows/ci.yml
name: CI

on:
Expand All @@ -9,35 +8,28 @@ on:

jobs:
build:

name: Build and Test
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [3.12]
python-version: [ 3.12 ]

steps:
- uses: actions/checkout@v4
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
export PATH="$HOME/.local/bin:$PATH"
- uses: Gr1N/setup-poetry@v9

- name: Install dependencies
run: |
poetry install --no-interaction --no-ansi
run: poetry install

- name: Run linters
run: |
poetry run flake8 concord/
poetry run black --check concord/
- name: Run pre-commit hooks
run: poetry run pre-commit run --all-files --show-diff-on-failure

- name: Run tests
run: |
poetry run pytest --cov=concord tests/
run: poetry run pytest
111 changes: 43 additions & 68 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,84 +1,59 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL Advanced"
name: "CodeQL"

on:
push:
branches: [ "main" ]
branches: [ main ]
pull_request:
branches: [ "main" ]
branches: [ main ]
schedule:
- cron: '33 8 * * 2'
- cron: '35 6 * * 3' # Runs at 06:35 every Wednesday

jobs:
analyze:
name: Analyze (${{ matrix.language }})
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners (GitHub.com only)
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
permissions:
# required for all workflows
security-events: write

# required to fetch internal or private CodeQL packs
packages: read
name: Analyze
runs-on: ubuntu-latest

# only required for workflows in private repositories
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
include:
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
language: [ python ]

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- if: matrix.build-mode == 'manual'
shell: bash
run: |
# TODO setup build command
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
export PATH="$HOME/.local/bin:$PATH"
- name: Cache Poetry Dependencies
uses: actions/cache@v4
with:
path: |
~/.cache/pypoetry
**/site-packages
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}

- name: Install Dependencies
run: poetry install --no-root

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# Add any custom queries if needed
# queries: ./path/to/custom/queries

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
repos:
- repo: local
hooks:
- id: black
name: black
entry: poetry run black
language: system
types: [ python ]
args: [ --check, --diff ]
- id: flake8
name: flake8
entry: poetry run flake8
language: system
types: [ python ]
- id: pytest
name: pytest
entry: poetry run pytest
language: system
pass_filenames: false
Empty file added concord/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions concord/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def main():
return


if __name__ == "__main__":
main()
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.12"


[tool.poetry.group.dev.dependencies]
pytest = "^8.3.3"
flake8 = "^7.1.1"
Expand Down
Empty file added tests/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# tests/test_main.py

from concord.main import main


def test_main():
assert main() is None

0 comments on commit fd9cb88

Please sign in to comment.