deskflow/CI/build_version.py
Daun Chung cae96765cb
flatpack workflow to build flatpak installer (#7177)
* flatpack workflow to build flatpak installer

* rename flatpak build name

* changing job-build-flatpak, disabling other job-tests meanwhile

* update apt before attempting to install flatpak

* changing install command

* adding logs for installing flatpak

* running installation as root

* running installation as root - for each command

* attempting to use github action to build flatpak

* fix typo on name

* typo in image

* adding privilege option and fixing manifest path

* changing manifest-path

* uploading bundle to artifact

* changing synergy.desktop for flatpak build

* adding versioning to flatpak bundle and upload to bin storage on release

* version info fix

* running build_version as root

* adding __w to safe directory

* adding git config safe directory command to builder

* testing which part of version info is breaking

* falling back to local build of flatpak

* running only the normal synergy

* investigating build_version.py

* investigating build_version.py 2

* investigating build_version.py 3

* checking if raspberry pi build is working correctly

* get subprocess error

* printing subprocess error

* disabling try catch in version

* running git rev-list --tags command

* running git rev-list --tags command

* disabling other tests

* trying to run extra step in gitaction

* trying to remove extra step in gitaction

* fixing issues with subprocess

* try to run git rev-list

* test

* ignore versioning

* run original flatpak

* testing various build options

* attempting to run flatpak through raspberry

* raspberry flatpak installation 1

* fixing tabs in flatpak build

* trying apt over apt-get

* removing sudo from build process

* removing apt update

* trying to build without versioning

* testing build without publish

* testing

* adding fetch-depth in checkout

* checking out with v3

* getting flatpak to run without github action

* using ubuntu20.04 container

* attempting to add __w into safe directory

* adding dependencies installation

* remove sudo from installing dependencies

* removing all sudo commands from flatpak install

* moving all the apt-get installs in dependencies job

* add yes response to flatpak platform & sdk install

* proper install command for flatpak builder

* flathub input yes to flatpak builder install

* check if flatpak folder exist

* adding flatpak using apt-get

* add privilege option in docker

* removing flatpak finalize build / remove com.symless.Synergy

* listing flatpak dir

* testing to publish flatpak

* checking the directory for flatpak file

* correcting the path for scp action

* attempting to create a specific file in scp

* flatpak workflow cleanup

* cleaning up

* adding changelog info and changing flatpak patch files location

* fedora add safe directory

* creating business/enterprise YAML to replace based on env var

* build test

* disabling tests

* fixing YAML struct

* disabling replace action to see if its causing issue

* changing cp command without backslash

* checking if condition syntax

* uncommenting error at build_version

* fixing file location

* cleaning up actions

* changing workkflow to use .yml file without copying

* finalizing git action

* Remove git safe directory

* Add final line to missing files

* Move safe directory workaround

* Minor cleanup for flatpak files

Co-authored-by: Daun Chung <daunchung@github.com>
Co-authored-by: Kyle Bloom <kyle@symless.com>
2022-05-27 15:42:01 +01:00

137 lines
4.1 KiB
Python

import subprocess
class VersionPart:
def __init__(self, part = ''):
self.prefix = ''
self.suffix = ''
self.number = 0
if part:
self.__parsePreffix(part)
self.__parseNumber(part)
self.__parseSuffix(part)
def __parsePreffix(self, part):
if not part[0].isdigit():
for i in part:
if not i.isdigit():
self.prefix += i
else:
break
def __parseNumber(self, part):
start = len(self.prefix)
end = part.find('-')
if end > 0:
self.number = int(part[start:end])
else:
self.number = int(part[start:])
def __parseSuffix(self, part):
items = part.split('-')
if len(items) == 2:
self.suffix = '-' + items[1]
def __str__(self):
return self.prefix + str(self.number) + self.suffix
class Version:
def __init__(self, version):
versionParts = version.split('.')
if len(versionParts) == 3:
self.major = VersionPart(versionParts[0])
self.minor = VersionPart(versionParts[1])
self.build = VersionPart(versionParts[2])
self.patch = VersionPart()
self.patch.number = self.build.number
elif len(versionParts) == 4:
self.major = VersionPart(versionParts[0])
self.minor = VersionPart(versionParts[1])
self.patch = VersionPart(versionParts[2])
self.build = VersionPart(versionParts[3])
else:
print('ERROR: Wrong version number')
def isSamePatch(self, version):
return (self.major.number == version.major.number and
self.minor.number == version.minor.number and
self.patch.number == version.patch.number)
def __str__(self):
result = str(self.major) + '.'
result += str(self.minor) + '.'
result += str(self.patch) + '.'
result += str(self.build)
return result
class VersionFile:
def __init__(self, file):
self.file = file
def setOption(self, name, value):
fp = open(self.file, 'rt+')
content = ''
for line in fp:
print(line)
if line.find(name) != -1:
line = 'set ('+ name + ' ' + value + ')'
content += line
fp.write(content)
fp.close()
def findVersion(versions, cmakeVersion):
gitVersion = Version(versions[0])
for version in versions:
ver = Version(version)
if ver.isSamePatch(cmakeVersion):
gitVersion = ver
break
print('INFO: Version '+ str(gitVersion) + ' has been read from git')
return gitVersion
def getVersionFromGit(cmakeVersion):
try:
taggedRevision = subprocess.check_output(('git rev-list --tags --max-count=100').split(), universal_newlines=True)
cmd = ('git describe --tags ' + taggedRevision).split()
versions = subprocess.check_output(cmd, universal_newlines=True).split()
return findVersion(versions, cmakeVersion)
except subprocess.CalledProcessError:
print('ERROR: Unable to get version from git')
exit(1)
def updateVersionFile(number):
fp = open('cmake/Version.cmake')
content = fp.read()
fp.close()
fp = open('cmake/Version.cmake', 'wt')
fp.write(content.replace('set (SYNERGY_VERSION_BUILD 1)', 'set (SYNERGY_VERSION_BUILD ' + str(number) + ')'))
fp.close()
def getOptionValue(source, option):
start = source.find(option)
if (start != -1):
start += len(option) + 1
end = source.find(')', start)
return source[start : end]
else:
print("ERROR: Can't find option <" + option + ">");
def getVersionFromFile():
fp = open('cmake/Version.cmake')
content = fp.read()
fp.close()
major = getOptionValue(content, 'SYNERGY_VERSION_MAJOR')
minor = getOptionValue(content, 'SYNERGY_VERSION_MINOR')
patch = getOptionValue(content, 'SYNERGY_VERSION_PATCH')
return Version(major + '.' + minor + '.' + patch)
if __name__ == '__main__':
cmakeVersion = getVersionFromFile()
gitVersion = getVersionFromGit(cmakeVersion)
updateVersionFile(gitVersion.build.number)
print('INFO: Build number is: <' + str(gitVersion) + '>')