conan-recipe-version.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. name: Get Conan Recipe Version
  2. on:
  3. workflow_call:
  4. inputs:
  5. project_name:
  6. required: true
  7. type: string
  8. additional_buildmetadata:
  9. required: false
  10. default: ""
  11. type: string
  12. outputs:
  13. recipe_id_full:
  14. description: "The full Conan recipe id: <name>/<version>@<user>/<channel>"
  15. value: ${{ jobs.get-semver.outputs.recipe_id_full }}
  16. recipe_id_latest:
  17. description: "The full Conan recipe aliased (latest) id: <name>/(latest)@<user>/<channel>"
  18. value: ${{ jobs.get-semver.outputs.recipe_id_latest }}
  19. recipe_semver_full:
  20. description: "The full semver <Major>.<Minor>.<Patch>-<PreReleaseTag>+<BuildMetaData>"
  21. value: ${{ jobs.get-semver.outputs.semver_full }}
  22. is_release_branch:
  23. description: "is current branch a release branch?"
  24. value: ${{ jobs.get-semver.outputs.release_branch }}
  25. recipe_user:
  26. description: "The conan user"
  27. value: ${{ jobs.get-semver.outputs.user }}
  28. recipe_channel:
  29. description: "The conan channel"
  30. value: ${{ jobs.get-semver.outputs.channel }}
  31. jobs:
  32. get-semver:
  33. runs-on: ubuntu-latest
  34. outputs:
  35. recipe_id_full: ${{ steps.get-conan-broadcast-data.outputs.recipe_id_full }}
  36. recipe_id_latest: ${{ steps.get-conan-broadcast-data.outputs.recipe_id_latest }}
  37. semver_full: ${{ steps.get-conan-broadcast-data.outputs.semver_full }}
  38. is_release_branch: ${{ steps.get-conan-broadcast-data.outputs.is_release_branch }}
  39. user: ${{ steps.get-conan-broadcast-data.outputs.user }}
  40. channel: ${{ steps.get-conan-broadcast-data.outputs.channel }}
  41. steps:
  42. - name: Checkout repo
  43. uses: actions/checkout@v3
  44. if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
  45. with:
  46. fetch-depth: 0
  47. ref: ${{ github.head_ref }}
  48. - name: Checkout repo PR
  49. uses: actions/checkout@v3
  50. if: ${{ github.event.pull_request.head.repo.full_name != github.repository }}
  51. with:
  52. fetch-depth: 0
  53. ref: ${{ github.event.pull_request.head.ref }}
  54. repository: ${{ github.event.pull_request.head.repo.full_name }}
  55. - name: Setup Python and pip
  56. uses: actions/setup-python@v4
  57. with:
  58. python-version: "3.10.x"
  59. cache: 'pip'
  60. cache-dependency-path: .github/workflows/requirements-conan-package.txt
  61. - name: Install Python requirements and Create default Conan profile
  62. run: |
  63. pip install -r .github/workflows/requirements-conan-package.txt
  64. pip install gitpython
  65. - id: get-conan-broadcast-data
  66. name: Get Conan broadcast data
  67. run: |
  68. import subprocess
  69. from conans import tools
  70. from conans.errors import ConanException
  71. from git import Repo
  72. repo = Repo('.')
  73. user = "${{ github.repository_owner }}".lower()
  74. project_name = "${{ inputs.project_name }}"
  75. event_name = "${{ github.event_name }}"
  76. issue_number = "${{ github.ref }}".split('/')[2]
  77. is_tag = "${{ github.ref_type }}" == "tag"
  78. is_release_branch = False
  79. buildmetadata = "" if "${{ inputs.additional_buildmetadata }}" == "" else "${{ inputs.additional_buildmetadata }}_"
  80. # FIXME: for when we push a tag (such as an release)
  81. channel = "testing"
  82. if is_tag:
  83. branch_version = tools.Version("${{ github.ref_name }}")
  84. is_release_branch = True
  85. channel = "_"
  86. user = "_"
  87. actual_version = f"{branch_version}"
  88. else:
  89. try:
  90. branch_version = tools.Version(repo.active_branch.name)
  91. except ConanException:
  92. branch_version = tools.Version('0.0.0')
  93. if "${{ github.ref_name }}" == f"{branch_version.major}.{branch_version.minor}":
  94. channel = 'stable'
  95. is_release_branch = True
  96. elif "${{ github.ref_name }}" in ("main", "master"):
  97. channel = 'testing'
  98. else:
  99. channel = repo.active_branch.name.split("_")[0].replace("-", "_").lower()
  100. if "pull_request" in event_name:
  101. channel = f"pr_{issue_number}"
  102. # %% Get the actual version
  103. latest_branch_version = tools.Version("0.0.0")
  104. latest_branch_tag = None
  105. for tag in repo.git.tag(merged = True).splitlines():
  106. if str(tag).startswith("firmware") or str(tag).startswith("master"):
  107. continue # Quick-fix for the versioning scheme name of the embedded team in fdm_materials(_private) repo
  108. try:
  109. version = tools.Version(tag)
  110. except ConanException:
  111. continue
  112. if version > latest_branch_version:
  113. latest_branch_version = version
  114. latest_branch_tag = repo.tag(tag)
  115. if latest_branch_tag:
  116. # %% Get the actual version
  117. no_commits = 0
  118. for commit in repo.iter_commits("HEAD"):
  119. if commit == latest_branch_tag.commit:
  120. break
  121. no_commits += 1
  122. latest_branch_version_prerelease = latest_branch_version.prerelease
  123. if latest_branch_version.prerelease and not "." in latest_branch_version.prerelease:
  124. # The prerealese did not contain a version number, default it to 1
  125. latest_branch_version_prerelease = f"{latest_branch_version.prerelease}.1"
  126. if event_name == "pull_request":
  127. actual_version = f"{latest_branch_version.major}.{latest_branch_version.minor}.{latest_branch_version.patch}-{latest_branch_version_prerelease.lower()}+{buildmetadata}pr_{issue_number}_{no_commits}"
  128. channel_metadata = f"{channel}_{no_commits}"
  129. else:
  130. if channel in ("stable", "_", ""):
  131. channel_metadata = f"{no_commits}"
  132. else:
  133. channel_metadata = f"{channel}_{no_commits}"
  134. if is_release_branch:
  135. if latest_branch_version.prerelease == "":
  136. # An actual full release has been created, we are working on patch
  137. bump_up_patch = int(latest_branch_version.patch) + 1
  138. actual_version = f"{latest_branch_version.major}.{latest_branch_version.minor}.{bump_up_patch}-beta.1+{buildmetadata}{channel_metadata}"
  139. else:
  140. # An beta release has been created we are working toward a next beta or full release
  141. bump_up_release_tag = int(latest_branch_version.prerelease.split('.')[1]) + 1
  142. actual_version = f"{latest_branch_version.major}.{latest_branch_version.minor}.{latest_branch_version.patch}-{latest_branch_version.prerelease.split('.')[0]}.{bump_up_release_tag}+{buildmetadata}{channel_metadata}"
  143. else:
  144. bump_up_minor = int(latest_branch_version.minor) + 1
  145. reset_patch = 0
  146. actual_version = f"{latest_branch_version.major}.{bump_up_minor}.{reset_patch}-alpha+{buildmetadata}{channel_metadata}"
  147. else:
  148. # FIXME: for external PR's
  149. actual_version = f"5.3.0-alpha+{buildmetadata}pr_{issue_number}"
  150. if is_tag and "${{ github.ref_name }}" == "5.2.0-beta":
  151. actual_version = "5.2.0-beta"
  152. is_release_branch = True
  153. user = "_"
  154. channel = "_"
  155. # %% print to output
  156. cmd_name = ["echo", f"::set-output name=name::{project_name}"]
  157. subprocess.call(cmd_name)
  158. cmd_version = ["echo", f"::set-output name=version::{actual_version}"]
  159. subprocess.call(cmd_version)
  160. cmd_channel = ["echo", f"::set-output name=channel::{channel}"]
  161. subprocess.call(cmd_channel)
  162. cmd_id_full= ["echo", f"::set-output name=recipe_id_full::{project_name}/{actual_version}@{user}/{channel}"]
  163. subprocess.call(cmd_id_full)
  164. cmd_id_latest = ["echo", f"::set-output name=recipe_id_latest::{project_name}/latest@{user}/{channel}"]
  165. subprocess.call(cmd_id_latest)
  166. cmd_semver_full = ["echo", f"::set-output name=semver_full::{actual_version}"]
  167. subprocess.call(cmd_semver_full)
  168. cmd_is_release_branch = ["echo", f"::set-output name=is_release_branch::{str(is_release_branch).lower()}"]
  169. subprocess.call(cmd_is_release_branch)
  170. print("::group::Conan Recipe Information")
  171. print(f"name = {project_name}")
  172. print(f"version = {actual_version}")
  173. print(f"user = {user}")
  174. print(f"channel = {channel}")
  175. print(f"= {project_name}/{actual_version}@{user}/{channel}")
  176. print(f"recipe_id_latest = {project_name}/latest@{user}/{channel}")
  177. print(f"semver_full = {actual_version}")
  178. print(f"is_release_branch = {str(is_release_branch).lower()}")
  179. print("::endgroup::")
  180. shell: python