-
Notifications
You must be signed in to change notification settings - Fork 1
77 lines (74 loc) · 2.7 KB
/
main.yml
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
name: Build and Package with Poetry (Feature)
on:
push:
branches:
- 'releases/**'
jobs:
build-and-publish-python-package:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Run image
uses: abatilo/actions-poetry@v4
with:
poetry-version: "1.5.1"
- name: Increment version
id: version
run: |
BRANCH_NAME=$(echo $GITHUB_REF | sed 's/refs\/heads\///')
VERSION=$(poetry version --short)
MINOR_PATCH_PART=${VERSION#*.}
LAST_VERSION_PART_PREFIX=${MINOR_PATCH_PART%??}
PATCH_PART=${LAST_VERSION_PART_PREFIX%.*}
if [[ $BRANCH_NAME == "fix"* || $BRANCH_NAME == "bugs"* ]]; then
NEW_LATEST_PATCH_PART=$((PATCH_PART+1))b${GITHUB_RUN_ID}
elif [[ $BRANCH_NAME == "feature"* ]]; then
NEW_LATEST_PATCH_PART=$((PATCH_PART+1))a${GITHUB_RUN_ID}
elif [[ $BRANCH_NAME == "test"* ]]; then
NEW_LATEST_PATCH_PART=$((PATCH_PART+1))rc${GITHUB_RUN_ID}
elif [[ $BRANCH_NAME == "main"* || $BRANCH_NAME == "releases"* ]]; then
poetry version patch
VERSION=$(poetry version --short)
MINOR_PATCH_PART=${VERSION#*.}
LAST_VERSION_PART_PREFIX=${MINOR_PATCH_PART%??}
PATCH_PART=${LAST_VERSION_PART_PREFIX%.*}
NEW_LATEST_PATCH_PART=${PATCH_PART}${GITHUB_RUN_ID}
else
echo "Invalid branch name"
exit 1
fi
NEW_VERSION=${VERSION%.*}.${NEW_LATEST_PATCH_PART}
echo $NEW_VERSION
echo "::set-output name=version::$NEW_VERSION"
echo "::set-output name=versionType::Release"
poetry version $NEW_VERSION --no-ansi
- name: Install dependencies
run: poetry install
- name: Test with pytest
run: |
poetry run pytest
- name: Build Package
run: |
poetry build
- name: Publish a Python distribution to PyPI
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
poetry publish
- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.KODEXA_GITHUB_TOKEN }}
with:
tag_name: v${{ steps.version.outputs.version }}
release_name: Release v${{ steps.version.outputs.version }}
draft: false
prerelease: false