Skip to content

Commit

Permalink
Merge pull request #94 from ASFHyP3/ruff
Browse files Browse the repository at this point in the history
Create Ruff reusable action
  • Loading branch information
forrestfwilliams authored Nov 22, 2023
2 parents 11c4450 + e738f0e commit 6a9f002
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 15 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/reusable-ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
on:
workflow_call:

jobs:
check-with-ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Python
uses: actions/setup-python@v4
with:
python-version: 3.x

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install ruff
- name: Ruff linting check
run: ruff check --output-format=github .

- name: Ruff format check
run: ruff format --diff .
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/)
and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.8.4]

### Added
- `reusable-ruff` workflow for perform linting and static analysis with [Ruff](https://github.com/astral-sh/ruff).

## [0.8.3]

Expand Down
78 changes: 63 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ on:

jobs:
call-bump-version-workflow:
uses: ASFHyP3/actions/.github/workflows/[email protected].2
uses: ASFHyP3/actions/.github/workflows/[email protected].4
with:
user: tools-bot # Optional; default shown
email: [email protected] # Optional; default shown
Expand Down Expand Up @@ -57,7 +57,7 @@ on:
jobs:
call-changelog-check-workflow:
uses: ASFHyP3/actions/.github/workflows/[email protected].2
uses: ASFHyP3/actions/.github/workflows/[email protected].4
secrets:
USER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
Expand All @@ -77,7 +77,7 @@ on:
jobs:
call-create-jira-issue-workflow:
uses: ASFHyP3/actions/.github/workflows/[email protected].2
uses: ASFHyP3/actions/.github/workflows/[email protected].4
secrets:
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
Expand Down Expand Up @@ -130,13 +130,13 @@ on:
jobs:
call-version-info-workflow:
uses: ASFHyP3/actions/.github/workflows/[email protected].2
uses: ASFHyP3/actions/.github/workflows/[email protected].4
with:
conda_env_name: hyp3-plugin
call-docker-ecr-workflow:
needs: call-version-info-workflow
uses: ASFHyP3/actions/.github/workflows/[email protected].2
uses: ASFHyP3/actions/.github/workflows/[email protected].4
with:
version_tag: ${{ needs.call-version-info-workflow.outputs.version_tag }}
ecr_registry: 845172464411.dkr.ecr.us-west-2.amazonaws.com
Expand Down Expand Up @@ -171,13 +171,13 @@ on:
jobs:
call-version-info-workflow:
uses: ASFHyP3/actions/.github/workflows/[email protected].2
uses: ASFHyP3/actions/.github/workflows/[email protected].4
with:
conda_env_name: hyp3-plugin
call-docker-ghcr-workflow:
needs: call-version-info-workflow
uses: ASFHyP3/actions/.github/workflows/[email protected].2
uses: ASFHyP3/actions/.github/workflows/[email protected].4
with:
version_tag: ${{ needs.call-version-info-workflow.outputs.version_tag }}
user: ${{ github.actor }}
Expand All @@ -198,14 +198,62 @@ on: push
jobs:
call-flake8-workflow:
uses: ASFHyP3/actions/.github/workflows/[email protected].2
uses: ASFHyP3/actions/.github/workflows/[email protected].4
with:
local_package_names: hyp3_plugin # Required; comma-seperated list of names that should be considered local to your application
excludes: hyp3_plugin/ugly.py # Optional; comma-separated list of glob patterns to exclude from checks
```

to ensure the Python code is styled correctly.

### [`reusable-ruff.yml`](./.github/workflows/reusable-ruff.yml)

Runs [Ruff](https://docs.astral.sh/ruff/) to enforce a configurable Python style guide. Use like:

```yaml
name: Static analysis
on: push
jobs:
call-ruff-workflow:
uses: ASFHyP3/actions/.github/workflows/[email protected]
```

to ensure the Python code is styled correctly.

To conform to ASFHyP3's Python style add the following to your project's `pyproject.toml`:
```toml
[tool.ruff]
line-length = 120
src = ["src", "tests"]
[tool.ruff.format]
indent-style = "space"
quote-style = "single"
[tool.ruff.lint]
extend-select = [
"UP", # pyupgrade
"D", # pydocstyle
"ANN", # annotations
"PTH", # use-pathlib-pth
]
[tool.ruff.lint.pydocstyle]
convention = "google"
[tool.ruff.lint.isort]
case-sensitive = true
lines-after-imports = 2
```

Ruff can automatically fix many linting errors and reformat code to match your Python style by running these commands:
```shell
ruff check --fix .
ruff format .
```

### [`reusable-git-object-name.yml`](./.github/workflows/reusable-git-object-name.yml)

Outputs the human-readable git object name from [`git describe --dirty --tags --long --match "*[0-9]*"`](https://git-scm.com/docs/git-describe)
Expand All @@ -226,7 +274,7 @@ on:
jobs:
call-git-object-name-workflow:
uses: ASFHyP3/actions/.github/workflows/[email protected].2
uses: ASFHyP3/actions/.github/workflows/[email protected].4
echo-git-object-name-outputs:
needs: call-git-object-name-workflow
Expand Down Expand Up @@ -256,7 +304,7 @@ on:
jobs:
call-labeled-pr-check-workflow:
uses: ASFHyP3/actions/.github/workflows/[email protected].2
uses: ASFHyP3/actions/.github/workflows/[email protected].4
```
to ensure a release label is included on any PR to `main`.

Expand All @@ -280,7 +328,7 @@ on:
jobs:
call-pytest-workflow:
uses: ASFHyP3/actions/.github/workflows/[email protected].2
uses: ASFHyP3/actions/.github/workflows/[email protected].4
with:
local_package_name: hyp3_plugin # Required; package to produce a coverage report for
fail_fast: false # Optional; default shown
Expand Down Expand Up @@ -309,7 +357,7 @@ on:
jobs:
call-release-workflow:
uses: ASFHyP3/actions/.github/workflows/[email protected].2
uses: ASFHyP3/actions/.github/workflows/[email protected].4
with:
release_prefix: HyP3-CI
release_branch: main # Optional; default shown
Expand Down Expand Up @@ -338,7 +386,7 @@ on:
jobs:
call-release-checklist-workflow:
uses: ASFHyP3/actions/.github/workflows/[email protected].2
uses: ASFHyP3/actions/.github/workflows/[email protected].4
permissions:
pull-requests: write
with:
Expand Down Expand Up @@ -367,7 +415,7 @@ on: push
jobs:
call-secrets-analysis-workflow:
uses: ASFHyP3/actions/.github/workflows/[email protected].2
uses: ASFHyP3/actions/.github/workflows/[email protected].4
```
to scan every push for secrets.

Expand All @@ -393,7 +441,7 @@ on:
jobs:
call-version-info-workflow:
uses: ASFHyP3/actions/.github/workflows/[email protected].2
uses: ASFHyP3/actions/.github/workflows/[email protected].4
with:
python_version: '3.9' # Optional; default shown
Expand Down

0 comments on commit 6a9f002

Please sign in to comment.