flatpak.yml 5.4 KB

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