-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (108 loc) · 4.64 KB
/
python-package.yml
File metadata and controls
130 lines (108 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python package
permissions:
contents: read
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: self-hosted
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/create-github-app-token@v2
id: app-token
with:
app-id: ${{ vars.FLAGGLE_BOT_ID }}
private-key: ${{ secrets.FLAGGLE_BOT_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install poetry
run: |
pipx install poetry
poetry config virtualenvs.in-project true
poetry lock --verbose
poetry install --no-interaction --no-ansi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
${{ github.workspace }}/.venv/bin/flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=.venv,.git,__pycache__,docs,tests,examples
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
${{ github.workspace }}/.venv/bin/flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --statistics --exclude=.venv,.git,__pycache__,docs,tests,examples
- name: Test with pytest
run: |
${{ github.workspace }}/.venv/bin/pytest --cov=flaggle --cov-report=xml --cov-report=term-missing
version-bump:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'pull_request' || github.event_name == 'push'
steps:
- uses: actions/create-github-app-token@v2
id: app-token
with:
app-id: ${{ vars.FLAGGLE_BOT_ID }}
private-key: ${{ secrets.FLAGGLE_BOT_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: Get SEMVER from PR Title
id: semver
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
pr_title="${{ github.event.pull_request.title }}"
pr_title_norm=$(echo "$pr_title" | tr '[:upper:]' '[:lower:]')
if [[ "$pr_title_norm" =~ ^fix ]]; then
echo "semver=patch" >> $GITHUB_OUTPUT
elif [[ "$pr_title_norm" =~ ^feat ]]; then
echo "semver=minor" >> $GITHUB_OUTPUT
elif [[ "$pr_title_norm" =~ ^breaking[[:space:]]change ]]; then
echo "semver=major" >> $GITHUB_OUTPUT
else
echo "PR title '${pr_title}' does not start with fix, feat, or breaking change, skipping version bump."
echo "semver=" >> $GITHUB_OUTPUT
fi
fi
- name: Get GitHub App User ID
if: steps.semver.outputs.semver != ''
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.generate-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
- name: Bump version
if: steps.semver.outputs.semver != ''
id: bump-version
run: |
echo "old_version=$(poetry version -s)" >> $GITHUB_OUTPUT
echo "Bumping version with semver: ${{ steps.semver.outputs.semver }}"
pipx install poetry
poetry config virtualenvs.in-project true
poetry self add poetry-bumpversion
poetry lock --verbose
poetry install --no-interaction --no-ansi
poetry version ${{ steps.semver.outputs.semver }} -vvv
echo "New version: $(poetry version -s)"
echo "new_version=$(poetry version -s)" >> $GITHUB_OUTPUT
- name: Set Commiter
if: steps.semver.outputs.semver != ''
run: |
git config --global user.name '${{ steps.generate-token.outputs.app-slug }}[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.generate-token.outputs.app-slug }}[bot]@users.noreply.github.com'
- name: Commit and push changes
if: steps.semver.outputs.semver != ''
run: |
git add .
git commit -m "[skip ci] 🔖 Bump version ${{ steps.bump-version.outputs.old_version }} -> ${{ steps.bump-version.outputs.new_version }}"
git push origin HEAD:${{ github.head_ref }} --force
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}