-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpython-release.yaml
More file actions
124 lines (118 loc) · 4.9 KB
/
python-release.yaml
File metadata and controls
124 lines (118 loc) · 4.9 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
---
# This is a workflow template for Python release.
# It will publish a new version of the package to PyPI and create a release draft in the repository.
# The workflow requires the following secrets to be set in the repository:
# - PYPI_API_TOKEN: PyPI API token to publish the package
# The workflow requires the configuration release-drafter-config.yml file to be placed in the .github folder of the repository.
# The example file can be found there:
# https://github.com/netcracker/qubership-workflow-hub/blob/main/docs/examples/release-drafter-config.yml
name: Python Release
run-name: "${{ github.event.repository.name }} release ${{ inputs.version || inputs.poetry-version-options }}"
on:
workflow_dispatch:
inputs:
version:
description: 'Specify version (optional)'
required: false
default: ''
python-version:
description: 'Python version to use'
required: false
default: '3.11'
poetry-version-options:
description: 'Poetry version bump (e.g., patch, minor, major)'
required: false
default: 'patch'
poetry-build-params:
description: 'Additional poetry build parameters'
required: false
default: ''
pytest-run:
description: 'Run pytest (true/false)'
required: true
type: boolean
default: true
pytest-params:
description: 'Parameters for pytest'
required: false
default: '--maxfail=3 -v'
permissions:
contents: read
jobs:
pre-build-checks:
name: "Pre-build Checks"
runs-on: ubuntu-latest
steps:
- name: Input parameters
run: |
echo "Input parameters:" >> $GITHUB_STEP_SUMMARY
echo "Version: ${{ github.event.inputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "Python version: ${{ github.event.inputs.python-version }}" >> $GITHUB_STEP_SUMMARY
echo "Poetry version options: ${{ github.event.inputs.poetry-version-options }}" >> $GITHUB_STEP_SUMMARY
echo "Poetry build parameters: ${{ github.event.inputs.poetry-build-params }}" >> $GITHUB_STEP_SUMMARY
echo "Pytest run: ${{ github.event.inputs.pytest-run }}" >> $GITHUB_STEP_SUMMARY
echo "Pytest parameters: ${{ github.event.inputs.pytest-params }}" >> $GITHUB_STEP_SUMMARY
- name: Check if tag exists
if: ${{ inputs.version != '' }}
id: check_tag
uses: netcracker/qubership-workflow-hub/actions/tag-action@5a557213e92e3d22d0292330c4817c82af6704d2 #v2.1.2
with:
tag-name: 'v${{ inputs.version }}'
ref: ${{ github.ref }}
create-tag: false
check-tag: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
name: "Publish Package to PyPI"
runs-on: ubuntu-latest
permissions:
contents: write
needs: [pre-build-checks]
outputs:
published-version: ${{ steps.publish.outputs.release-version }}
steps:
- name: "Prepare app token"
if: ${{ vars.GH_BUMP_VERSION_APP_ID != '' }}
uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0
id: app-token
with:
app-id: ${{ vars.GH_BUMP_VERSION_APP_ID }}
private-key: ${{ secrets.GH_BUMP_VERSION_APP_KEY }}
- name: "Checkout"
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
token: ${{ steps.app-token.outputs.token || secrets.GITHUB_TOKEN }}
- name: "Setup Python ${{ inputs.python-version }}"
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: ${{ inputs.python-version }}
- name: "Publish to PyPI"
id: publish
uses: netcracker/qubership-workflow-hub/actions/poetry-publisher@5a557213e92e3d22d0292330c4817c82af6704d2 #v2.1.2
with:
package_version: ${{ inputs.version }}
poetry_version_bump: ${{ inputs.poetry-version-options }}
poetry_build_options: ${{ inputs.poetry-build-params }}
run_pytest: ${{ inputs.pytest-run }}
pytest_options: ${{ inputs.pytest-params }}
publish: "true"
env:
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
- name: "Commit changes"
run: |
git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com"
git config --global user.name "$GITHUB_ACTOR"
git add .
git commit -m "Update version to ${{ steps.publish.outputs.release-version }} for release"
git push -u origin ${{ github.ref }}
github-release:
name: "Create GitHub Release Draft"
permissions:
contents: write
pull-requests: write
needs: [publish]
uses: netcracker/qubership-workflow-hub/.github/workflows/release-drafter.yml@5a557213e92e3d22d0292330c4817c82af6704d2 #v2.1.2
with:
version: ${{ needs.publish.outputs.published-version }}
publish: true