Compare commits
61 Commits
Author | SHA1 | Date | |
---|---|---|---|
494a402cdf
|
|||
2e4ae7c984
|
|||
80a17bd258
|
|||
6978c11d02
|
|||
678a81a116
|
|||
5c0254c036
|
|||
695450cfb9
|
|||
59f2add5c7
|
|||
9ba66614ec
|
|||
e9f61e6b52
|
|||
d65ec75d94
|
|||
7a591afe21
|
|||
fee7aaaedb
|
|||
41ba33d5a7
|
|||
f82156d2f1
|
|||
7f7c75e983
|
|||
ce41933381
|
|||
6f105a6a12
|
|||
7abbecd28c
|
|||
0331672f92
|
|||
051cbfecfb
|
|||
495ff5c51e
|
|||
0df2400892
|
|||
47621f90c0
|
|||
0897d76fdc | |||
34a7ad2f10 | |||
b564ad15aa | |||
7969a8259e | |||
8acddeb2cf | |||
adae5638d3 | |||
b66ca744ae | |||
f72c8b115f | |||
1b05213466
|
|||
f3f62d5cf5
|
|||
e5967bb726
|
|||
d194562474
|
|||
e87741bedb
|
|||
c64effea3b
|
|||
cb94e9e017
|
|||
0e8823bba1
|
|||
5fd785a826
|
|||
3ea721a4e7
|
|||
fdc5e97fc2 | |||
79dba02090
|
|||
b9663f82d3 | |||
bde034ba7a
|
|||
3e09e510da
|
|||
131ab9e789
|
|||
255ff55cee
|
|||
bb0c14b39f
|
|||
1ffba72b6b
|
|||
af6b41a0ae
|
|||
26a8759919
|
|||
62c3f0e00f
|
|||
dff4090678
|
|||
0c8e75e82e
|
|||
715c984e40
|
|||
9d348117f8
|
|||
81966c095c
|
|||
23cfe0f6ea
|
|||
b4efe0d259
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.pyc
|
29
.gitlab-ci.yml
Normal file
29
.gitlab-ci.yml
Normal file
@ -0,0 +1,29 @@
|
||||
stages:
|
||||
- check
|
||||
- release
|
||||
|
||||
build:
|
||||
stage: check
|
||||
image: registry.hottis.de/dockerized/base-build-env:latest
|
||||
tags:
|
||||
- hottis
|
||||
- linux
|
||||
- docker
|
||||
script:
|
||||
- for I in *.py; do python -m py_compile $I; done
|
||||
- for I in *.py; do python -m pycodestyle --ignore=E501 $I; done
|
||||
|
||||
release:
|
||||
stage: release
|
||||
image: registry.hottis.de/dockerized/base-build-env:latest
|
||||
tags:
|
||||
- hottis
|
||||
- linux
|
||||
- docker
|
||||
only:
|
||||
- release
|
||||
script:
|
||||
- zip GitlabReleaseTool.zip gitlabreleaseuploader.py deleterelease.py checksemver.py
|
||||
- python gitlabreleaseuploader.py -p $PRIVATE_TOKEN -i $CI_PROJECT_ID -u $CI_PROJECT_URL -I $CI_SERVER_URL
|
||||
-f GitlabReleaseTool.zip -F info.json -T $CI_COMMIT_SHA
|
||||
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019-2020 Wolfgang Hottgenroth
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
80
checksemver.py
Normal file
80
checksemver.py
Normal file
@ -0,0 +1,80 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import re
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
parser = argparse.ArgumentParser(description='Semantic Version Validator')
|
||||
parser.add_argument('--versionToValidate', '-V',
|
||||
help='The version to validate against the semantic versioning rules',
|
||||
required=True)
|
||||
parser.add_argument('--messageToValidate', '-M',
|
||||
help='A message to validate, means: it must not be empty',
|
||||
default='',
|
||||
required=False)
|
||||
parser.add_argument('--validateMessage', '-m',
|
||||
help='Consider -M',
|
||||
required=False,
|
||||
action='store_true',
|
||||
default=False)
|
||||
parser.add_argument('--printExports', '-e',
|
||||
help='Print exports',
|
||||
action='store_true',
|
||||
default=False,
|
||||
required=False)
|
||||
parser.add_argument('--exportFormat', '-f',
|
||||
help='Print exports in >bash< or >powershell< format, to be used in '
|
||||
'backticks or with Invoke-Expression',
|
||||
default='bash',
|
||||
required=False)
|
||||
parser.add_argument('--verbose', '-v',
|
||||
help='Verbose output, overrides -q',
|
||||
required=False,
|
||||
action='store_true',
|
||||
default=False)
|
||||
args = parser.parse_args()
|
||||
|
||||
verbose = args.verbose
|
||||
versionToValidate = args.versionToValidate
|
||||
messageToValidate = args.messageToValidate
|
||||
validateMessage = args.validateMessage
|
||||
printExports = args.printExports
|
||||
exportFormat = args.exportFormat
|
||||
|
||||
r = re.compile(r'^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$')
|
||||
|
||||
if verbose:
|
||||
print("Version to validate: {}".format(versionToValidate))
|
||||
|
||||
m = r.match(versionToValidate)
|
||||
|
||||
if m:
|
||||
if verbose:
|
||||
for i in r.groupindex:
|
||||
print("Found: {}: {}".format(i, m.group(i)))
|
||||
if validateMessage:
|
||||
if verbose:
|
||||
print("Checking message {}".format(messageToValidate))
|
||||
if messageToValidate == '':
|
||||
if verbose:
|
||||
print("Message shall be validate and is invalid")
|
||||
sys.exit(1)
|
||||
else:
|
||||
if printExports:
|
||||
if exportFormat == "bash":
|
||||
print("export MESSAGE={}".format(messageToValidate))
|
||||
elif exportFormat == "powershell":
|
||||
print("set MESSAGE {}".format(messageToValidate))
|
||||
|
||||
if printExports:
|
||||
for i in r.groupindex:
|
||||
if exportFormat == "bash":
|
||||
print("export {}={}".format(i.upper(), '' if m.group(i) is None else m.group(i)))
|
||||
elif exportFormat == "powershell":
|
||||
print("set {} {}".format(i.upper(), '""' if m.group(i) is None else m.group(i)))
|
||||
|
||||
sys.exit(0)
|
||||
else:
|
||||
if verbose:
|
||||
print("Version is invalid")
|
||||
sys.exit(1)
|
66
deleterelease.py
Normal file
66
deleterelease.py
Normal file
@ -0,0 +1,66 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import requests
|
||||
import json
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description='Gitlab Release Deleter')
|
||||
parser.add_argument('--privateToken', '-p',
|
||||
help='Private token to access Gitlab', required=True)
|
||||
parser.add_argument('--projectId', '-i',
|
||||
help='ProjectID of the related project', required=True)
|
||||
parser.add_argument('--releaseTag', '-t',
|
||||
help='Tag of the release in the repo',
|
||||
required=True,
|
||||
default='')
|
||||
parser.add_argument('--instanceUrl', '-I',
|
||||
help='URL of your gitlab instance', required=False,
|
||||
default='https://gitlab.com')
|
||||
parser.add_argument('--verbose', '-v',
|
||||
help='verbose output',
|
||||
required=False,
|
||||
action='store_true',
|
||||
default=False)
|
||||
parser.add_argument('--caBundle', '-B',
|
||||
help='File with the CA certificates to trust', required=False,
|
||||
default='/etc/ssl/certs/ca-certificates.crt')
|
||||
parser.add_argument('--insecure',
|
||||
help='insecure ssl connect',
|
||||
required=False,
|
||||
action='store_true',
|
||||
default=False)
|
||||
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
privateToken = args.privateToken
|
||||
projectId = args.projectId
|
||||
releaseTag = args.releaseTag
|
||||
instanceUrl = args.instanceUrl
|
||||
verbose = args.verbose
|
||||
caBundle = args.caBundle
|
||||
insecure = args.insecure
|
||||
|
||||
# --- delete release
|
||||
deleteReleaseUrl = "%s/api/v4/projects/%s/releases/%s" % (instanceUrl, projectId, releaseTag)
|
||||
headers = {"PRIVATE-TOKEN": privateToken, "Content-Type": "application/json"}
|
||||
|
||||
if verbose:
|
||||
print("URL: %s" % deleteReleaseUrl)
|
||||
|
||||
if insecure:
|
||||
caBundle = (False)
|
||||
|
||||
deleteReleaseResult = requests.delete(deleteReleaseUrl, headers=headers, verify=caBundle)
|
||||
|
||||
if deleteReleaseResult.status_code != 200:
|
||||
print(deleteReleaseResult)
|
||||
print(deleteReleaseResult.text)
|
||||
raise Exception('Unable to delete release')
|
||||
|
||||
if verbose:
|
||||
print(deleteReleaseResult)
|
||||
print(deleteReleaseResult.text)
|
||||
print('Release successfully delete')
|
269
gitlabreleaseuploader.py
Normal file → Executable file
269
gitlabreleaseuploader.py
Normal file → Executable file
@ -1,69 +1,260 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import requests
|
||||
import json
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description='Gitlab Release Uploader')
|
||||
parser.add_argument('--privateToken', '-p', help='Private token to access Gitlab', required=True)
|
||||
parser.add_argument('--projectId', '-i', help='ProjectID of the related project', required=True)
|
||||
parser.add_argument('--projectUrl', '-u', help='URL of the related project at Gitlab', required=True)
|
||||
parser.add_argument('--file', '-f', help='File to be released', required=True)
|
||||
parser.add_argument('--releaseName', '-n', help='Name of the release', required=True)
|
||||
parser.add_argument('--releaseTag', '-t', help='Tag of the release in the repo, make sure it already exists', required=True)
|
||||
parser.add_argument('--description', '-d', help='Description of the release', required=True)
|
||||
parser.add_argument('--privateToken', '-p',
|
||||
help='Private token to access Gitlab', required=True)
|
||||
parser.add_argument('--projectId', '-i',
|
||||
help='ProjectID of the related project', required=True)
|
||||
parser.add_argument('--projectUrl', '-u',
|
||||
help='URL of the related project at Gitlab', required=True)
|
||||
parser.add_argument('--file', '-f',
|
||||
help='File to be released, can appear multiple times',
|
||||
action='append',
|
||||
required=False)
|
||||
parser.add_argument('--releaseName', '-n',
|
||||
help='Name of the release', required=False,
|
||||
default='')
|
||||
parser.add_argument('--createRelease', '-C',
|
||||
help='Shall the release be created here',
|
||||
required=False,
|
||||
action='store_true',
|
||||
default=False)
|
||||
parser.add_argument('--releaseTag', '-t',
|
||||
help='Tag of the release in the repo',
|
||||
required=False,
|
||||
default='')
|
||||
parser.add_argument('--releaseTagTarget', '-T',
|
||||
help='Commit or branch the tag should point to',
|
||||
required=False,
|
||||
default='')
|
||||
parser.add_argument('--createReleaseTag', '-c',
|
||||
help='Shall the release tag be created here',
|
||||
required=False,
|
||||
action='store_true',
|
||||
default=False)
|
||||
parser.add_argument('--description', '-d',
|
||||
help='Description of the release', required=False,
|
||||
default='')
|
||||
parser.add_argument('--releaseInfoFile', '-F',
|
||||
help='File containing JSON object with release info '
|
||||
'(release tag, create release tag, description',
|
||||
required=False,
|
||||
default='')
|
||||
parser.add_argument('--instanceUrl', '-I',
|
||||
help='URL of your gitlab instance', required=False,
|
||||
default='https://gitlab.com')
|
||||
parser.add_argument('--caBundle', '-B',
|
||||
help='File with the CA certificates to trust', required=False,
|
||||
default='/etc/ssl/certs/ca-certificates.crt')
|
||||
parser.add_argument('--insecure',
|
||||
help='insecure ssl connect',
|
||||
required=False,
|
||||
action='store_true',
|
||||
default=False)
|
||||
parser.add_argument('--verbose', '-v',
|
||||
help='verbose output',
|
||||
required=False,
|
||||
action='store_true',
|
||||
default=False)
|
||||
args = parser.parse_args()
|
||||
print(args)
|
||||
|
||||
privateToken = args.privateToken
|
||||
projectId = args.projectId
|
||||
projectUrl = args.projectUrl
|
||||
fileToUpload = args.file
|
||||
filesToUpload = args.file
|
||||
releaseName = args.releaseName
|
||||
createRelease = args.createRelease
|
||||
releaseTag = args.releaseTag
|
||||
releaseTagTarget = args.releaseTagTarget
|
||||
releaseDescription = args.description
|
||||
instanceUrl = args.instanceUrl
|
||||
createReleaseTag = args.createReleaseTag
|
||||
releaseInfoFilename = args.releaseInfoFile
|
||||
caBundle = args.caBundle
|
||||
verbose = args.verbose
|
||||
insecure = args.insecure
|
||||
|
||||
releaseInfo = {}
|
||||
if (releaseInfoFilename):
|
||||
with open(releaseInfoFilename, 'r') as releaseInfoFile:
|
||||
releaseInfo = releaseInfoFile.read()
|
||||
releaseInfo = json.loads(releaseInfo)
|
||||
if 'releaseName' in releaseInfo:
|
||||
releaseName = releaseInfo['releaseName']
|
||||
if 'createRelease' in releaseInfo:
|
||||
createRelease = (releaseInfo['createRelease'] in
|
||||
('true', 'True'))
|
||||
if 'releaseTag' in releaseInfo:
|
||||
releaseTag = releaseInfo['releaseTag']
|
||||
if 'releaseTagTarget' in releaseInfo:
|
||||
releaseTagTarget = releaseInfo['releaseTagTarget']
|
||||
if 'createReleaseTag' in releaseInfo:
|
||||
createReleaseTag = (releaseInfo['createReleaseTag'] in
|
||||
('true', 'True'))
|
||||
if 'description' in releaseInfo:
|
||||
releaseDescription = releaseInfo['description']
|
||||
|
||||
if releaseName == '':
|
||||
raise Exception('No release name given')
|
||||
if releaseTag == '':
|
||||
raise Exception('No release tag given')
|
||||
if (releaseTagTarget == '') and createReleaseTag:
|
||||
raise Exception('No release tag target given but creation of tag requested')
|
||||
if (releaseDescription == '') and createRelease:
|
||||
raise Exception('No release description given but creation of release requested')
|
||||
|
||||
if insecure:
|
||||
caBundle = (False)
|
||||
|
||||
|
||||
def checkAndShowResult(result, expectedCode, errorMessage):
|
||||
global verbose
|
||||
|
||||
uploadUrl = "https://gitlab.com/api/v4/projects/%s/uploads" % projectId
|
||||
createReleaseUrl = "https://gitlab.com/api/v4/projects/%s/releases" % projectId
|
||||
if result.status_code != expectedCode:
|
||||
print(result)
|
||||
print(result.text)
|
||||
raise Exception(errorMessage)
|
||||
|
||||
if verbose:
|
||||
print(result)
|
||||
print(result.text)
|
||||
|
||||
|
||||
# --- upload the file
|
||||
assets = [] # is required later, must be defined
|
||||
if filesToUpload:
|
||||
url = "%s/api/v4/projects/%s/uploads" % (instanceUrl, projectId)
|
||||
headers = {"PRIVATE-TOKEN": privateToken}
|
||||
|
||||
files = {"file": open(fileToUpload, 'rb')}
|
||||
for filename in filesToUpload:
|
||||
with open(filename, 'rb') as filehandle:
|
||||
files = {"file": filehandle}
|
||||
|
||||
uploadResult = requests.post(uploadUrl, files=files, headers=headers)
|
||||
print(uploadResult)
|
||||
print(uploadResult.text)
|
||||
if uploadResult.status_code != 201:
|
||||
raise Exception('Unable to upload file to Gitlab')
|
||||
if verbose:
|
||||
print("POST to {}".format(url))
|
||||
result = requests.post(url, files=files, headers=headers, verify=caBundle)
|
||||
|
||||
checkAndShowResult(result, 201, 'Unable to upload file to Gitlab')
|
||||
|
||||
uploadResultJson = json.loads(uploadResult.text)
|
||||
assetUrl = projectUrl + json.loads(result.text)['url']
|
||||
assets.append({'name': filename, 'url': assetUrl, 'id': "new-link-{}".format(len(assets))})
|
||||
|
||||
fullUrl = projectUrl + uploadResultJson['url']
|
||||
|
||||
payloadCreateRelease = {
|
||||
"name": releaseName,
|
||||
"tag_name": releaseTag,
|
||||
"description": releaseDescription,
|
||||
"assets": {
|
||||
"links": [
|
||||
{
|
||||
"name": fileToUpload,
|
||||
"url": fullUrl
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
print('File {} successfully uploaded, url is {}'.format(filename, assetUrl))
|
||||
|
||||
# --- create release tag
|
||||
if createReleaseTag:
|
||||
url = "%s/api/v4//projects/%s/repository/tags" % (instanceUrl, projectId)
|
||||
headers = {"PRIVATE-TOKEN": privateToken, "Content-Type": "application/json"}
|
||||
|
||||
createReleaseResult = requests.post(createReleaseUrl, headers=headers, data=json.dumps(payloadCreateRelease))
|
||||
print(createReleaseResult)
|
||||
print(createReleaseResult.text)
|
||||
if createReleaseResult.status_code != 201:
|
||||
raise Exception('Unable to create release')
|
||||
payload = {
|
||||
"tag_name": releaseTag,
|
||||
"id": projectId,
|
||||
"ref": releaseTagTarget,
|
||||
"message": "Tag for release %s" % releaseName
|
||||
}
|
||||
|
||||
if verbose:
|
||||
print("POST to {}".format(url))
|
||||
result = requests.post(url, headers=headers, data=json.dumps(payload), verify=caBundle)
|
||||
|
||||
checkAndShowResult(result, 201, 'Unable to create release tag')
|
||||
|
||||
print('Tag successfully created')
|
||||
|
||||
|
||||
# --- create release
|
||||
if createRelease:
|
||||
url = "%s/api/v4/projects/%s/releases" % (instanceUrl, projectId)
|
||||
headers = {"PRIVATE-TOKEN": privateToken, "Content-Type": "application/json"}
|
||||
|
||||
payload = {
|
||||
"name": releaseName,
|
||||
"tag_name": releaseTag,
|
||||
"description": releaseDescription
|
||||
}
|
||||
|
||||
if verbose:
|
||||
print("POST to {}".format(url))
|
||||
result = requests.post(url, headers=headers, data=json.dumps(payload), verify=caBundle)
|
||||
|
||||
checkAndShowResult(result, 201, 'Unable to create release')
|
||||
|
||||
print('Release successfully created')
|
||||
|
||||
|
||||
# --- update release in case of additional description
|
||||
if not createRelease and releaseDescription:
|
||||
# --- get release to fetch existing description
|
||||
url = "%s/api/v4/projects/%s/releases/%s" % (instanceUrl, projectId, releaseTag)
|
||||
headers = {"PRIVATE-TOKEN": privateToken}
|
||||
|
||||
if verbose:
|
||||
print("GET to {}".format(url))
|
||||
result = requests.get(url, headers=headers, verify=caBundle)
|
||||
|
||||
checkAndShowResult(result, 200, 'Unable to get release')
|
||||
existingDescription = json.loads(result.text)['description']
|
||||
print("Existing description is {}".format(existingDescription))
|
||||
|
||||
releaseDescription += "\n\n---------------------------------------------\n\n"
|
||||
releaseDescription += existingDescription
|
||||
|
||||
# --- update release
|
||||
url = "%s/api/v4/projects/%s/releases/%s" % (instanceUrl, projectId, releaseTag)
|
||||
headers = {"PRIVATE-TOKEN": privateToken, "Content-Type": "application/json"}
|
||||
|
||||
payload = {
|
||||
"name": releaseName,
|
||||
"tag_name": releaseTag,
|
||||
"description": releaseDescription
|
||||
}
|
||||
|
||||
if verbose:
|
||||
print("PUT to {}".format(url))
|
||||
result = requests.put(url, headers=headers, data=json.dumps(payload), verify=caBundle)
|
||||
|
||||
checkAndShowResult(result, 200, 'Unable to update release')
|
||||
|
||||
print('Release successfully update')
|
||||
|
||||
|
||||
# --- add assets
|
||||
# get existing assets
|
||||
headers = {"PRIVATE-TOKEN": privateToken}
|
||||
url = "%s/api/v4/projects/%s/releases/%s" % (instanceUrl, projectId, releaseTag)
|
||||
if verbose:
|
||||
print("GET to {}".format(url))
|
||||
result = requests.get(url, headers=headers, verify=caBundle)
|
||||
checkAndShowResult(result, 200, 'Unable to get release information')
|
||||
|
||||
# add existing assets to list of assets
|
||||
links = json.loads(result.text)['assets']['links']
|
||||
assets.extend(links)
|
||||
|
||||
# delete existing assets
|
||||
headers = {"PRIVATE-TOKEN": privateToken}
|
||||
for link in links:
|
||||
assetId = link['id']
|
||||
url = "%s/api/v4/projects/%s/releases/%s/assets/links/%s" % (instanceUrl, projectId, releaseTag, assetId)
|
||||
if verbose:
|
||||
print("DELETE to {}".format(url))
|
||||
result = requests.delete(url, headers=headers, verify=caBundle)
|
||||
checkAndShowResult(result, 200, 'Unable to delete asset')
|
||||
print("Asset {} successfully deleted".format(assetId))
|
||||
|
||||
|
||||
# create all assets ("existing" and new)
|
||||
headers = {"PRIVATE-TOKEN": privateToken, "Content-Type": "application/json"}
|
||||
url = "%s/api/v4/projects/%s/releases/%s/assets/links" % (instanceUrl, projectId, releaseTag)
|
||||
for asset in assets:
|
||||
if verbose:
|
||||
print("POST to {}".format(url))
|
||||
result = requests.post(url, headers=headers, data=json.dumps(asset), verify=caBundle)
|
||||
checkAndShowResult(result, 201, "Unable to create asset")
|
||||
print("Asset {} successfully created".format(asset))
|
||||
|
8
info.json
Normal file
8
info.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"createRelease": "true",
|
||||
"releaseTag": "v1.12",
|
||||
"createReleaseTag": "true",
|
||||
"releaseName": "updater release",
|
||||
"description": "add option to add files to existing release or extend description of existing release"
|
||||
}
|
||||
|
114
readme.md
Normal file
114
readme.md
Normal file
@ -0,0 +1,114 @@
|
||||
# Release Uploader for Gitlab
|
||||
|
||||
Creating releases on Gitlab seems to work only via the REST API.
|
||||
|
||||
This Python script handles the upload of a release file, the creation of
|
||||
the required release tag in the repository and the creation of the actual
|
||||
release referring to both the tag and the file.
|
||||
|
||||
It supports commandline options and an input file, adjusted to be used in
|
||||
Gitlab CI scripts.
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
wn@tron:~/workspace-python/gitlabreleaseuploader [master ≡]$ ./gitlabreleaseuploader.py -h
|
||||
usage: gitlabreleaseuploader.py [-h] --privateToken PRIVATETOKEN --projectId
|
||||
PROJECTID --projectUrl PROJECTURL --file FILE
|
||||
[--releaseName RELEASENAME]
|
||||
[--releaseTag RELEASETAG]
|
||||
[--releaseTagTarget RELEASETAGTARGET]
|
||||
[--createReleaseTag]
|
||||
[--description DESCRIPTION]
|
||||
[--releaseInfoFile RELEASEINFOFILE]
|
||||
[--caBundle FILE_WITH_CA_CERTIFICATES_TO_TRUST]
|
||||
[--instanceUrl INSTANCEURL] [--verbose]
|
||||
|
||||
Gitlab Release Uploader
|
||||
|
||||
optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
--privateToken PRIVATETOKEN, -p PRIVATETOKEN
|
||||
Private token to access Gitlab
|
||||
--projectId PROJECTID, -i PROJECTID
|
||||
ProjectID of the related project
|
||||
--projectUrl PROJECTURL, -u PROJECTURL
|
||||
URL of the related project at Gitlab
|
||||
--file FILE, -f FILE File to be released
|
||||
--releaseName RELEASENAME, -n RELEASENAME
|
||||
Name of the release
|
||||
--releaseTag RELEASETAG, -t RELEASETAG
|
||||
Tag of the release in the repo
|
||||
--releaseTagTarget RELEASETAGTARGET, -T RELEASETAGTARGET
|
||||
Commit or branch the tag should point to
|
||||
--createReleaseTag, -c
|
||||
Shall the release be created here
|
||||
--description DESCRIPTION, -d DESCRIPTION
|
||||
Description of the release
|
||||
--releaseInfoFile RELEASEINFOFILE, -F RELEASEINFOFILE
|
||||
File containing JSON object with release info (release
|
||||
tag, create release tag, description
|
||||
--instanceUrl INSTANCEURL, -I INSTANCEURL
|
||||
URL of your gitlab instance
|
||||
--caBundle FILE_WITH_CA_CERTIFICATES_TO_TRUST, -B FILE_WITH_CA_CERTIFICATES_TO_TRUST
|
||||
--verbose, -v verbose output
|
||||
wn@tron:~/workspace-python/gitlabreleaseuploader [master ≡]$
|
||||
|
||||
|
||||
|
||||
|
||||
### Without release info file:
|
||||
|
||||
gitlabreleaseuploader.py -p PRIVATE_TOKEN -i PROJECT_ID -u PROJECT_URL
|
||||
-f FILE_TO_BE_RELEASED -n RELEASE_NAME
|
||||
-t RELEASE_TAG -T RELEASE_TAG_TARGET -c
|
||||
-d RELEASE_DESCRIPTION -I INSTANCE_URL
|
||||
|
||||
|
||||
### With release info file:
|
||||
|
||||
Release Info File:
|
||||
|
||||
{
|
||||
"releaseTag": "v1.5",
|
||||
"createReleaseTag": "true",
|
||||
"releaseName": "Sixth release of the uploader",
|
||||
"description": "Now with CI script and automatic release upload (hey, eat your own dogfood)"
|
||||
}
|
||||
|
||||
Command:
|
||||
|
||||
gitlabreleaseuploader.py -p PRIVATE_TOKEN -i PROJECT_ID -u PROJECT_URL
|
||||
-f FILE_TO_BE_RELEASED -F RELEASE_INFO_FILE
|
||||
|
||||
|
||||
### Use in CI script
|
||||
|
||||
The PRIVATE_TOKEN should not be entered directly into the CI script but added as protected a CI variable to you particular project.
|
||||
|
||||
Then add the following stage into your CI script:
|
||||
|
||||
release:
|
||||
stage: release
|
||||
image: registry.gitlab.com/wolutator/base-build-env
|
||||
only:
|
||||
- release
|
||||
script:
|
||||
- gitlabreleaseuploader.py -p $PRIVATE_TOKEN -i $CI_PROJECT_ID -u $CI_PROJECT_URL
|
||||
-f gitlabreleaseuploader.py -F info.json -T $CI_COMMIT_REF_NAME
|
||||
|
||||
Note, please: this stage definition is for a docker worker. It uses my ``base-build-env`` image, which already contains the
|
||||
uploader script. However, it is no problem to use the uploader script also in different environments. It just depends on the
|
||||
``Requests`` package.
|
||||
|
||||
Note too, please: this job is releasing the ``gitlabreleaseuploader.py`` script itself, so you see the name of the script twice in the CI script. Don't be confused, the option ``-f`` gets the file to be released.
|
||||
|
||||
Most information are taken from CI builtin variables, the tag name, release name and release description should be stored in
|
||||
the release info file (here: ``info.json``), which is under version control.
|
||||
|
||||
To avoid releasing a file with everything single push to an arbitrary branch, add the ``only`` block.
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user