diff options
author | j.spijker@ultimaker.com <jelle spijker> | 2022-07-12 11:55:05 +0300 |
---|---|---|
committer | jspijker <j.spijker@ultimaker.com> | 2022-07-12 11:55:05 +0300 |
commit | 36c4c56abb384a39e13b54d67b2f2a2a824f9910 (patch) | |
tree | 3a99f93de883d0b9d8523b5350485e24dc1e41df /.github | |
parent | 913d9b8ed7dc974afd50e5c6314857f1cd5522a1 (diff) |
Use custom versioning system
We already had to customize to much, it isn't worth
the effort to continue with GitVersion
The script still has some issues when a tag is pushed
Contributes to CURA-9365
Diffstat (limited to '.github')
-rw-r--r-- | .github/workflows/conan-recipe-version.yml | 171 | ||||
-rw-r--r-- | .github/workflows/requirements-conan-package.txt | 3 |
2 files changed, 106 insertions, 68 deletions
diff --git a/.github/workflows/conan-recipe-version.yml b/.github/workflows/conan-recipe-version.yml index dd30e8807a..a69b1206e0 100644 --- a/.github/workflows/conan-recipe-version.yml +++ b/.github/workflows/conan-recipe-version.yml @@ -10,15 +10,23 @@ on: outputs: recipe_id_full: description: "The full Conan recipe id: <name>/<version>@<user>/<channel>" - value: ${{ jobs.get-semver.outputs.recipe_id_full }} + value: ${{ jobs.get-conan-broadcast-data.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 }} + value: ${{ jobs.get-conan-broadcast-data.outputs.recipe_id_latest }} recipe_semver_full: description: "The full semver <Major>.<Minor>.<Patch>-<PreReleaseTag>+<BuildMetaData>" - value: ${{ jobs.get-semver.outputs.semver_full }} + value: ${{ jobs.get-conan-broadcast-data.outputs.semver_full }} + + recipe_user: + description: "The conan user" + value: ${{ jobs.get-conan-broadcast-data.outputs.user }} + + recipe_channel: + description: "The conan channel" + value: ${{ jobs.get-conan-broadcast-data.outputs.channel }} jobs: get-semver: @@ -26,10 +34,9 @@ jobs: runs-on: ubuntu-latest outputs: - recipe_id_full: ${{ inputs.project_name }}/${{ steps.get-conan-broadcast-data.outputs.version }}@${{ steps.get-conan-broadcast-data.outputs.user }}/${{ steps.get-conan-broadcast-data.outputs.channel }} - recipe_id_latest: ${{ steps.latest-alias.outputs.recipe_id_latest }} - recipe_id_pr: ${{ steps.pr-alias.outputs.recipe_id_pr }} - semver_full: ${{ steps.get-conan-broadcast-data.outputs.version }} + 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 }} @@ -40,69 +47,99 @@ jobs: ref: ${{ github.head_ref }} fetch-depth: 0 - - name: Install GitVersion - uses: gittools/actions/gitversion/setup@v0.9.13 + - name: Setup Python and pip + uses: actions/setup-python@v4 with: - versionSpec: '5.x' + python-version: "3.10.x" + cache: 'pip' + cache-dependency-path: .github/workflows/requirements-conan-package.txt - - name: GitTools - id: git-tool - uses: gittools/actions/gitversion/execute@v0.9.13 + - name: Install Python requirements and Create default Conan profile + run: pip install -r .github/workflows/requirements-conan-package.txt - id: get-conan-broadcast-data name: Get Conan broadcast data run: | - if [ "${{ github.ref_type == 'tag' && github.ref_name == '${{ steps.git-tool.outputs.Major }}.${{ steps.git-tool.outputs.Minor }}.${{ steps.git-tool.outputs.Patch }}' }}" = "true" ]; then - # tagged commits on a release branch matching the major.minor.patch are actual released version and should have no user and channel - # name/major.minor.patch@_/_ - echo '::set-output name=user::_' - echo '::set-output name=channel::_' - echo '::set-output name=version::${{ steps.git-tool.outputs.Major }}.${{ steps.git-tool.outputs.Minor }}.${{ steps.git-tool.outputs.Patch }}' - elif [ "${{ github.ref_type == 'tag' && github.ref_name == '${{ steps.git-tool.outputs.Major }}.${{ steps.git-tool.outputs.Minor }}.${{ steps.git-tool.outputs.Patch }}-BETA' }}" = "true" ]; then - # tagged commits with major.minor.patch-BETA on a release branch are actual released version and should have no user and channel - # name/major.minor.patch-beta@_/_ - echo '::set-output name=user::_' - echo '::set-output name=channel::_' - echo '::set-output name=version::${{ steps.git-tool.outputs.Major }}.${{ steps.git-tool.outputs.Minor }}.${{ steps.git-tool.outputs.Patch }}-${{ steps.git-tool.outputs.PreReleaseLabel }}' - elif [ "${{ github.ref_name == 'main' || github.ref_name == 'master' }}" = "true" ]; then - # commits on main/master are alpha's (nightlies) and are considered testing - # name/major.minor.patch-alpha+build@ultimaker/testing - echo ${{ github.repository_owner }} | awk '{print "::set-output name=user::"tolower($0)}' - echo '::set-output name=channel::testing' - echo '::set-output name=version::${{ steps.git-tool.outputs.Major }}.${{ steps.git-tool.outputs.Minor }}.${{ steps.git-tool.outputs.Patch }}-${{ steps.git-tool.outputs.PreReleaseLabel }}+${{ steps.git-tool.outputs.BuildMetaData }}' - elif [ "${{ github.ref_name == '5.1' }}" = "true" ]; then - # commits on release branches are beta's and are considered stable - # name/major.minor.patch-beta+build@ultimaker/stable - # FIXME: For release branches: maybe rename the branch to release/** - echo ${{ github.repository_owner }} | awk '{print "::set-output name=user::"tolower($0)}' - echo '::set-output name=channel::stable' - echo '::set-output name=version::${{ steps.git-tool.outputs.Major }}.${{ steps.git-tool.outputs.Minor }}.${{ steps.git-tool.outputs.Patch }}-${{ steps.git-tool.outputs.PreReleaseLabel }}+${{ steps.git-tool.outputs.BuildMetaData }}' - else - # commits on other branches are considered unstable and for development purposes only - # Use the Cura branch naming scheme CURA-1234_foo_bar - # we use the first 9 characters of the branch name - # name/major.minor.patch-beta+build@ultimaker/cura_<jira_number> - echo ${{ github.repository_owner }} | awk '{print "::set-output name=user::"tolower($0)}' - branch=${{ github.ref_name }} - sanitized_branch="${branch//-/_}" - echo $sanitized_branch | awk '{print "::set-output name=channel::"substr(tolower($0),0,9)}' - echo '::set-output version=${{ steps.git-tool.outputs.Major }}.${{ steps.git-tool.outputs.Minor }}.${{ steps.git-tool.outputs.Patch }}-${{ steps.git-tool.outputs.PreReleaseLabel }}+${{ steps.git-tool.outputs.BuildMetaData }}' - fi - - - name: Get pull request alias - id: pr-alias - run: | - if [ "${{ github.event_name == 'pull_request' }}" = "true" ]; then - # pull request events are considered unstable and are for testing purposes - # name/latest@ultimaker/pr_<number> - echo "::set-output name=recipe_id_pr::${{ inputs.project_name }}/latest@${{ steps.get-conan-broadcast-data.outputs.user }}/pr_$PR_NUMBER" - else - echo "::set-output name=recipe_id_pr::''" - fi - env: - PR_NUMBER: ${{ github.event.issue.number }} - - - name: Get latest alias - id: latest-alias - run: | - echo "::set-output name=recipe_id_latest::${{ inputs.project_name }}/latest@${{ steps.get-conan-broadcast-data.outputs.user }}/${{ steps.get-conan-broadcast-data.outputs.channel }}" + from conans import tools + from conans.errors import ConanException + from git import Repo + + repo = Repo('.') + user = "${{ github.repository_owner }}" + project_name = "test" + event_name = "${{ github.event_name }}" + issue_number = "${{ github.event.issue.number }}" + 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("_").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 + print(f"::set-output name=name::{project_name}") + print(f"::set-output name=version::{actual_version}") + print(f"::set-output name=user::{user}") + print(f"::set-output name=channel::{channel}") + print(f"::set-output name=recipe_id_full::{project_name}/{actual_version}@{user}/{channel}") + print(f"::set-output name=recipe_id_latest::{project_name}/latest@{user}/{channel}") + print(f"::set-output name=semver_full::{actual_version}") + + 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 diff --git a/.github/workflows/requirements-conan-package.txt b/.github/workflows/requirements-conan-package.txt index 674ef437c2..41fa67dd16 100644 --- a/.github/workflows/requirements-conan-package.txt +++ b/.github/workflows/requirements-conan-package.txt @@ -1,2 +1,3 @@ conan -sip==6.5.1
\ No newline at end of file +sip==6.5.1 +gitpython |