-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore/auto formatting workflow (#109)
This PR adds a new GitHub workflow. Purpose of that is, for every commit to either of the branches master or develop as well as any commit pushed to a branch that is in a PR with a base branch of either master or develop the new workflow should run and automatically apply code formatting with black, import sorting with isort as well as update the README.tex.md (porting changes over from README.md). --------- Co-authored-by: Pietropaolo Frisoni <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
fa1a433
commit 9f771bc
Showing
18 changed files
with
145 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: AutoUpdateFormatting | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- develop | ||
pull_request: | ||
branches: | ||
- master | ||
- develop | ||
|
||
jobs: | ||
code-formatting: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.10' # Specify the desired Python version | ||
|
||
- name: Install dependencies | ||
run: | | ||
pip install -r requirements_test.txt | ||
- name: Updating README files | ||
id: update_readme | ||
run: | | ||
bash scripts/update-readme.sh | ||
bash scripts/auto-commit.sh "Updating README files" | ||
continue-on-error: true | ||
|
||
- name: Code formatting and committing changes | ||
id: code_format | ||
run: | | ||
bash scripts/auto-format.sh | ||
bash scripts/auto-commit.sh "Automated formatting changes" | ||
continue-on-error: true | ||
|
||
- name: Push changes | ||
if: ${{ steps.update_readme.outcome == 'success' || steps.code_format.outcome == 'success' }} | ||
uses: ad-m/github-push-action@master | ||
with: | ||
branch: ${{ github.head_ref }} |
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
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
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
black==23.1.0 | ||
black | ||
mypy | ||
isort | ||
jupyter | ||
|
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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
pytest>=7.3.2 | ||
black | ||
mypy | ||
isort | ||
pylint |
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,25 @@ | ||
#!/bin/bash | ||
|
||
echo "Running auto commit" | ||
|
||
COMMITMSG=$1 | ||
|
||
if [ -z "$COMMITMSG" ]; then | ||
COMMITMSG="Automated formatting changes" | ||
fi | ||
|
||
# Stage changes | ||
git add --update | ||
|
||
# Check Git diff-index | ||
git diff-index --quiet HEAD -- | ||
|
||
if [ $? -eq 0 ]; then | ||
echo "No changes found, nothing to see/do here." | ||
exit 1 | ||
else | ||
echo "Changes found. Preparing commit." | ||
git config --local user.email "github-actions[bot]@users.noreply.github.com" | ||
git config --local user.name "github-actions[bot]" | ||
git commit -m "${COMMITMSG}" | ||
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,6 @@ | ||
#!/bin/bash | ||
|
||
# Code formatting with isort and black | ||
echo "Code formatting with isort and black:" | ||
isort $(git ls-files '*.py') | ||
black $(git ls-files '*.py') |
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,43 @@ | ||
#!/bin/bash | ||
|
||
update_version_readme() { | ||
local version_file="version" | ||
local readme_md="$1" | ||
|
||
# Read the current version from the "version" file | ||
local current_version=$(grep -Eo 'version=([0-9]+\.){2}[0-9]+' "$version_file" | cut -d'=' -f2) | ||
|
||
update_file() { | ||
local file=$1 | ||
sed -i "s/pypi-v[0-9]\+\.[0-9]\+\.[0-9]\+/pypi-v$current_version/" "$file" | ||
echo "Version updated to $current_version in $file" | ||
} | ||
|
||
# Update version in README.md | ||
update_file "$readme_md" | ||
} | ||
|
||
update_readme_tex() { | ||
local file_path="$1" | ||
|
||
# Copy README.md to README.tex.md | ||
cp README.md "$file_path" | ||
|
||
# Read the contents of README.tex.md | ||
local content=$(<"$file_path") | ||
|
||
# Replace patterns | ||
content=$(echo "$content" | sed -E "s/<img src=\"(.*?)\" align=middle width=194.52263655pt height=46.976899200000005pt\/>/\$\\\\displaystyle\\\\dfrac{\\\\text{price}_{t_i} - \\\\text{price}_{t_0} + \\\\text{dividend}}{\\\\text{price}_{t_0}}\$/") | ||
|
||
content=$(echo "$content" | sed -E "s/<img src=\"(.*?)\" align=middle width=126.07712039999997pt height=48.84266309999997pt\/>/\$\\\\displaystyle\\\\dfrac{\\\\text{price}_{t_i} - \\\\text{price}_{t_{i-1}}}{\\\\text{price}_{t_{i-1}}}\$/") | ||
|
||
content=$(echo "$content" | sed -E "s/<img src=\"(.*?)\" align=middle width=208.3327686pt height=57.53473439999999pt\/>/\$\\\\displaystyle\\\\log\\\\left(1 + \\\\dfrac{\\\\text{price}_{t_i} - \\\\text{price}_{t_{i-1}}}{\\\\text{price}_{t_{i-1}}}\\\\right)\$/") | ||
|
||
# Write the updated contents back to README.tex.md | ||
echo "$content" > "$file_path" | ||
} | ||
|
||
# Update both readme files: | ||
echo "Updating README files:" | ||
update_version_readme "README.md" | ||
update_readme_tex "README.tex.md" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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