11 server=
"gitlab.in2p3.fr"
12 apiProject=
"/api/v4/projects/"
17 Get the list of the archives file for a given project name
19 inputDirectory : directory (for one OS) where all the binary packages are created
20 projectName : name of the project
22 list of corresponding binary packages
24 listPackage = glob.glob(inputDirectory +
"/*/" + projectName +
"-*" )
32 Upload a file in the given gitlab project
34 projectIdOwn : id of the project
35 fileName : name of the file to be uploaded
36 token : token to be used to create the release
38 url of the uploaded file
40 print(
"Upload file",fileName)
41 URL =
'"https://'+server+apiProject+
str(projectIdOwn)+
'/uploads"'
42 privateToken=
'--header "PRIVATE-TOKEN: '+token+
'" '
43 fileCmd =
'--form "file=@'+fileName+
'" '
44 command =
"curl --insecure --request POST " + privateToken + fileCmd + URL
46 output = subprocess.getoutput(command)
47 print(
"Upload file output :",output)
48 outputDico = json.loads(
'{' + output.split(
"{")[1])
49 outputFile = outputDico[
"full_path"]
50 outputUrl = outputDico[
"full_path"]
51 print(
"Upload file output file ",outputFile,
", url :",outputUrl)
52 return outputFile, outputUrl
60 Create the list of link to the archive uploaded binary packages
62 projectIdOwn : id of the project to be used
63 listPackage : list of the binary packages to be uploaded and linked
64 useComma : True to add a comma in the first place, false otherwise
65 token : token to be used to create the release
67 string of the list of archive links corresponding to the given list of packages
70 for packageName
in listPackage:
73 baseName = os.path.basename(packageName)
74 packageOsName = packageName.split(
'/')[-2]
75 nameData =
"\"name\": \"" + packageOsName +
" " + baseName+
"\""
78 print(
"outputUrl =",outputUrl)
79 fullPathToFile =
'https://'+server+
"/"+uploadedFullPath
81 linkType =
'"link_type": "other" '
82 urlData =
'"url": "'+fullPathToFile+
'"'
84 addDataLink =
'{ '+nameData +
", " + urlData +
", " + linkType +
'}'
85 print(
"addDataLink =",addDataLink)
86 linksData += addDataLink
94 Create a release of the given project
96 projectIdOwn : id of the project on gitlab
97 projectName : name of the project
98 projectTagName : tag name of the project
99 basePackageDir : base directory wher eto find binary packages
100 token : token to be used to create the release
102 postURL=
"--request POST https://"+server+apiProject+
str(projectIdOwn)+
"/releases"
103 header=
"--header 'Content-Type: application/json' "
104 privateToken=
'--header "PRIVATE-TOKEN: '+token+
'" '
105 versionName=
"version " + projectTagName
106 dataStr =
"--data '{ \"name\": \"Release "+versionName+
"\"," +
"\"tag_name\": \""+projectTagName+
"\","
107 dataStr +=
"\"description\": \"Automatic release, "+versionName+
"\""
110 linksData =
", \"assets\": { \"links\": ["
116 command =
"curl --insecure " + header + privateToken + dataStr + postURL
117 print(
"Create Release command :",command)
118 output = subprocess.getoutput(command)
119 print(
"Release Output :",output)
122 if __name__ ==
"__main__":
123 parser = argparse.ArgumentParser(description=
"Program which creates release with given tag")
124 parser.add_argument(
'-n',
'--projectname', help=
"Name of the current projet", required=
True, type=str)
125 parser.add_argument(
'-i',
'--projectid', help=
"Id of the current projet", required=
True, type=int)
126 parser.add_argument(
'-t',
'--tag', help=
"Tag to be used to create the current release", required=
True, type=str)
127 parser.add_argument(
'-p',
'--token', help=
"Token to be used to create the release", required=
True, type=str)
128 parser.add_argument(
'-d',
'--packagedirectory', help=
"Directory where to find packages", required=
False, type=str, default=
"./")
129 args = parser.parse_args()