Skip to content

Commit 2ddc2a0

Browse files
Merge pull request #2 from tahzeer/develop
feat: add gh workflows for pre-commit and openapi
2 parents 6ef01d4 + b6f54d0 commit 2ddc2a0

File tree

7 files changed

+204
-2
lines changed

7 files changed

+204
-2
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: OpenAPI Generate - Bene Portal API
2+
3+
on:
4+
push:
5+
branches:
6+
- "**"
7+
tags-ignore:
8+
- '**'
9+
workflow_dispatch:
10+
11+
jobs:
12+
openapi-publish:
13+
name: OpenAPI Generate - Bene Portal API
14+
runs-on: ubuntu-latest
15+
defaults:
16+
run:
17+
working-directory: openg2p-pbms-bene-portal-api
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Get branch name (merge)
21+
run: |
22+
echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV
23+
- name: Setup python for openapi generate
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: "3.10"
27+
- name: Install app
28+
run: |
29+
python -m pip install git+https://github.com/openg2p/openg2p-fastapi-common@1.1\#subdirectory=openg2p-fastapi-common
30+
python -m pip install git+https://github.com/openg2p/openg2p-fastapi-common@1.1\#subdirectory=openg2p-fastapi-auth
31+
python -m pip install ../openg2p-pbms-models
32+
python -m pip install ../openg2p-bg-task-models
33+
python -m pip install .
34+
- name: Generate openapi json
35+
run: |
36+
mkdir -p api-docs/generated
37+
python3 main.py getOpenAPI api-docs/generated/openapi.json
38+
if ! [ -z "$(git status --porcelain=v1 2>/dev/null -- openg2p-pbms-bene-portal-api/api-docs/generated/openapi.json)" ]; then
39+
shopt -s nocasematch
40+
if [[ ${{ github.repository_owner }} == 'OpenG2P' ]]; then
41+
export OPENAPI_CHANGED="true"
42+
echo OPENAPI_CHANGED=$OPENAPI_CHANGED >> $GITHUB_ENV
43+
fi
44+
fi
45+
- name: Commit Changes
46+
uses: EndBug/add-and-commit@v7
47+
with:
48+
default_author: github_actions
49+
message: "Generated new openapi.json for Bene Portal API on push to ${{ github.event.inputs.git-ref }}"
50+
add: "openg2p-pbms-bene-portal-api/api-docs/generated/openapi.json"
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: OpenAPI Generate - Staff Portal API
2+
3+
on:
4+
push:
5+
branches:
6+
- "**"
7+
tags-ignore:
8+
- '**'
9+
workflow_dispatch:
10+
11+
jobs:
12+
openapi-publish:
13+
name: OpenAPI Generate - Staff Portal API
14+
runs-on: ubuntu-latest
15+
defaults:
16+
run:
17+
working-directory: openg2p-pbms-staff-portal-api
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Get branch name (merge)
21+
run: |
22+
echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV
23+
- name: Setup python for openapi generate
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: "3.10"
27+
- name: Install app
28+
run: |
29+
python -m pip install git+https://github.com/openg2p/openg2p-fastapi-common@1.1\#subdirectory=openg2p-fastapi-common
30+
python -m pip install git+https://github.com/openg2p/openg2p-fastapi-common@1.1\#subdirectory=openg2p-fastapi-auth
31+
python -m pip install ../openg2p-pbms-models
32+
python -m pip install ../openg2p-bg-task-models
33+
python -m pip install .
34+
- name: Generate openapi json
35+
run: |
36+
mkdir -p api-docs/generated
37+
python3 main.py getOpenAPI api-docs/generated/openapi.json
38+
if ! [ -z "$(git status --porcelain=v1 2>/dev/null -- openg2p-pbms-staff-portal-api/api-docs/generated/openapi.json)" ]; then
39+
shopt -s nocasematch
40+
if [[ ${{ github.repository_owner }} == 'OpenG2P' ]]; then
41+
export OPENAPI_CHANGED="true"
42+
echo OPENAPI_CHANGED=$OPENAPI_CHANGED >> $GITHUB_ENV
43+
fi
44+
fi
45+
- name: Commit Changes
46+
uses: EndBug/add-and-commit@v7
47+
with:
48+
default_author: github_actions
49+
message: "Generated new openapi.json for Staff Portal API on push to ${{ github.event.inputs.git-ref }}"
50+
add: "openg2p-pbms-staff-portal-api/api-docs/generated/openapi.json"

.github/workflows/pre-commit.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: pre-commit
2+
3+
on:
4+
pull_request:
5+
push:
6+
workflow_dispatch:
7+
8+
jobs:
9+
pre-commit:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-python@v3
14+
- uses: pre-commit/action@v3.0.0
15+
with:
16+
extra_args: --all-files --show-diff-on-failure

.github/workflows/tag.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Tag the repo
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
new-tag:
6+
description: Tag in "vN.N.N" format
7+
required: true
8+
type: string
9+
previous-tag:
10+
description: Previous tag. "None" if no previous tag
11+
required: true
12+
type: string
13+
default: latest
14+
jobs:
15+
tag-repo:
16+
uses: openg2p/openg2p-packaging/.github/workflows/tag.yml@main
17+
with:
18+
new-tag: ${{ inputs.new-tag }}
19+
previous-tag: ${{ inputs.previous-tag }}
20+
secrets:
21+
OPENG2P_BOT_GITHUB_PAT: ${{ secrets.OPENG2P_BOT_GITHUB_PAT }}

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ cython_debug/
182182
.abstra/
183183

184184
# Visual Studio Code
185-
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
185+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186186
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187-
# and can be added to the global gitignore or merged into this file. However, if you prefer,
187+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
188188
# you could uncomment the following to ignore the entire vscode folder
189189
# .vscode/
190190

.pre-commit-config.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
exclude: |
2+
(?x)
3+
# We don't want to mess with tool-generated files
4+
.svg$|/tests/([^/]+/)?cassettes/|^.copier-answers.yml$|^.github/|
5+
# Maybe reactivate this when all README files include prettier ignore tags?
6+
^README\.md$|
7+
# Repos using Sphinx to generate docs don't need prettying
8+
^docs/_templates/.*\.html$|
9+
# You don't usually want a bot to modify your legal texts
10+
(LICENSE.*|COPYING.*)
11+
default_language_version:
12+
python: python3
13+
repos:
14+
- repo: https://github.com/pre-commit/pre-commit-hooks
15+
rev: v4.4.0
16+
hooks:
17+
- id: trailing-whitespace
18+
- id: end-of-file-fixer
19+
- id: debug-statements
20+
- id: fix-encoding-pragma
21+
args: ["--remove"]
22+
- id: check-case-conflict
23+
- id: check-docstring-first
24+
- id: check-executables-have-shebangs
25+
- id: check-merge-conflict
26+
- id: check-symlinks
27+
- id: check-toml
28+
- id: check-yaml
29+
args:
30+
- --unsafe
31+
- id: mixed-line-ending
32+
args: ["--fix=lf"]
33+
- repo: https://github.com/asottile/pyupgrade
34+
rev: v3.11.0
35+
hooks:
36+
- id: pyupgrade
37+
args:
38+
- --py3-plus
39+
- --keep-runtime-typing
40+
- repo: https://github.com/psf/black
41+
rev: 23.9.1
42+
hooks:
43+
- id: black
44+
- repo: https://github.com/astral-sh/ruff-pre-commit
45+
rev: v0.0.289
46+
hooks:
47+
- id: ruff
48+
args:
49+
- --fix

.ruff.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
select = [
2+
"E", # pycodestyle errors
3+
"W", # pycodestyle warnings
4+
"F", # pyflakes
5+
"I", # isort
6+
"C", # flake8-comprehensions
7+
"B", # flake8-bugbear
8+
]
9+
ignore = [
10+
"E501", # line too long, handled by black
11+
"B008", # do not perform function calls in argument defaults
12+
"C901", # too complex
13+
]
14+
15+
[per-file-ignores]
16+
"__init__.py" = ["F401"]

0 commit comments

Comments
 (0)