48 lines
1.3 KiB
Python
Executable File
48 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import sys
|
|
|
|
import requests
|
|
import semver
|
|
|
|
|
|
def start_pre_release_build():
|
|
gitlab_project_id = os.environ["CI_PROJECT_ID"]
|
|
api_token = os.environ["CISCRIPT_API_TOKEN"]
|
|
branch = os.environ["CI_COMMIT_BRANCH"]
|
|
print(f"branch '{branch}'")
|
|
major_version = minor_version = 0
|
|
patch_version = int(os.environ["CI_PIPELINE_ID"])
|
|
commit_short_sha = os.environ["CI_COMMIT_SHORT_SHA"]
|
|
future_version = str(
|
|
semver.VersionInfo(
|
|
major=major_version,
|
|
minor=minor_version,
|
|
patch=patch_version,
|
|
prerelease="beta",
|
|
build=commit_short_sha,
|
|
)
|
|
)
|
|
future_tag_name = f"v{future_version}"
|
|
print(f"future tag name '{future_tag_name}'")
|
|
response = requests.post(
|
|
(
|
|
f"https://gitlab.princip.cz/"
|
|
f"api/v4/projects/{gitlab_project_id}/repository/tags"
|
|
),
|
|
headers={"PRIVATE-TOKEN": api_token},
|
|
params={"tag_name": future_tag_name, "ref": branch},
|
|
)
|
|
if response.status_code == 201:
|
|
print(f"tag '{future_tag_name}' created")
|
|
else:
|
|
sys.exit(
|
|
f"error creating tag '{future_tag_name}', "
|
|
f"status code '{response.status_code}', json '{response.json()}'"
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
start_pre_release_build()
|