blob: 8e4e38553b89126e2688b9b290480d12dcb29303 (
plain)
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
name: Get Conan Recipe Version
on:
workflow_call:
inputs:
project_name:
required: true
type: string
outputs:
recipe_id_full:
description: "The full Conan recipe id: <name>/<version>@<user>/<channel>"
value: ${{ jobs.get-semver.outputs.recipe_id_full }}
recipe_id_latest:
description: "The full Conan recipe aliased (latest) id: <name>/(latest)@<user>/<channel>"
value: ${{ jobs.get-semver.outputs.recipe_id_latest }}
recipe_semver_full:
description: "The full semver <Major>.<Minor>.<Patch>-<PreReleaseTag>+<BuildMetaData>"
value: ${{ jobs.get-semver.outputs.semver_full }}
recipe_user:
description: "The conan user"
value: ${{ jobs.get-semver.outputs.user }}
recipe_channel:
description: "The conan channel"
value: ${{ jobs.get-semver.outputs.channel }}
jobs:
get-semver:
runs-on: ubuntu-latest
outputs:
recipe_id_full: ${{ steps.get-conan-broadcast-data.outputs.recipe_id_full }}
recipe_id_latest: ${{ steps.get-conan-broadcast-data.outputs.recipe_id_latest }}
semver_full: ${{ steps.get-conan-broadcast-data.outputs.semver_full }}
user: ${{ steps.get-conan-broadcast-data.outputs.user }}
channel: ${{ steps.get-conan-broadcast-data.outputs.channel }}
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Setup Python and pip
uses: actions/setup-python@v4
with:
python-version: "3.10.x"
cache: 'pip'
cache-dependency-path: .github/workflows/requirements-conan-package.txt
- name: Install Python requirements and Create default Conan profile
run: |
pip install -r .github/workflows/requirements-conan-package.txt
pip install gitpython
- id: get-conan-broadcast-data
name: Get Conan broadcast data
run: |
import subprocess
from conans import tools
from conans.errors import ConanException
from git import Repo
repo = Repo('.')
user = "${{ github.repository_owner }}"
project_name = "${{ inputs.project_name }}"
event_name = "${{ github.event_name }}"
issue_number = "${{ github.ref }}".split('/')[2]
is_tag = "${{ github.ref_type }}" == "tag"
# FIXME: for when we push a tag (such as an release)
if is_tag:
branch_version = tools.Version("2.3.5")
else:
try:
branch_version = tools.Version(repo.active_branch.name)
channel = "stable"
except ConanException:
branch_version = tools.Version('0.0.0')
if repo.active_branch.name == f"{branch_version.major}.{branch_version.minor}":
channel = 'stable'
elif repo.active_branch.name == "main" or repo.active_branch.name == "master":
channel = 'testing'
else:
channel = repo.active_branch.name.split("_")[0].replace("-", "_").lower()
if event_name == "pull_request":
channel = f"pr_{issue_number}"
# %% Get the actual version
latest_branch_version = tools.Version("0.0.0")
latest_branch_tag = None
for tag in repo.git.tag(merged = True).splitlines():
try:
version = tools.Version(tag)
except ConanException:
continue
if version > latest_branch_version:
latest_branch_version = version
latest_branch_tag = repo.tag(tag)
# %% Get the actual version
no_commits = 0
for commit in repo.iter_commits("HEAD"):
if commit == latest_branch_tag.commit:
break
no_commits += 1
if no_commits == 0:
# This is a release
actual_version = f"{latest_branch_version.major}.{latest_branch_version.minor}.{latest_branch_version.patch}"
if channel == "stable":
user = "_"
channel = "_"
else:
if event_name == "pull_request":
actual_version = f"{latest_branch_version.major}.{latest_branch_version.minor}.{latest_branch_version.patch}-{latest_branch_version.prerelease.lower()}+pr_{issue_number}_{no_commits}"
else:
if latest_branch_version.prerelease == "":
actual_version = f"{latest_branch_version.major}.{latest_branch_version.minor}.{latest_branch_version.patch}-alpha+{no_commits}"
else:
actual_version = f"{latest_branch_version.major}.{latest_branch_version.minor}.{latest_branch_version.patch}-{latest_branch_version.prerelease.lower()}+{no_commits}"
# %% print to output
cmd_name = ["echo", f"::set-output name=name::{project_name}"]
subprocess.call(cmd_name)
cmd_version = ["echo", f"::set-output name=version::{actual_version}"]
subprocess.call(cmd_version)
cmd_channel = ["echo", f"::set-output name=channel::{channel}"]
subprocess.call(cmd_channel)
cmd_id_full= ["echo", f"::set-output name=recipe_id_full::{project_name}/{actual_version}@{user}/{channel}"]
subprocess.call(cmd_id_full)
cmd_id_latest = ["echo", f"::set-output name=recipe_id_latest::{project_name}/latest@{user}/{channel}"]
subprocess.call(cmd_id_latest)
cmd_semver_full = ["echo", f"::set-output name=semver_full::{actual_version}"]
subprocess.call(cmd_semver_full)
print("::group::Conan Recipe Information")
print(f"name = {project_name}")
print(f"version = {actual_version}")
print(f"user = {user}")
print(f"channel = {channel}")
print(f"recipe_id_full = {project_name}/{actual_version}@{user}/{channel}")
print(f"recipe_id_latest = {project_name}/latest@{user}/{channel}")
print(f"semver_full = {actual_version}")
print("::endgroup::")
shell: python
|