flatpak.yml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. name: Flatpak release job
  2. on:
  3. workflow_call:
  4. inputs:
  5. ryujinx_version:
  6. required: true
  7. type: string
  8. concurrency: flatpak-release
  9. jobs:
  10. release:
  11. timeout-minutes: ${{ fromJSON(vars.JOB_TIMEOUT) }}
  12. runs-on: ubuntu-latest
  13. env:
  14. NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
  15. GIT_COMMITTER_NAME: "RyujinxBot"
  16. GIT_COMMITTER_EMAIL: "61127645+RyujinxBot@users.noreply.github.com"
  17. RYUJINX_PROJECT_FILE: "src/Ryujinx/Ryujinx.csproj"
  18. NUGET_SOURCES_DESTDIR: "nuget-sources"
  19. RYUJINX_VERSION: "${{ inputs.ryujinx_version }}"
  20. steps:
  21. - uses: actions/checkout@v4
  22. with:
  23. path: Ryujinx
  24. - uses: actions/setup-dotnet@v4
  25. with:
  26. global-json-file: Ryujinx/global.json
  27. - name: Get version info
  28. id: version_info
  29. working-directory: Ryujinx
  30. run: |
  31. echo "git_hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
  32. - uses: actions/checkout@v4
  33. with:
  34. repository: flathub/org.ryujinx.Ryujinx
  35. token: ${{ secrets.RYUJINX_BOT_PAT }}
  36. submodules: recursive
  37. path: flathub
  38. - name: Install dependencies
  39. run: python -m pip install PyYAML lxml
  40. - name: Restore Nuget packages
  41. # With .NET 8.0.100, Microsoft.NET.ILLink.Tasks isn't restored by default and only seems to appears when publishing.
  42. # So we just publish to grab the dependencies
  43. run: |
  44. dotnet publish -c Release -r linux-x64 Ryujinx/${{ env.RYUJINX_PROJECT_FILE }} --self-contained
  45. dotnet publish -c Release -r linux-arm64 Ryujinx/${{ env.RYUJINX_PROJECT_FILE }} --self-contained
  46. - name: Generate nuget_sources.json
  47. shell: python
  48. run: |
  49. from pathlib import Path
  50. import base64
  51. import binascii
  52. import json
  53. import os
  54. sources = []
  55. for path in Path(os.environ['NUGET_PACKAGES']).glob('**/*.nupkg.sha512'):
  56. name = path.parent.parent.name
  57. version = path.parent.name
  58. filename = '{}.{}.nupkg'.format(name, version)
  59. url = 'https://api.nuget.org/v3-flatcontainer/{}/{}/{}'.format(name, version, filename)
  60. with path.open() as fp:
  61. sha512 = binascii.hexlify(base64.b64decode(fp.read())).decode('ascii')
  62. sources.append({
  63. 'type': 'file',
  64. 'url': url,
  65. 'sha512': sha512,
  66. 'dest': os.environ['NUGET_SOURCES_DESTDIR'],
  67. 'dest-filename': filename,
  68. })
  69. with open('flathub/nuget_sources.json', 'w') as fp:
  70. json.dump(sources, fp, indent=4)
  71. - name: Update flatpak metadata
  72. id: metadata
  73. env:
  74. RYUJINX_GIT_HASH: ${{ steps.version_info.outputs.git_hash }}
  75. shell: python
  76. run: |
  77. import hashlib
  78. import hmac
  79. import json
  80. import os
  81. import yaml
  82. from datetime import datetime
  83. from lxml import etree
  84. # Ensure we don't destroy multiline strings
  85. def str_presenter(dumper, data):
  86. if len(data.splitlines()) > 1:
  87. return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|")
  88. return dumper.represent_scalar("tag:yaml.org,2002:str", data)
  89. yaml.representer.SafeRepresenter.add_representer(str, str_presenter)
  90. yaml_file = "flathub/org.ryujinx.Ryujinx.yml"
  91. xml_file = "flathub/org.ryujinx.Ryujinx.appdata.xml"
  92. with open(yaml_file, "r") as f:
  93. data = yaml.safe_load(f)
  94. for source in data["modules"][0]["sources"]:
  95. if type(source) is str:
  96. continue
  97. if (
  98. source["type"] == "git"
  99. and source["url"] == "https://github.com/Ryujinx/Ryujinx.git"
  100. ):
  101. source["commit"] = os.environ['RYUJINX_GIT_HASH']
  102. is_same_version = data["modules"][0]["build-options"]["env"]["RYUJINX_VERSION"] == os.environ['RYUJINX_VERSION']
  103. with open(os.environ['GITHUB_OUTPUT'], "a") as gh_out:
  104. if is_same_version:
  105. gh_out.write(f"commit_message=Retry update to {os.environ['RYUJINX_VERSION']}")
  106. else:
  107. gh_out.write(f"commit_message=Update to {os.environ['RYUJINX_VERSION']}")
  108. if not is_same_version:
  109. data["modules"][0]["build-options"]["env"]["RYUJINX_VERSION"] = os.environ['RYUJINX_VERSION']
  110. with open(yaml_file, "w") as f:
  111. yaml.safe_dump(data, f, sort_keys=False)
  112. parser = etree.XMLParser(remove_blank_text=True)
  113. tree = etree.parse(xml_file, parser)
  114. root = tree.getroot()
  115. releases = root.find("releases")
  116. element = etree.Element("release")
  117. element.set("version", os.environ['RYUJINX_VERSION'])
  118. element.set("date", datetime.now().date().isoformat())
  119. releases.insert(0, element)
  120. # Ensure 4 spaces
  121. etree.indent(root, space=" ")
  122. with open(xml_file, "wb") as f:
  123. f.write(
  124. etree.tostring(
  125. tree,
  126. pretty_print=True,
  127. encoding="UTF-8",
  128. doctype='<?xml version="1.0" encoding="UTF-8"?>',
  129. )
  130. )
  131. - name: Push flatpak update
  132. working-directory: flathub
  133. env:
  134. COMMIT_MESSAGE: ${{ steps.metadata.outputs.commit_message }}
  135. run: |
  136. git config user.name "${{ env.GIT_COMMITTER_NAME }}"
  137. git config user.email "${{ env.GIT_COMMITTER_EMAIL }}"
  138. git add .
  139. git commit -m "$COMMIT_MESSAGE"
  140. git push origin master