Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
af6b41a0ae
|
|||
26a8759919
|
|||
62c3f0e00f
|
|||
dff4090678
|
|||
0c8e75e82e
|
|||
715c984e40
|
|||
9d348117f8
|
|||
81966c095c
|
28
.gitlab-ci.yml
Normal file
28
.gitlab-ci.yml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
stages:
|
||||||
|
- check
|
||||||
|
- release
|
||||||
|
|
||||||
|
build:
|
||||||
|
stage: check
|
||||||
|
image: registry.gitlab.com/wolutator/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 --max-line-length=120 $I; done
|
||||||
|
|
||||||
|
release:
|
||||||
|
stage: release
|
||||||
|
image: registry.gitlab.com/wolutator/base-build-env
|
||||||
|
tags:
|
||||||
|
- hottis
|
||||||
|
- linux
|
||||||
|
- docker
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
script:
|
||||||
|
- python gitlabreleaseuploader.py -p $PRIVATE_TOKEN -i $CI_PROJECT_ID -u $CI_PROJECT_URL
|
||||||
|
-f gitlabreleaseuploader.py -F info.json -T $CI_COMMIT_REF_NAME
|
||||||
|
|
51
gitlabreleaseuploader.py
Normal file → Executable file
51
gitlabreleaseuploader.py
Normal file → Executable file
@ -1,3 +1,5 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
import argparse
|
import argparse
|
||||||
@ -40,8 +42,12 @@ parser.add_argument('--releaseInfoFile', '-F',
|
|||||||
parser.add_argument('--instanceUrl', '-I',
|
parser.add_argument('--instanceUrl', '-I',
|
||||||
help='URL of your gitlab instance', required=False,
|
help='URL of your gitlab instance', required=False,
|
||||||
default='https://gitlab.com')
|
default='https://gitlab.com')
|
||||||
|
parser.add_argument('--verbose', '-v',
|
||||||
|
help='verbose output',
|
||||||
|
required=False,
|
||||||
|
action='store_true',
|
||||||
|
default=False)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
print(args)
|
|
||||||
|
|
||||||
privateToken = args.privateToken
|
privateToken = args.privateToken
|
||||||
projectId = args.projectId
|
projectId = args.projectId
|
||||||
@ -54,7 +60,7 @@ releaseDescription = args.description
|
|||||||
instanceUrl = args.instanceUrl
|
instanceUrl = args.instanceUrl
|
||||||
createReleaseTag = args.createReleaseTag
|
createReleaseTag = args.createReleaseTag
|
||||||
releaseInfoFilename = args.releaseInfoFile
|
releaseInfoFilename = args.releaseInfoFile
|
||||||
|
verbose = args.verbose
|
||||||
releaseInfo = {}
|
releaseInfo = {}
|
||||||
|
|
||||||
if (releaseInfoFilename):
|
if (releaseInfoFilename):
|
||||||
@ -68,7 +74,8 @@ if (releaseInfoFilename):
|
|||||||
if 'releaseTagTarget' in releaseInfo:
|
if 'releaseTagTarget' in releaseInfo:
|
||||||
releaseTagTarget = releaseInfo['releaseTagTarget']
|
releaseTagTarget = releaseInfo['releaseTagTarget']
|
||||||
if 'createReleaseTag' in releaseInfo:
|
if 'createReleaseTag' in releaseInfo:
|
||||||
createReleaseTag = (releaseInfo['createReleaseTag'] in ('true', 'True'))
|
createReleaseTag = (releaseInfo['createReleaseTag'] in
|
||||||
|
('true', 'True'))
|
||||||
if 'description' in releaseInfo:
|
if 'description' in releaseInfo:
|
||||||
releaseDescription = releaseInfo['description']
|
releaseDescription = releaseInfo['description']
|
||||||
|
|
||||||
@ -88,23 +95,25 @@ headers = {"PRIVATE-TOKEN": privateToken}
|
|||||||
files = {"file": open(fileToUpload, 'rb')}
|
files = {"file": open(fileToUpload, 'rb')}
|
||||||
|
|
||||||
uploadResult = requests.post(uploadUrl, files=files, headers=headers)
|
uploadResult = requests.post(uploadUrl, files=files, headers=headers)
|
||||||
|
|
||||||
|
if uploadResult.status_code != 201:
|
||||||
print(uploadResult)
|
print(uploadResult)
|
||||||
print(uploadResult.text)
|
print(uploadResult.text)
|
||||||
if uploadResult.status_code != 201:
|
|
||||||
raise Exception('Unable to upload file to Gitlab')
|
raise Exception('Unable to upload file to Gitlab')
|
||||||
|
|
||||||
|
if verbose:
|
||||||
|
print(uploadResult)
|
||||||
|
print(uploadResult.text)
|
||||||
|
print('File successfully uploaded')
|
||||||
|
|
||||||
uploadResultJson = json.loads(uploadResult.text)
|
uploadResultJson = json.loads(uploadResult.text)
|
||||||
|
|
||||||
# --- create release tag
|
# --- create release tag
|
||||||
if createReleaseTag:
|
if createReleaseTag:
|
||||||
createReleaseTagUrl = "%s/api/v4//projects/%s/repository/tags" % (instanceUrl, projectId)
|
createReleaseTagUrl = ("%s/api/v4//projects/%s/repository/tags" %
|
||||||
headers = {"PRIVATE-TOKEN": privateToken, "Content-Type": "application/json"}
|
(instanceUrl, projectId))
|
||||||
|
headers = {"PRIVATE-TOKEN": privateToken,
|
||||||
# id (required) - The ID or URL-encoded path of the project owned by the authenticated user
|
"Content-Type": "application/json"}
|
||||||
# tag_name (required) - The name of a tag
|
|
||||||
# ref (required) - Create tag using commit SHA, another tag name, or branch name.
|
|
||||||
# message (optional) - Creates annotated tag.
|
|
||||||
# release_description (optional) - Add release notes to the git tag and store it in the GitLab database.
|
|
||||||
|
|
||||||
payloadCreateReleaseTag = {
|
payloadCreateReleaseTag = {
|
||||||
"tag_name": releaseTag,
|
"tag_name": releaseTag,
|
||||||
@ -113,14 +122,21 @@ if createReleaseTag:
|
|||||||
"message": "Tag for release %s" % releaseName
|
"message": "Tag for release %s" % releaseName
|
||||||
}
|
}
|
||||||
|
|
||||||
createReleaseTagResult = requests.post(createReleaseTagUrl, headers=headers,
|
createReleaseTagResult = requests.post(createReleaseTagUrl,
|
||||||
|
headers=headers,
|
||||||
data=json.dumps(payloadCreateReleaseTag))
|
data=json.dumps(payloadCreateReleaseTag))
|
||||||
|
|
||||||
|
if createReleaseTagResult.status_code != 201:
|
||||||
print(createReleaseTagResult)
|
print(createReleaseTagResult)
|
||||||
print(createReleaseTagResult.text)
|
print(createReleaseTagResult.text)
|
||||||
if createReleaseTagResult.status_code != 201:
|
|
||||||
raise Exception('Unable to create release tag')
|
raise Exception('Unable to create release tag')
|
||||||
|
|
||||||
|
if verbose:
|
||||||
|
print(createReleaseTagResult)
|
||||||
|
print(createReleaseTagResult.text)
|
||||||
|
print('Tag successfully created')
|
||||||
|
|
||||||
|
|
||||||
# --- create release
|
# --- create release
|
||||||
createReleaseUrl = "%s/api/v4/projects/%s/releases" % (instanceUrl, projectId)
|
createReleaseUrl = "%s/api/v4/projects/%s/releases" % (instanceUrl, projectId)
|
||||||
headers = {"PRIVATE-TOKEN": privateToken, "Content-Type": "application/json"}
|
headers = {"PRIVATE-TOKEN": privateToken, "Content-Type": "application/json"}
|
||||||
@ -143,7 +159,12 @@ payloadCreateRelease = {
|
|||||||
createReleaseResult = requests.post(createReleaseUrl, headers=headers,
|
createReleaseResult = requests.post(createReleaseUrl, headers=headers,
|
||||||
data=json.dumps(payloadCreateRelease))
|
data=json.dumps(payloadCreateRelease))
|
||||||
|
|
||||||
|
if createReleaseResult.status_code != 201:
|
||||||
print(createReleaseResult)
|
print(createReleaseResult)
|
||||||
print(createReleaseResult.text)
|
print(createReleaseResult.text)
|
||||||
if createReleaseResult.status_code != 201:
|
|
||||||
raise Exception('Unable to create release')
|
raise Exception('Unable to create release')
|
||||||
|
|
||||||
|
if verbose:
|
||||||
|
print(createReleaseResult)
|
||||||
|
print(createReleaseResult.text)
|
||||||
|
print('Release successfully created')
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"releaseTag": "v1.1",
|
"releaseTag": "v1.5",
|
||||||
"createReleaseTag": "true",
|
"createReleaseTag": "true",
|
||||||
"releaseName": "Second release of the uploader",
|
"releaseName": "Sixth release of the uploader",
|
||||||
"description": "Now includes the option to create the tag and to load infos from file"
|
"description": "Now with CI script and automatic release upload (he, eat your own dogfood)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
readme.md
Normal file
12
readme.md
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
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.
|
||||||
|
|
Reference in New Issue
Block a user