Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kiyoon committed Jul 2, 2024
0 parents commit 2ff4731
Show file tree
Hide file tree
Showing 19 changed files with 1,286 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/apply-ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Apply ruff format, isort, and fixes

on:
workflow_call:
inputs:
ruff-select:
description: 'ruff select'
default: I,D20,D21,UP00,UP032,UP034
type: string
ruff-ignore:
description: 'ruff ignore'
default: D212
type: string
ruff-version-file:
description: The requirements.txt file that contains the Ruff version (ruff==x.x.x)
required: true
type: string

jobs:
apply-ruff:
name: Apply ruff
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install ruff
run: |
pip3 install -r <(grep '^ruff==' "${{ inputs.ruff-version-file }}")
- name: Run ruff and push
run: |
# It will exit on ruff failure
ruff check --select=${{ inputs.ruff-select }} --ignore=${{ inputs.ruff-ignore }} --fix --unsafe-fixes .
ruff format .
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git add .
git commit -m "style: ruff format, isort, fixes [skip ci]"
git push
46 changes: 46 additions & 0 deletions .github/workflows/check-cargo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Cargo style checking

on:
workflow_call:
inputs:
check-type:
description: fmt, clippy
default: lint
type: string
working-directory:
description: Rust project root
default: rust
type: string

jobs:
check-cargo:
name: check-cargo
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run clippy
run: |
set +e # Do not exit shell on ruff failure
cd ${{ inputs.working-directory }}
if [[ "${{ inputs.check-type }}" == "clippy" ]]; then
out=$(cargo clippy --all-targets --all-features -- -D warnings 2> app_stderr.txt)
elif [[ "${{ inputs.check-type }}" == "fmt" ]]; then
out=$(cargo fmt --all -- --check 2> app_stderr.txt)
else
echo "Invalid check-type: ${{ inputs.check-type }}"
exit 1
fi
exit_code=$?
err=$(<app_stderr.txt)
# Display the raw output in the step
echo "${out}"
echo "${err}"
# Display the Markdown output in the job summary
{ echo "\`\`\`rust"; echo "${out}"; echo "${err}"; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY"
# Exit with the exit-code returned by ruff
exit ${exit_code}
101 changes: 101 additions & 0 deletions .github/workflows/check-ruff-only-changed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Style check on changed files

on:
workflow_call:
inputs:
check-type:
description: format, isort or lint
default: lint
type: string
ruff-version-file:
description: The requirements.txt file that contains the Ruff version (ruff==x.x.x)
required: true
type: string

jobs:
# ------------------------------------------------------------------------------------------------------------------------------------------------
# Event `pull_request`: Compare the last commit of the main branch or last remote commit of the PR branch -> to the current commit of a PR branch.
# ------------------------------------------------------------------------------------------------------------------------------------------------
format:
name: ruff-format-changed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit.

- name: Get all changed python files
id: changed-python-files
uses: tj-actions/changed-files@v44
with:
# Avoid using single or double quotes for multiline patterns
files: |
**.py
- name: Install ruff
if: steps.changed-python-files.outputs.any_changed == 'true'
run: |
pip3 install -r <(grep '^ruff==' ${{ inputs.ruff-version-file }})
- name: Run ruff
if: steps.changed-python-files.outputs.any_changed == 'true'
run: |
set +e # Do not exit shell on app failure
if [[ ${{ inputs.check-type }} == 'lint' ]]; then
nonzero_exit=0
for file in ${{ steps.changed-python-files.outputs.all_changed_files }}; do
out=$(ruff check --force-exclude "$file" 2> app_stderr.txt)
exit_code=$?
err=$(<app_stderr.txt)
if [[ $exit_code -ne 0 ]]; then
nonzero_exit=$exit_code
fi
if [[ -n "$out" ]]; then
# Display the raw output in the step
echo "${out}"
# Display the Markdown output in the job summary
{ echo "\`\`\`python"; echo "${out}"; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY"
fi
if [[ -n "$err" ]]; then
echo "${err}"
{ echo "\`\`\`python"; echo "${err}"; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY"
fi
out=$(ruff check --diff --force-exclude "$file" 2> ruff_stderr.txt)
err=$(<ruff_stderr.txt)
if [[ -n "$out" ]]; then
# Display the raw output in the step
echo "${out}"
# Display the Markdown output in the job summary
{ echo "\`\`\`diff"; echo "${out}"; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY"
fi
if [[ -n "$err" ]]; then
echo "${err}"
{ echo "\`\`\`python"; echo "${err}"; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY"
fi
done
# Exit with the first non-zero exit-code returned by ruff
# or just zero if all passed
exit ${nonzero_exit}
else
if [[ ${{ inputs.check-type }} == 'format' ]]; then
out=$(ruff format --check --diff ${{ steps.changed-python-files.outputs.all_changed_files }} 2> app_stderr.txt)
elif [[ ${{ inputs.check-type }} == 'isort' ]]; then
out=$(ruff check --select I --diff ${{ steps.changed-python-files.outputs.all_changed_files }} 2> app_stderr.txt)
fi
exit_code=$?
err=$(<app_stderr.txt)
# Display the raw output in the step
echo "${out}"
echo "${err}"
# Display the Markdown output in the job summary
{ echo "\`\`\`diff"; echo "${out}"; echo "${err}"; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY"
# Exit with the exit-code returned by the app
exit ${exit_code}
fi
96 changes: 96 additions & 0 deletions .github/workflows/check-ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Ruff style checking

on:
workflow_call:
inputs:
check-type:
description: format, isort or lint
default: lint
type: string
ruff-version-file:
description: The requirements.txt file that contains the Ruff version (ruff==x.x.x)
required: true
type: string

jobs:
ruff:
name: ruff
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install ruff and requirements
run: |
pip3 install -r <(grep '^ruff==' "${{ inputs.ruff-version-file }}")
- name: Run ruff
run: |
set +e # Do not exit shell on ruff failure
if [[ "${{ inputs.check-type }}" == "lint" ]]; then
# code annotation
ruff check --output-format=github
# summary
nonzero_exit=0
files=$(find . -type f -name "*.py" | sort)
while read -r file; do
out=$(ruff check --force-exclude "$file" 2> ruff_stderr.txt)
exit_code=$?
err=$(<ruff_stderr.txt)
if [[ $exit_code -ne 0 ]]; then
nonzero_exit=$exit_code
fi
if [[ -n "$out" ]]; then
# Display the raw output in the step
echo "${out}"
# Display the Markdown output in the job summary
{ echo "\`\`\`python"; echo "${out}"; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY"
fi
if [[ -n "$err" ]]; then
echo "${err}"
{ echo "\`\`\`python"; echo "${err}"; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY"
fi
out=$(ruff check --diff --force-exclude "$file" 2> ruff_stderr.txt)
err=$(<ruff_stderr.txt)
if [[ -n "$out" ]]; then
# Display the raw output in the step
echo "${out}"
# Display the Markdown output in the job summary
{ echo "\`\`\`python"; echo "${out}"; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY"
fi
if [[ -n "$err" ]]; then
echo "${err}"
{ echo "\`\`\`python"; echo "${err}"; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY"
fi
done <<< "$files"
# Exit with the first non-zero exit-code returned by ruff
# or just zero if all passed
exit ${nonzero_exit}
else
if [[ "${{ inputs.check-type }}" == "format" ]]; then
out=$(ruff format --check --diff . 2> app_stderr.txt)
elif [[ "${{ inputs.check-type }}" == "isort" ]]; then
out=$(ruff check --select I --diff . 2> app_stderr.txt)
else
echo "Invalid check-type: ${{ inputs.check-type }}"
exit 1
fi
exit_code=$?
err=$(<app_stderr.txt)
# Display the raw output in the step
echo "${out}"
echo "${err}"
# Display the Markdown output in the job summary
{ echo "\`\`\`diff"; echo "${out}"; echo "${err}"; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY"
# Exit with the exit-code returned by ruff
exit ${exit_code}
fi
98 changes: 98 additions & 0 deletions .github/workflows/commit-changelog-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Commit CHANGELOG.md and create a Release

on:
workflow_call:
inputs:
version-tag:
description: New version tag that starts with 'v' (e.g. v0.1.0)
required: true
type: string
dry-run:
description: Show a sample changelog in Summary without committing or creating a release
type: boolean
default: false
changelog-path:
description: Path to the CHANGELOG.md file
type: string
default: docs/CHANGELOG.md
exclude-types:
description: Comma-separated list of commit types to exclude from the changelog
type: string
default: build,docs,style,other

jobs:
dry-run:
if: ${{ inputs.dry-run == true }}
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Push new version tag temporarily for changelog generation
run: |
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git tag -a ${{ inputs.version-tag }} -m ${{ inputs.version-tag }}
git push --tags
- name: Get CHANGELOG
id: changelog-dry-run
uses: requarks/changelog-action@v1.10.2
with:
includeInvalidCommits: true
excludeTypes: ${{ inputs.exclude-types }}
token: ${{ github.token }}
tag: ${{ inputs.version-tag }}

- name: Display CHANGELOG
run: |
echo '${{ steps.changelog-dry-run.outputs.changes }}'
echo '${{ steps.changelog-dry-run.outputs.changes }}' > "$GITHUB_STEP_SUMMARY"
- name: Remove temporary version tag
run: |
git tag -d ${{ inputs.version-tag }}
git push origin --delete ${{ inputs.version-tag }}
deploy:
if: ${{ inputs.dry-run == false }}
runs-on: ubuntu-latest
environment: mkdocs

steps:
- uses: actions/checkout@v4
- name: Push new version tag temporarily for changelog generation
run: |
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git tag -a ${{ inputs.version-tag }} -m ${{ inputs.version-tag }}
git push --tags
- name: Update CHANGELOG
id: changelog
uses: requarks/changelog-action@v1.10.2
with:
includeInvalidCommits: true
excludeTypes: ${{ inputs.exclude-types }}
token: ${{ github.token }}
tag: ${{ inputs.version-tag }}
changelogFilePath: ${{ inputs.changelog-path }}

- name: Commit ${{ inputs.changelog-path }} and update tag
run: |
git tag -d ${{ inputs.version-tag }}
git push origin --delete ${{ inputs.version-tag }}
git add ${{ inputs.changelog-path }}
git commit -m "docs: update ${{ inputs.changelog-path }} for ${{ inputs.version-tag }} [skip ci]"
git tag -a ${{ inputs.version-tag }} -m ${{ inputs.version-tag }}
git push
git push --tags
- name: Create Release
uses: ncipollo/release-action@v1.14.0
with:
allowUpdates: true
draft: false
makeLatest: true
name: ${{ inputs.version-tag }}
tag: ${{ inputs.version-tag }}
body: ${{ steps.changelog.outputs.changes }}
Loading

0 comments on commit 2ff4731

Please sign in to comment.