7 Commits
v1.6 ... v1.8

Author SHA1 Message Date
cb94e9e017 fix code style 2020-02-28 19:36:55 +01:00
0e8823bba1 fix code style 2020-02-28 19:35:58 +01:00
5fd785a826 ca bundle added 2020-02-28 19:34:31 +01:00
3ea721a4e7 deleterelease added 2019-07-16 15:32:20 +02:00
fdc5e97fc2 Update readme.md, fix typo 2019-07-10 12:39:02 +00:00
79dba02090 readme change 2019-05-30 16:07:35 +02:00
b9663f82d3 Add LICENSE 2019-05-30 14:04:15 +00:00
6 changed files with 98 additions and 10 deletions

View File

@ -23,6 +23,7 @@ release:
only: only:
- release - release
script: script:
- zip GitlabReleaseTool.zip gitlabreleaseuploader.py deleterelease.py
- python gitlabreleaseuploader.py -p $PRIVATE_TOKEN -i $CI_PROJECT_ID -u $CI_PROJECT_URL - 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 -f GitlabReleaseTool.zip -F info.json -T $CI_COMMIT_REF_NAME

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 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.

56
deleterelease.py Normal file
View File

@ -0,0 +1,56 @@
#!/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')
args = parser.parse_args()
privateToken = args.privateToken
projectId = args.projectId
releaseTag = args.releaseTag
instanceUrl = args.instanceUrl
verbose = args.verbose
caBundle = args.caBundle
# --- 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)
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')

View File

@ -42,6 +42,9 @@ 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('--caBundle', '-B',
help='File with the CA certificates to trust', required=False,
default='/etc/ssl/certs/ca-certificates.crt')
parser.add_argument('--verbose', '-v', parser.add_argument('--verbose', '-v',
help='verbose output', help='verbose output',
required=False, required=False,
@ -60,6 +63,7 @@ releaseDescription = args.description
instanceUrl = args.instanceUrl instanceUrl = args.instanceUrl
createReleaseTag = args.createReleaseTag createReleaseTag = args.createReleaseTag
releaseInfoFilename = args.releaseInfoFile releaseInfoFilename = args.releaseInfoFile
caBundle = args.caBundle
verbose = args.verbose verbose = args.verbose
releaseInfo = {} releaseInfo = {}
@ -94,7 +98,7 @@ uploadUrl = "%s/api/v4/projects/%s/uploads" % (instanceUrl, projectId)
headers = {"PRIVATE-TOKEN": privateToken} 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, verify=caBundle)
if uploadResult.status_code != 201: if uploadResult.status_code != 201:
print(uploadResult) print(uploadResult)
@ -124,7 +128,8 @@ if createReleaseTag:
createReleaseTagResult = requests.post(createReleaseTagUrl, createReleaseTagResult = requests.post(createReleaseTagUrl,
headers=headers, headers=headers,
data=json.dumps(payloadCreateReleaseTag)) data=json.dumps(payloadCreateReleaseTag),
verify=caBundle)
if createReleaseTagResult.status_code != 201: if createReleaseTagResult.status_code != 201:
print(createReleaseTagResult) print(createReleaseTagResult)
@ -157,7 +162,8 @@ payloadCreateRelease = {
} }
createReleaseResult = requests.post(createReleaseUrl, headers=headers, createReleaseResult = requests.post(createReleaseUrl, headers=headers,
data=json.dumps(payloadCreateRelease)) data=json.dumps(payloadCreateRelease),
verify=caBundle)
if createReleaseResult.status_code != 201: if createReleaseResult.status_code != 201:
print(createReleaseResult) print(createReleaseResult)

View File

@ -1,7 +1,7 @@
{ {
"releaseTag": "v1.6", "releaseTag": "v1.8",
"createReleaseTag": "true", "createReleaseTag": "true",
"releaseName": "Seventh release of the uploader", "releaseName": "CA Bundle",
"description": "Work on readme and change of CI script" "description": "Option to provide CA bundle file for ssl verification"
} }

View File

@ -21,6 +21,7 @@ Gitlab CI scripts.
[--createReleaseTag] [--createReleaseTag]
[--description DESCRIPTION] [--description DESCRIPTION]
[--releaseInfoFile RELEASEINFOFILE] [--releaseInfoFile RELEASEINFOFILE]
[--caBundle FILE_WITH_CA_CERTIFICATES_TO_TRUST]
[--instanceUrl INSTANCEURL] [--verbose] [--instanceUrl INSTANCEURL] [--verbose]
Gitlab Release Uploader Gitlab Release Uploader
@ -49,6 +50,7 @@ Gitlab CI scripts.
tag, create release tag, description tag, create release tag, description
--instanceUrl INSTANCEURL, -I INSTANCEURL --instanceUrl INSTANCEURL, -I INSTANCEURL
URL of your gitlab instance URL of your gitlab instance
--caBundle FILE_WITH_CA_CERTIFICATES_TO_TRUST, -B FILE_WITH_CA_CERTIFICATES_TO_TRUST
--verbose, -v verbose output --verbose, -v verbose output
wn@tron:~/workspace-python/gitlabreleaseuploader [master ≡]$ wn@tron:~/workspace-python/gitlabreleaseuploader [master ≡]$
@ -71,7 +73,7 @@ Release Info File:
"releaseTag": "v1.5", "releaseTag": "v1.5",
"createReleaseTag": "true", "createReleaseTag": "true",
"releaseName": "Sixth release of the uploader", "releaseName": "Sixth release of the uploader",
"description": "Now with CI script and automatic release upload (he, eat your own dogfood)" "description": "Now with CI script and automatic release upload (hey, eat your own dogfood)"
} }
Command: Command:
@ -95,9 +97,11 @@ Then add the following stage into your CI script:
- gitlabreleaseuploader.py -p $PRIVATE_TOKEN -i $CI_PROJECT_ID -u $CI_PROJECT_URL - gitlabreleaseuploader.py -p $PRIVATE_TOKEN -i $CI_PROJECT_ID -u $CI_PROJECT_URL
-f gitlabreleaseuploader.py -F info.json -T $CI_COMMIT_REF_NAME -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 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 uploader script. However, it is no problem to use the uploader script also in different environments. It just depends on the
``Requests`` package.) ``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 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. the release info file (here: ``info.json``), which is under version control.