99 description : ' PyPI API token to publish package'
1010 required : false
1111 inputs :
12- UPLOAD_PACKAGE :
12+ RELEASE_STEPS :
1313 description : ' Should the package be uploaded to PyPI?'
1414 required : false
1515 default : false
@@ -27,181 +27,119 @@ on:
2727 required : false
2828 default : ' 3.10.11'
2929 type : string
30- PUSH_TAG :
31- description : ' Push tag after version bump'
32- required : false
33- default : false
34- type : boolean
3530 RELEASE_BUILD :
3631 description : ' Is release build?'
3732 required : false
3833 default : false
3934 type : boolean
40- GIT_USER :
41- description : ' Git user name for commit and tag'
42- required : true
43- type : string
44- GIT_EMAIL :
45- description : ' Git user email for commit and tag'
46- required : true
47- type : string
48- PROJECT_NAME :
49- description : ' Project name for tests'
50- required : true
51- type : string
52- SOURCE_PATH :
53- description : ' Path to the source code directory'
54- required : false
55- default : ' src'
56- type : string
5735 RUNS_ON :
5836 description : ' Runner type for the job'
5937 required : false
6038 default : ' ubuntu-latest'
6139 type : string
40+ JOB_NAME :
41+ description : ' Name of the job'
42+ required : false
43+ default : ' build_whl'
44+ type : string
6245
6346jobs :
6447 build_whl :
65- permissions :
66- contents : write
67- id-token : write
68- environment :
69- name : " pypi"
70- url : https://pypi.org/p/${{ inputs.PROJECT_NAME }}
48+ name : ${{ inputs.JOB_NAME }}
7149 runs-on : ${{ inputs.RUNS_ON }}
7250 steps :
7351 - uses : actions/checkout@v4
7452 with :
7553 fetch-tags : true
7654 fetch-depth : 0
77- path : ${{ inputs.SOURCE_PATH }}
7855 ref : ${{ inputs.BRANCH_NAME }}
56+ repository : ${{ inputs.REPOSITORY_NAME }}
7957
8058 - name : Set up Python
8159 uses : actions/setup-python@v5
8260 with :
8361 python-version : ${{ inputs.PYTHON_VERSION }}
8462 cache : ' pip'
8563
86- - name : Version bumping
87- id : VERSION_BUMP
88- if : inputs.RELEASE_BUILD == true
89- env :
90- GIT_AUTHOR_NAME : ${{ inputs.GIT_USER }}
91- GIT_AUTHOR_EMAIL : ${{ inputs.GIT_EMAIL }}
92- GIT_COMMITTER_NAME : ${{ inputs.GIT_USER }}
93- GIT_COMMITTER_EMAIL : ${{ inputs.GIT_EMAIL }}
94- shell : bash
95- run : |
96- python -m pip install --upgrade pip
97- python -m venv bump_version
98- source bump_version/bin/activate
99- pip install python-semantic-release~=10.2
100- pip install -r ${{ inputs.SOURCE_PATH }}/requirements-dev.txt
101- pip install ./${{ inputs.SOURCE_PATH }}
102- mfd-create-config-files --project-dir ./${{ inputs.SOURCE_PATH }}
103- cd ${{ inputs.SOURCE_PATH }}
104- version_after_bump=$(semantic-release version --print | tail -n 1 | tr -d '\n')
105- version_from_tag=$(git describe --tags --abbrev=0 | tr -d '\n' | sed 's/^v//')
106- echo "Version after semantic-release bump is: ${version_after_bump}"
107- echo "Version from tag: ${version_from_tag}"
108- # Only check version equality if RELEASE_BUILD is true
109- if [ "${{ inputs.RELEASE_BUILD }}" == "true" ]; then
110- if [ "$version_after_bump" == "$version_from_tag" ]; then
111- echo "Version would not change: version_after_bump=${version_after_bump}, version_from_tag=${version_from_tag}"
112- exit 1
113- fi
114- fi
115- semantic-release version --no-push --no-vcs-release
116- cat pyproject.toml
117- echo "version_after_bump=v${version_after_bump}" >> $GITHUB_OUTPUT
118- - name : Create virtual environment for whl creation
119- shell : bash
64+ - name : Show python version
65+ run : python --version
66+
67+ - name : Run mfd-create-config-files
12068 run : |
121- python -m venv whl_creation
122- source whl_creation/bin/activate
123- pip install build==1.2.2.post1
124- cd ${{ inputs.SOURCE_PATH }}
125- ../whl_creation/bin/python -m build --wheel --outdir ../whl_creation/dist
126- ls -l ../whl_creation/dist
69+ pip install -r requirements-dev.txt
70+ pip install .
71+ mfd-create-config-files --project-dir .
12772
128- - name : Determine if unit and functional tests should run
129- id : test_check
130- shell : bash
73+ - name : Check if bump version is expected
13174 run : |
132- REPO_NAME=$(echo "${{ inputs.PROJECT_NAME }}")
133- echo "Repository name extracted: $REPO_NAME"
75+ if [ "${{ inputs.RELEASE_BUILD }}" = "false" ]; then
76+ COMMIT_MSG=$(git log -1 --pretty=%B)
13477
135- UNIT_TEST_DIR="${{ inputs.SOURCE_PATH }}/tests/unit/test_$(echo "${REPO_NAME}" | tr '-' '_')"
136- FUNC_TEST_DIR="${{ inputs.SOURCE_PATH }}/tests/system/test_$(echo "${REPO_NAME}" | tr '-' '_')"
137- if [ -d "$UNIT_TEST_DIR" ]; then
138- echo "Unit tests directory exists: $UNIT_TEST_DIR"
139- echo "run_unit_tests=true" >> $GITHUB_OUTPUT
140- else
141- echo "Unit tests directory does not exist: $UNIT_TEST_DIR"
142- echo "run_unit_tests=false" >> $GITHUB_OUTPUT
143- fi
144- if [ -d "$FUNC_TEST_DIR" ]; then
145- echo "Functional tests directory exists: $FUNC_TEST_DIR"
146- echo "run_functional_tests=true" >> $GITHUB_OUTPUT
78+ if echo "$COMMIT_MSG" | grep -Ei '^(docs|build|test|ci|refactor|perf|chore|revert):\s'; then
79+ echo "CREATE_WHL=false" >> $GITHUB_ENV
80+ echo "No version bump needed for commit message: $COMMIT_MSG, ending job"
81+ else
82+ echo "CREATE_WHL=true" >> $GITHUB_ENV
83+ echo "Version bump needed for commit message: $COMMIT_MSG, continuing job"
84+ fi
14785 else
148- echo "Functional tests directory does not exist: $FUNC_TEST_DIR "
149- echo "run_functional_tests=false " >> $GITHUB_OUTPUT
86+ echo "Skipping potential bump version check for release build "
87+ echo "CREATE_WHL=true " >> $GITHUB_ENV
15088 fi
15189
152- - name : Install dependencies for tests
153- if : steps.test_check.outputs.run_unit_tests == 'true' || steps.test_check.outputs.run_functional_tests == 'true'
154- shell : bash
155- run : |
156- python -m venv test_env
157- source test_env/bin/activate
158- python -m pip install -r "${{ inputs.SOURCE_PATH }}/requirements.txt" -r "${{ inputs.SOURCE_PATH }}/requirements-test.txt" -r "${{ inputs.SOURCE_PATH }}/requirements-dev.txt"
159- python -m pip install ./${{ inputs.SOURCE_PATH }}
90+ - name : Run python-semantic-release without version bump - force patch bump
91+ if : env.CREATE_WHL == 'false'
92+ uses :
python-semantic-release/[email protected] 93+ with :
94+ build : true
95+ vcs_release : false
96+ push : false
97+ strict : true
98+ force : patch
16099
161- - name : Run unit tests if test directory exists
162- if : steps.test_check.outputs.run_unit_tests == 'true'
163- shell : bash
164- run : |
165- source test_env/bin/activate
166- mfd-unit-tests --project-dir ${{ github.workspace }}/${{ inputs.SOURCE_PATH }}
100+ - name : Run python-semantic-release
101+ if : env.CREATE_WHL == 'true'
102+ uses :
python-semantic-release/[email protected] 103+ with :
104+ build : true
105+ vcs_release : false
106+ push : false
107+ strict : true
167108
168- - name : Run functional tests if test directory exists
169- if : steps.test_check.outputs.run_functional_tests == 'true'
109+ - name : Check if .whl is installable
170110 shell : bash
171111 run : |
172- source test_env/bin/activate
173- mfd-system-tests --project-dir ${{ github.workspace }}/${{ inputs.SOURCE_PATH }}
112+ python -m pip install dist/*.whl
113+
174114 - name : Publish package distributions to PyPI
175- if : ${{ inputs.RELEASE_BUILD == true && inputs.UPLOAD_PACKAGE == true }}
115+ if : ${{ inputs.RELEASE_BUILD == true && inputs.RELEASE_STEPS == true }}
176116 uses : pypa/gh-action-pypi-publish@release/v1
177117 with :
178- packages-dir : ' whl_creation/ dist'
118+ packages-dir : ' dist'
179119 password : ${{ secrets.PYPI_TOKEN }}
180120
181121 - name : Publish comment how to build .whl
182- if : inputs.RELEASE_BUILD == false
122+ if : inputs.RELEASE_BUILD == false && (github.event.pull_request != null && github.event.pull_request.head.repo.full_name == github.repository) # skip for forks
183123 uses : actions/github-script@v7
184124 with :
185125 github-token : ${{ secrets.GH_TOKEN }}
186126 script : |
187127 const prNumber = context.payload.pull_request.number;
188- const commentBody = "We don't publish DEVs .whl.\n To build .whl, run 'pip install git+https://github.com/${{ inputs.REPOSITORY_NAME }}@${{ inputs.BRANCH_NAME }}'";
189- await github.rest.issues.createComment({
128+ const commentBody = "We don't publish DEVs .whl.\n To build .whl, run 'pip install git+https://${{ inputs.REPOSITORY_NAME }}@${{ inputs.BRANCH_NAME }}'";
129+
130+ const { data: comments } = await github.rest.issues.listComments({
190131 owner: context.repo.owner,
191132 repo: context.repo.repo,
192133 issue_number: prNumber,
193- body: commentBody
194134 });
195135
196- - name : Push git tag after version bump
197- if : ${{ inputs.RELEASE_BUILD == true && inputs.PUSH_TAG == true }}
198- shell : bash
199- env :
200- GIT_AUTHOR_NAME : ${{ inputs.GIT_USER }}
201- GIT_AUTHOR_EMAIL : ${{ inputs.GIT_EMAIL }}
202- GIT_COMMITTER_NAME : ${{ inputs.GIT_USER }}
203- GIT_COMMITTER_EMAIL : ${{ inputs.GIT_EMAIL }}
204- version_after_bump : ${{ steps.VERSION_BUMP.outputs.version_after_bump }}
205- run : |
206- cd ${{ inputs.SOURCE_PATH }}
207- git push origin "${version_after_bump}"
136+ const alreadyCommented = comments.some(comment => comment.body === commentBody);
137+
138+ if (!alreadyCommented) {
139+ await github.rest.issues.createComment({
140+ owner: context.repo.owner,
141+ repo: context.repo.repo,
142+ issue_number: prNumber,
143+ body: commentBody
144+ });
145+ }
0 commit comments