Skip to content

Commit

Permalink
Create reusable workflows (#15)
Browse files Browse the repository at this point in the history
* Create publish-pypi.yml

* Create dependabot.yml

* Create README.md

* Create coverage.yml

* Update coverage.yml

* Add move reusable workflows

* update main.yml to fix error

* update main.yml to fix error

* update job names

* add mkdocs and sphinx workflows

* update inputs name

* add release-drafter.yml

* Update README.md

Co-authored-by: Brendan <[email protected]>

* Update .pre-commit-config.yaml

Co-authored-by: Brendan <[email protected]>

* Update sphinx.yml

Co-authored-by: Brendan <[email protected]>

* update based on review

* checkout repo in pre-commit.yml

* fix indent in sphinx.yml

* test: test workflows

* test workflows

* add test dummy code

* refactor dummy source code

* remove test source code

* Update .gitignore

---------

Co-authored-by: Brendan <[email protected]>
  • Loading branch information
shenxianpeng and 2bndy5 authored Feb 21, 2024
1 parent 248c53c commit 0d42924
Show file tree
Hide file tree
Showing 12 changed files with 398 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: "weekly"
11 changes: 11 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: main

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
main:
uses: ./.github/workflows/pre-commit.yml
24 changes: 24 additions & 0 deletions .github/workflows/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: MkDocs Deploy

on:
workflow_call:

jobs:
mkdocs-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install dependencies
run: pip install mkdocs mkdocs-include-markdown-plugin mkdocs-material
- name: check mkdocs build
if: github.ref != 'refs/heads/main'
run: mkdocs build
- name: Build docs and deploy to gh-pages
if: github.ref == 'refs/heads/main'
run: |
git config user.name 'github-actions'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
mkdocs gh-deploy --force
20 changes: 20 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Run pre-commit

on:
workflow_call:

jobs:
run-pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
id: python-setup
with:
python-version: '3.x'
- name: Cache pre-commit environments
uses: actions/cache@v4
with:
path: '~/.cache/pre-commit'
key: pre-commit-${{ steps.python-setup.outputs.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }}
- run: pipx run pre-commit run --all-files
46 changes: 46 additions & 0 deletions .github/workflows/py-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Upload coverage reports

on:
workflow_call:

jobs:
publish-coverage-reports:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ci-artifacts
pattern: coverage-data-*

- run: mv ci-artifacts/**/.coverage* ./

- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Create coverage report
run: |
pip3 install coverage[toml]
coverage combine
coverage html
- name: Upload comprehensive coverage HTML report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: htmlcov/

- run: coverage report && coverage xml

- uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
with:
files: ./coverage.xml
fail_ci_if_error: true # optional (default = false)
verbose: true # optional (default = false)
44 changes: 44 additions & 0 deletions .github/workflows/py-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build and publish python package

on:
workflow_call:

permissions:
contents: read

jobs:
publish-to-pypi:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
# use fetch --all for setuptools_scm to work
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install dependencies
run: python -m pip install --upgrade pip twine

- name: Build wheel
run: python -m pip wheel -w dist --no-deps .

- name: Check distribution
run: twine check dist/*

- name: Publish package (to TestPyPI)
if: github.event_name == 'workflow_dispatch' && startsWith(github.repository, 'cpp-linter')
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}
run: twine upload --repository testpypi dist/*

- name: Publish package (to PyPI)
if: github.event_name != 'workflow_dispatch' && startsWith(github.repository, 'cpp-linter')
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: twine upload dist/*
13 changes: 13 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Release Drafter

on:
workflow_call:

jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
# Draft your next Release notes as Pull Requests are merged into the default branch
- uses: release-drafter/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39 changes: 39 additions & 0 deletions .github/workflows/sphinx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Sphinx Deploy

on:
workflow_call:
inputs:
path-to-doc:
required: true
type: string
default: docs/_build/html
description: The docs path name

jobs:
sphinx-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install dependencies
run: pip install sphinx-immaterial

- name: Build docs
if: github.ref != 'refs/heads/main'
run: sphinx-build docs ${{ inputs.path-to-doc }}

- name: Upload docs build as artifact
uses: actions/upload-artifact@v4
with:
name: ${{ github.repository }}_docs
path: ${{ github.workspace }}/${{ inputs.path-to-doc }}

- name: Upload to github pages
# only publish doc changes from main branch
if: github.ref == 'refs/heads/main'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./${{ inputs.path-to-doc }}
176 changes: 176 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml

# ruff
.ruff_cache/

# LSP config files
pyrightconfig.json

# End of https://www.toptal.com/developers/gitignore/api/python
Loading

0 comments on commit 0d42924

Please sign in to comment.