flatpak.yml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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@v3
  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: dotnet publish -c Release -r linux-x64 Ryujinx/${{ env.RYUJINX_PROJECT_FILE }} --self-contained
  44. - name: Generate nuget_sources.json
  45. shell: python
  46. run: |
  47. from pathlib import Path
  48. import base64
  49. import binascii
  50. import json
  51. import os
  52. sources = []
  53. for path in Path(os.environ['NUGET_PACKAGES']).glob('**/*.nupkg.sha512'):
  54. name = path.parent.parent.name
  55. version = path.parent.name
  56. filename = '{}.{}.nupkg'.format(name, version)
  57. url = 'https://api.nuget.org/v3-flatcontainer/{}/{}/{}'.format(name, version, filename)
  58. with path.open() as fp:
  59. sha512 = binascii.hexlify(base64.b64decode(fp.read())).decode('ascii')
  60. sources.append({
  61. 'type': 'file',
  62. 'url': url,
  63. 'sha512': sha512,
  64. 'dest': os.environ['NUGET_SOURCES_DESTDIR'],
  65. 'dest-filename': filename,
  66. })
  67. with open('flathub/nuget_sources.json', 'w') as fp:
  68. json.dump(sources, fp, indent=4)
  69. - name: Update flatpak metadata
  70. id: metadata
  71. env:
  72. RYUJINX_GIT_HASH: ${{ steps.version_info.outputs.git_hash }}
  73. shell: python
  74. run: |
  75. import hashlib
  76. import hmac
  77. import json
  78. import os
  79. import yaml
  80. from datetime import datetime
  81. from lxml import etree
  82. # Ensure we don't destroy multiline strings
  83. def str_presenter(dumper, data):
  84. if len(data.splitlines()) > 1:
  85. return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|")
  86. return dumper.represent_scalar("tag:yaml.org,2002:str", data)
  87. yaml.representer.SafeRepresenter.add_representer(str, str_presenter)
  88. yaml_file = "flathub/org.ryujinx.Ryujinx.yml"
  89. xml_file = "flathub/org.ryujinx.Ryujinx.appdata.xml"
  90. with open(yaml_file, "r") as f:
  91. data = yaml.safe_load(f)
  92. for source in data["modules"][0]["sources"]:
  93. if type(source) is str:
  94. continue
  95. if (
  96. source["type"] == "git"
  97. and source["url"] == "https://github.com/Ryujinx/Ryujinx.git"
  98. ):
  99. source["commit"] = os.environ['RYUJINX_GIT_HASH']
  100. is_same_version = data["modules"][0]["build-options"]["env"]["RYUJINX_VERSION"] == os.environ['RYUJINX_VERSION']
  101. with open(os.environ['GITHUB_OUTPUT'], "a") as gh_out:
  102. if is_same_version:
  103. gh_out.write(f"commit_message=Retry update to {os.environ['RYUJINX_VERSION']}")
  104. else:
  105. gh_out.write(f"commit_message=Update to {os.environ['RYUJINX_VERSION']}")
  106. if not is_same_version:
  107. data["modules"][0]["build-options"]["env"]["RYUJINX_VERSION"] = os.environ['RYUJINX_VERSION']
  108. with open(yaml_file, "w") as f:
  109. yaml.safe_dump(data, f, sort_keys=False)
  110. parser = etree.XMLParser(remove_blank_text=True)
  111. tree = etree.parse(xml_file, parser)
  112. root = tree.getroot()
  113. releases = root.find("releases")
  114. element = etree.Element("release")
  115. element.set("version", os.environ['RYUJINX_VERSION'])
  116. element.set("date", datetime.now().date().isoformat())
  117. releases.insert(0, element)
  118. # Ensure 4 spaces
  119. etree.indent(root, space=" ")
  120. with open(xml_file, "wb") as f:
  121. f.write(
  122. etree.tostring(
  123. tree,
  124. pretty_print=True,
  125. encoding="UTF-8",
  126. doctype='<?xml version="1.0" encoding="UTF-8"?>',
  127. )
  128. )
  129. - name: Push flatpak update
  130. working-directory: flathub
  131. env:
  132. COMMIT_MESSAGE: ${{ steps.metadata.outputs.commit_message }}
  133. run: |
  134. git config user.name "${{ env.GIT_COMMITTER_NAME }}"
  135. git config user.email "${{ env.GIT_COMMITTER_EMAIL }}"
  136. git add .
  137. git commit -m "$COMMIT_MESSAGE"
  138. git push origin master