Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add working flatpak manifest #1275

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,49 @@ jobs:
if-no-files-found: error
retention-days: 1

buildFlatpak:
needs: buildAssets
runs-on: ubuntu-latest
steps:
- name: Python Setup
uses: actions/setup-python@v4
with:
python-version: 3
architecture: x64

- name: Install Packages (apt)
run: |
sudo apt update
sudo apt install flatpak flatpak-builder
sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

- name: Checkout Source
uses: actions/checkout@v3

- name: Get Version
shell: bash
run: |
NW_VER=$(python setup.py version)
echo "novelWriter Version: $NW_VER"
echo "VERSION=$NW_VER" >> $GITHUB_ENV

- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: nw-assets
path: novelwriter/assets

- name: Build Flatpak
run: sudo python setup.py build-flatpak

- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: novelWriter-${{ env.VERSION }}-linux.flatpak
path: dist_flatpak/novelWriter-${{ env.VERSION }}-linux.flatpak
if-no-files-found: error
retention-days: 1

buildMac:
needs: buildAssets
strategy:
Expand Down
127 changes: 125 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ def genMacOSPlist():
"""
numVers, _, _ = extractVersion()
pkgVers = compactVersion(numVers)

outDir = "setup/macos"

copyrightYear = datetime.datetime.now().year
Expand All @@ -427,6 +428,49 @@ def genMacOSPlist():
return


def generateAppdateXML():
"""update the appdata.xml used by appimage and flatpak.
"""
numVers, _, relDate = extractVersion()
pkgVers = compactVersion(numVers)

outDir = "setup/data"

curDate = f"date=\"{relDate}\""

releaseTemplate = (
"<release version=\"{version}\" {date}>\n"
" <url>https://github.com/vkbo/novelWriter/releases/tag/v{version}</url>\n"
"</release>"
)

tagsOutput = subprocess.check_output(["git", "--no-pager", "tag", "-l", "v*.*.*"])

strVersions = tagsOutput.decode("utf-8").split("\n")

versions = [tuple(map(int, v.lstrip("v").split("."))) for v in strVersions if v]
sortedVersions = [".".join(map(str, v)) for v in reversed(sorted(versions))]

xmlVersions = [releaseTemplate.format(version=v, date="") for v in sortedVersions if v != pkgVers]
xmlVersions.insert(0, releaseTemplate.format(version=pkgVers, date=curDate))

from textwrap import indent

versionsXMLBlock = indent("\n".join(xmlVersions) + "\n", " " * 2).lstrip()

desc = indent(readFile("setup/description_short.txt"), " " * 2).lstrip()

xmlAppData = readFile("setup/linux/novelwriter.appdata.xml.template").format(
releases=versionsXMLBlock,
description=desc
)

print(f"Writing novelwriter.appdata.xml to {outDir}/novelwriter.appdata.xml")
writeFile(f"{outDir}/novelwriter.appdata.xml", xmlAppData)

return


##
# Sample Project ZIP File Builder (sample)
##
Expand Down Expand Up @@ -619,6 +663,7 @@ def makeMinimalPackage(targetOS):
print("")

rootFiles = [
"MANIFEST.in",
"README.md",
"LICENSE.md",
"CREDITS.md",
Expand Down Expand Up @@ -1093,8 +1138,7 @@ def makeAppImage(sysArgs):
# Write Metadata
# ==============

appDescription = readFile("setup/description_short.txt")
appdataXML = readFile("setup/novelwriter.appdata.xml").format(description=appDescription)
appdataXML = readFile("setup/data/novelwriter.appdata.xml")
writeFile(f"{imageDir}/novelwriter.appdata.xml", appdataXML)
print("Wrote: novelwriter.appdata.xml")

Expand Down Expand Up @@ -1147,6 +1191,71 @@ def makeAppImage(sysArgs):
return unparsedArgs



##
# Make a flatpak
##

def makeFlatpak():
"""build a flatpak bundle localy (not for flathub)
"""

print("")
print("Build flatpak")
print("==============")
print("")

numVers, _, relDate = extractVersion()
pkgVers = compactVersion(numVers)
relDate = datetime.datetime.strptime(relDate, "%Y-%m-%d")

bldDir = "dist_flatpak"
bldPkg = f"novelwriter_{pkgVers}"
outDir = f"{bldDir}/{bldPkg}"


# Set Up Folders
# ==============

if not os.path.isdir(bldDir):
os.mkdir(bldDir)

if os.path.isdir(outDir):
print("Removing old build files ...")
print("")
shutil.rmtree(outDir)

os.mkdir(outDir)

# Build flatpak
# ==============

manifestPath = "setup/flatpak/io.novelwriter.novelWriter.yml"

bundlFile = f"{bldDir}/novelWriter-{pkgVers}-linux.flatpak"

try:
subprocess.call([
"flatpak-builder", f"--repo={outDir}/repo", "--install-deps-from=flathub", "--force-clean", outDir, manifestPath
])
subprocess.call([
"flatpak", "build-bundle", f"{outDir}/repo", bundlFile, "io.novelwriter.novelWriter",
])
except Exception as exc:
print("Flatpak build: FAILED")
print("")
print(str(exc))
print("")
print("Dependencies:")
print(" * flatpak flatpak-builder")
print("")
sys.exit(1)

shaFile = makeCheckSum(os.path.basename(bundlFile), cwd=bldDir)

toUpload(bundlFile)
toUpload(shaFile)

##
# Make Windows Setup EXE (build-win-exe)
##
Expand Down Expand Up @@ -1905,6 +2014,8 @@ def winUninstall():
" The package must be built from a minimal windows zip file.",
" build-appimage Build an AppImage. Argument --linux-tag defaults to",
" manylinux1_x86_64 / i386, and --python-version to 3.10.",
" build-flatpak Build a flatpak bundle. Builds a local flatpak for install,",
" not for distribution to flathub.",
"",
"System Install:",
"",
Expand Down Expand Up @@ -1973,6 +2084,10 @@ def winUninstall():
if "gen-plist" in sys.argv:
sys.argv.remove("gen-plist")
genMacOSPlist()

if "gen-appdata" in sys.argv:
sys.argv.remove("gen-appdata")
generateAppdateXML()

# Python Packaging
# ================
Expand Down Expand Up @@ -2018,6 +2133,14 @@ def winUninstall():
else:
print("ERROR: Command 'build-appimage' can only be used on Linux")
sys.exit(1)

if "build-flatpak" in sys.argv:
sys.argv.remove("build-flatpak")
if hostOS == OS_LINUX:
makeFlatpak()
else:
print("ERROR: Command 'install-flatpak' can only be used on Linux")
sys.exit(1)

# General Installers
# ==================
Expand Down
Loading