-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate GH Action CI automatically (#6)
* add ci feat * clean * clean
- Loading branch information
Showing
7 changed files
with
256 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
name: CI | ||
|
||
on: | ||
pull_request: # Start the job on all PRs | ||
branches: [master, main] | ||
types: [synchronize, opened, reopened, ready_for_review] | ||
push: # Start the job on all main branch push | ||
branches: [master, main] | ||
|
||
jobs: | ||
precommit: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Cache pip dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-pip- | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
- name: Cache shfmt binary | ||
uses: actions/cache@v3 | ||
with: | ||
path: /usr/local/bin/shfmt | ||
# key: ${{ runner.os }}-shfmt-${{ env.SHFMT_VERSION }} | ||
key: ${{ runner.os }}-shfmt- | ||
restore-keys: | | ||
${{ runner.os }}-shfmt- | ||
- name: Cache Pre-Commit environments | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.cache/pre-commit | ||
# key: ${{ runner.os }}-pc-${{ hashFiles('.pre-commit-config.yaml') }} | ||
key: ${{ runner.os }}-pc- | ||
restore-keys: | | ||
${{ runner.os }}-pc- | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install pre-commit | ||
pre-commit install | ||
- name: Install shfmt | ||
run: | | ||
SHFMT_VERSION="v3.7.0" | ||
SHFMT_BIN="shfmt_${SHFMT_VERSION}_linux_amd64" | ||
if [[ ! -f /usr/local/bin/shfmt ]]; then | ||
wget -O shfmt "https://github.com/mvdan/sh/releases/download/${SHFMT_VERSION}/${SHFMT_BIN}" | ||
chmod +x shfmt | ||
sudo mv shfmt /usr/local/bin/ | ||
fi | ||
sudo apt-get install shellcheck | ||
- name: Run pre-commits | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
REPO_NAME=$(echo $GITHUB_REPOSITORY | sed 's/^.*\///') | ||
DEFAULT_BRANCH=$(curl -H "Authorization: token $GITHUB_TOKEN" \ | ||
"https://api.github.com/repos/$GITHUB_REPOSITORY" | jq -r '.default_branch') | ||
git fetch | ||
CUR_SHA=$(git log --pretty=tformat:"%H" -n1 . | tail -n1) | ||
echo "Default branch is $DEFAULT_BRANCH" | ||
echo "Current SHA is $CUR_SHA" | ||
if [[ $GITHUB_REF == "refs/heads/$DEFAULT_BRANCH" ]]; then | ||
pre-commit run --all | ||
else | ||
pre-commit run --from-ref origin/$DEFAULT_BRANCH --to-ref $CUR_SHA | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
[tool.poetry] | ||
name = "example" | ||
version = "0.0.1" | ||
description = "" | ||
authors = [ | ||
"My Name <[email protected]>" | ||
] | ||
license = "" | ||
|
||
[build-system] | ||
requires = ["poetry-core>=1.7.0"] | ||
build-backend = "poetry.core.masonry.api" | ||
|
||
[tool.black] | ||
line-length = 120 | ||
skip-string-normalization = false | ||
target-version = ['py310'] | ||
include = '\.pyi?$' | ||
exclude = ''' | ||
/( | ||
\.eggs | ||
| \.git | ||
| \.hg | ||
| \.mypy_cache | ||
| \.tox | ||
| \.venv | ||
| _build | ||
| buck-out | ||
| build | ||
| dist | ||
)/ | ||
''' | ||
color = true | ||
|
||
[tool.isort] | ||
balanced_wrapping = true | ||
include_trailing_comma = true | ||
known_first_party = "example" | ||
known_third_party = [ | ||
"boto3", # Common for AWS | ||
"django", # Common web framework, if used | ||
"flask", # Common web framework, if used | ||
"jinja2", # Common templating engine | ||
"matplotlib", # Common for plotting | ||
"numpy", # Common for numerical operations | ||
"pandas", # Common for data manipulation | ||
"pendulum", # Common for date time | ||
"pytest", # Common for testing | ||
"requests", # Common for HTTP requests | ||
"sqlalchemy", # Common ORM for databases | ||
] | ||
multi_line_output = 3 | ||
profile = "black" | ||
line_length = 120 | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.10" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
pre-commit = ">=3.5.0" | ||
pytest = "^7.3.1" | ||
pytest-cov = "^4.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
max_width = 120 | ||
imports_granularity = "Crate" | ||
group_imports = "StdExternalCrate" | ||
imports_layout = "Horizontal" | ||
|
||
comment_width = 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
{% raw %} | ||
name: CI | ||
|
||
on: | ||
pull_request: # Start the job on all PRs | ||
branches: [master, main] | ||
types: [synchronize, opened, reopened, ready_for_review] | ||
push: # Start the job on all main branch push | ||
branches: [master, main] | ||
|
||
jobs: | ||
precommit: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Cache pip dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-pip- | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
- name: Cache shfmt binary | ||
uses: actions/cache@v3 | ||
with: | ||
path: /usr/local/bin/shfmt | ||
# key: ${{ runner.os }}-shfmt-${{ env.SHFMT_VERSION }} | ||
key: ${{ runner.os }}-shfmt- | ||
restore-keys: | | ||
${{ runner.os }}-shfmt- | ||
- name: Cache Pre-Commit environments | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.cache/pre-commit | ||
# key: ${{ runner.os }}-pc-${{ hashFiles('.pre-commit-config.yaml') }} | ||
key: ${{ runner.os }}-pc- | ||
restore-keys: | | ||
${{ runner.os }}-pc- | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install pre-commit | ||
pre-commit install | ||
- name: Install shfmt | ||
run: | | ||
SHFMT_VERSION="v3.7.0" | ||
SHFMT_BIN="shfmt_${SHFMT_VERSION}_linux_amd64" | ||
if [[ ! -f /usr/local/bin/shfmt ]]; then | ||
wget -O shfmt "https://github.com/mvdan/sh/releases/download/${SHFMT_VERSION}/${SHFMT_BIN}" | ||
chmod +x shfmt | ||
sudo mv shfmt /usr/local/bin/ | ||
fi | ||
sudo apt-get install shellcheck | ||
- name: Run pre-commits | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
REPO_NAME=$(echo $GITHUB_REPOSITORY | sed 's/^.*\///') | ||
DEFAULT_BRANCH=$(curl -H "Authorization: token $GITHUB_TOKEN" \ | ||
"https://api.github.com/repos/$GITHUB_REPOSITORY" | jq -r '.default_branch') | ||
git fetch | ||
CUR_SHA=$(git log --pretty=tformat:"%H" -n1 . | tail -n1) | ||
echo "Default branch is $DEFAULT_BRANCH" | ||
echo "Current SHA is $CUR_SHA" | ||
if [[ $GITHUB_REF == "refs/heads/$DEFAULT_BRANCH" ]]; then | ||
pre-commit run --all | ||
else | ||
pre-commit run --from-ref origin/$DEFAULT_BRANCH --to-ref $CUR_SHA | ||
fi | ||
{% endraw %} |