mirror of
https://github.com/pyTooling/Actions.git
synced 2026-02-12 11:06:56 +08:00
Extract version from version file.
This commit is contained in:
52
.github/workflows/CompletePipeline.yml
vendored
52
.github/workflows/CompletePipeline.yml
vendored
@@ -177,6 +177,58 @@ jobs:
|
|||||||
exclude_list: ${{ inputs.unittest_exclude_list }}
|
exclude_list: ${{ inputs.unittest_exclude_list }}
|
||||||
disable_list: ${{ inputs.unittest_disable_list }}
|
disable_list: ${{ inputs.unittest_disable_list }}
|
||||||
|
|
||||||
|
VersionCheck:
|
||||||
|
name: ''
|
||||||
|
runs-on: 'ubuntu-24.04'
|
||||||
|
needs:
|
||||||
|
- Prepare
|
||||||
|
- UnitTestingParams
|
||||||
|
if: needs.Prepare.outputs.version != '' && needs.UnitTestingParams.outputs.package_version_file != ''
|
||||||
|
outputs:
|
||||||
|
code_version: ${{ steps.extract.outputs.code_version }}
|
||||||
|
steps:
|
||||||
|
- name: ⏬ Checkout repository
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
with:
|
||||||
|
# The command 'git describe' (used for version) needs the history.
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: 🔧 Install pyTooling dependencies (native)
|
||||||
|
run: |
|
||||||
|
python -m pip install --disable-pip-version-check -U pyTooling
|
||||||
|
|
||||||
|
- name: Extract version from Python source file
|
||||||
|
id: extract
|
||||||
|
if: endsWith(needs.UnitTestingParams.outputs.package_version_file, '.py')
|
||||||
|
shell: python
|
||||||
|
run: |
|
||||||
|
from pathlib import Path
|
||||||
|
from sys import exit
|
||||||
|
from pyTooling.Packaging import extractVersionInformation
|
||||||
|
|
||||||
|
expectedVersion = "${{ needs.Prepare.outputs.version }}".strip()
|
||||||
|
|
||||||
|
versionFile = Path("${{ needs.UnitTestingParams.outputs.package_version_file }}")
|
||||||
|
if not versionFile.exists():
|
||||||
|
print(f"::error title=CompletePipeline::Version file '{versionFile}' not found.")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
versionInformation = extractVersionInformation(versionFile)
|
||||||
|
print(f"expected: {expectedVersion}")
|
||||||
|
print(f"from code: {versionInformation.Version}")
|
||||||
|
|
||||||
|
if expectedVersion != versionInformation.Version:
|
||||||
|
print(f"::error title=CompletePipeline::Expected version does not version in Python code.")
|
||||||
|
exit(2)
|
||||||
|
|
||||||
|
# Write jobs to special file
|
||||||
|
github_output = Path(getenv("GITHUB_OUTPUT"))
|
||||||
|
print(f"GITHUB_OUTPUT: {github_output}")
|
||||||
|
with github_output.open("a+", encoding="utf-8") as f:
|
||||||
|
f.write(dedent(f"""\
|
||||||
|
code_version={versionInformation.Version}
|
||||||
|
"""))
|
||||||
|
|
||||||
UnitTesting:
|
UnitTesting:
|
||||||
uses: pyTooling/Actions/.github/workflows/UnitTesting.yml@dev
|
uses: pyTooling/Actions/.github/workflows/UnitTesting.yml@dev
|
||||||
needs:
|
needs:
|
||||||
|
|||||||
40
.github/workflows/Parameters.yml
vendored
40
.github/workflows/Parameters.yml
vendored
@@ -45,6 +45,11 @@ on:
|
|||||||
required: false
|
required: false
|
||||||
default: ''
|
default: ''
|
||||||
type: string
|
type: string
|
||||||
|
version_file:
|
||||||
|
description: "Path to module containing the version ('__version__' variable)."
|
||||||
|
required: false
|
||||||
|
default: '__init__.py'
|
||||||
|
type: string
|
||||||
python_version:
|
python_version:
|
||||||
description: 'Python version.'
|
description: 'Python version.'
|
||||||
required: false
|
required: false
|
||||||
@@ -121,6 +126,9 @@ on:
|
|||||||
package_directory:
|
package_directory:
|
||||||
description: "The package's directory."
|
description: "The package's directory."
|
||||||
value: ${{ jobs.Parameters.outputs.package_directory }}
|
value: ${{ jobs.Parameters.outputs.package_directory }}
|
||||||
|
package_version_file:
|
||||||
|
description: "Path to the package's module containing the version ('__version__' variable)."
|
||||||
|
value: ${{ jobs.Parameters.outputs.package_version_file }}
|
||||||
artifact_basename:
|
artifact_basename:
|
||||||
description: "Artifact base name."
|
description: "Artifact base name."
|
||||||
value: ${{ jobs.Parameters.outputs.artifact_basename }}
|
value: ${{ jobs.Parameters.outputs.artifact_basename }}
|
||||||
@@ -139,11 +147,18 @@ jobs:
|
|||||||
python_version: ${{ steps.variables.outputs.python_version }}
|
python_version: ${{ steps.variables.outputs.python_version }}
|
||||||
package_fullname: ${{ steps.variables.outputs.package_fullname }}
|
package_fullname: ${{ steps.variables.outputs.package_fullname }}
|
||||||
package_directory: ${{ steps.variables.outputs.package_directory }}
|
package_directory: ${{ steps.variables.outputs.package_directory }}
|
||||||
|
package_version_file: ${{ steps.variables.outputs.package_version_file }}
|
||||||
artifact_basename: ${{ steps.variables.outputs.artifact_basename }}
|
artifact_basename: ${{ steps.variables.outputs.artifact_basename }}
|
||||||
artifact_names: ${{ steps.artifacts.outputs.artifact_names }}
|
artifact_names: ${{ steps.artifacts.outputs.artifact_names }}
|
||||||
python_jobs: ${{ steps.jobs.outputs.python_jobs }}
|
python_jobs: ${{ steps.jobs.outputs.python_jobs }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- name: ⏬ Checkout repository
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
with:
|
||||||
|
# The command 'git describe' (used for version) needs the history.
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Generate a startup delay of ${{ inputs.pipeline-delay }} seconds
|
- name: Generate a startup delay of ${{ inputs.pipeline-delay }} seconds
|
||||||
id: delay
|
id: delay
|
||||||
if: inputs.pipeline-delay >= 0
|
if: inputs.pipeline-delay >= 0
|
||||||
@@ -162,6 +177,7 @@ jobs:
|
|||||||
python_version = "${{ inputs.python_version }}".strip()
|
python_version = "${{ inputs.python_version }}".strip()
|
||||||
package_namespace = "${{ inputs.package_namespace }}".strip()
|
package_namespace = "${{ inputs.package_namespace }}".strip()
|
||||||
package_name = "${{ inputs.package_name }}".strip()
|
package_name = "${{ inputs.package_name }}".strip()
|
||||||
|
version_file = "${{ inputs.version_file }}".strip()
|
||||||
name = "${{ inputs.name }}".strip()
|
name = "${{ inputs.name }}".strip()
|
||||||
|
|
||||||
if package_namespace == "":
|
if package_namespace == "":
|
||||||
@@ -174,15 +190,27 @@ jobs:
|
|||||||
package_fullname = f"{package_namespace}.{package_name}"
|
package_fullname = f"{package_namespace}.{package_name}"
|
||||||
package_directory = f"{package_namespace}/{package_name}"
|
package_directory = f"{package_namespace}/{package_name}"
|
||||||
|
|
||||||
|
packageDirectory = Path(package_directory)
|
||||||
|
packageVersionFile = packageDirectory / version_file
|
||||||
|
print(f"Check if package version file '{packageVersionFile}' exists ... ", end="")
|
||||||
|
if packageVersionFile.exists():
|
||||||
|
print("✅")
|
||||||
|
package_version_file = packageVersionFile.as_posix()
|
||||||
|
else:
|
||||||
|
print("❌")
|
||||||
|
package_version_file = ""
|
||||||
|
print(f"::warning title=Parameters::Version file '{packageVersionFile}' not found.")
|
||||||
|
|
||||||
artifact_basename = package_fullname if name == "" else name
|
artifact_basename = package_fullname if name == "" else name
|
||||||
if artifact_basename == "" or artifact_basename == ".":
|
if artifact_basename == "" or artifact_basename == ".":
|
||||||
print("::error title=Parameter::artifact_basename is empty.")
|
print("::error title=Parameters::artifact_basename is empty.")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
print("Variables:")
|
print("Variables:")
|
||||||
print(f" python_version: {python_version}")
|
print(f" python_version: {python_version}")
|
||||||
print(f" package_fullname: {package_fullname}")
|
print(f" package_fullname: {package_fullname}")
|
||||||
print(f" package_directory: {package_directory}")
|
print(f" package_directory: {package_directory}")
|
||||||
|
print(f" package_version_file: {package_directory}")
|
||||||
print(f" artifact_basename: {artifact_basename}")
|
print(f" artifact_basename: {artifact_basename}")
|
||||||
|
|
||||||
# Write jobs to special file
|
# Write jobs to special file
|
||||||
@@ -193,6 +221,7 @@ jobs:
|
|||||||
python_version={python_version}
|
python_version={python_version}
|
||||||
package_fullname={package_fullname}
|
package_fullname={package_fullname}
|
||||||
package_directory={package_directory}
|
package_directory={package_directory}
|
||||||
|
package_version_file={package_version_file}
|
||||||
artifact_basename={artifact_basename}
|
artifact_basename={artifact_basename}
|
||||||
"""))
|
"""))
|
||||||
|
|
||||||
@@ -263,7 +292,7 @@ jobs:
|
|||||||
currentAlphaRelease = "3.15.0-a.1"
|
currentAlphaRelease = "3.15.0-a.1"
|
||||||
|
|
||||||
if systems == "":
|
if systems == "":
|
||||||
print("::error title=Parameter::system_list is empty.")
|
print("::error title=Parameters::system_list is empty.")
|
||||||
else:
|
else:
|
||||||
systems = [sys.strip() for sys in systems.split(" ")]
|
systems = [sys.strip() for sys in systems.split(" ")]
|
||||||
|
|
||||||
@@ -431,9 +460,10 @@ jobs:
|
|||||||
printf "python_version: %s\n" '${{ steps.variables.outputs.python_version }}'
|
printf "python_version: %s\n" '${{ steps.variables.outputs.python_version }}'
|
||||||
printf "package_fullname: %s\n" '${{ steps.variables.outputs.package_fullname }}'
|
printf "package_fullname: %s\n" '${{ steps.variables.outputs.package_fullname }}'
|
||||||
printf "package_directory: %s\n" '${{ steps.variables.outputs.package_directory }}'
|
printf "package_directory: %s\n" '${{ steps.variables.outputs.package_directory }}'
|
||||||
|
printf "package_version_file: %s\n" '${{ steps.variables.outputs.package_version_file }}'
|
||||||
printf "artifact_basename: %s\n" '${{ steps.variables.outputs.artifact_basename }}'
|
printf "artifact_basename: %s\n" '${{ steps.variables.outputs.artifact_basename }}'
|
||||||
printf "====================\n"
|
printf "================================================================================\n"
|
||||||
printf "artifact_names: %s\n" '${{ steps.artifacts.outputs.artifact_names }}'
|
printf "artifact_names: %s\n" '${{ steps.artifacts.outputs.artifact_names }}'
|
||||||
printf "====================\n"
|
printf "================================================================================\n"
|
||||||
printf "python_jobs: %s\n" '${{ steps.jobs.outputs.python_jobs }}'
|
printf "python_jobs: %s\n" '${{ steps.jobs.outputs.python_jobs }}'
|
||||||
printf "====================\n"
|
printf "================================================================================\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user