flatpak.yml 5.4 KB

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