flatpak.yml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. name: Flatpak release job
  2. on:
  3. workflow_call:
  4. inputs:
  5. ryujinx_base_version:
  6. required: true
  7. type: string
  8. ryujinx_version_minor:
  9. required: true
  10. type: string
  11. concurrency: flatpak-release
  12. jobs:
  13. release:
  14. runs-on: ubuntu-latest
  15. env:
  16. NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
  17. GIT_COMMITTER_NAME: "RyujinxBot"
  18. GIT_COMMITTER_EMAIL: "61127645+RyujinxBot@users.noreply.github.com"
  19. RYUJINX_PROJECT_FILE: "Ryujinx/Ryujinx.csproj"
  20. NUGET_SOURCES_DESTDIR: "nuget-sources"
  21. RYUJINX_VERSION: "${{ inputs.ryujinx_base_version }}. ${{ inputs.ryujinx_version_minor }}"
  22. steps:
  23. - uses: actions/checkout@v3
  24. with:
  25. path: Ryujinx
  26. - uses: actions/setup-dotnet@v3
  27. with:
  28. global-json-file: Ryujinx/global.json
  29. - name: Get version info
  30. id: version_info
  31. working-directory: Ryujinx
  32. run: |
  33. echo "git_short_hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  34. - uses: actions/checkout@v3
  35. with:
  36. repository: flathub/org.ryujinx.Ryujinx
  37. token: ${{ secrets.RYUJINX_BOT_PAT }}
  38. submodules: recursive
  39. path: flathub
  40. - name: Install dependencies
  41. run: python -m pip install PyYAML lxml
  42. - name: Restore Nuget packages
  43. run: dotnet restore Ryujinx/${{ env.RYUJINX_PROJECT_FILE }}
  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_short_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. yaml_file = "flathub/org.ryujinx.Ryujinx.yml"
  83. xml_file = "flathub/org.ryujinx.Ryujinx.appdata.xml"
  84. with open(yaml_file, "r") as f:
  85. data = yaml.safe_load(f)
  86. for source in data["modules"][0]["sources"]:
  87. if type(source) is str:
  88. continue
  89. if (
  90. source["type"] == "git"
  91. and source["url"] == "https://github.com/Ryujinx/Ryujinx.git"
  92. ):
  93. source["commit"] = os.environ['RYUJINX_GIT_HASH']
  94. is_same_version = data["modules"][0]["build-options"]["env"]["RYUJINX_VERSION"] == os.environ['RYUJINX_VERSION']
  95. with open(os.environ['GITHUB_OUTPUT'], "a") as gh_out:
  96. if is_same_version:
  97. gh_out.write(f"commit_message=Retry update to {os.environ['RYUJINX_VERSION']}")
  98. else:
  99. gh_out.write(f"commit_message=Update to {os.environ['RYUJINX_VERSION']}")
  100. if not is_same_version:
  101. data["modules"][0]["build-options"]["env"]["RYUJINX_VERSION"] = os.environ['RYUJINX_VERSION']
  102. with open(yaml_file, "w") as f:
  103. yaml.safe_dump(data, f, sort_keys=False)
  104. parser = etree.XMLParser(remove_blank_text=True)
  105. tree = etree.parse(xml_file, parser)
  106. root = tree.getroot()
  107. releases = root.find("releases")
  108. element = etree.Element("release")
  109. element.set("version", os.environ['RYUJINX_VERSION'])
  110. element.set("date", datetime.now().date().isoformat())
  111. releases.insert(0, element)
  112. # Ensure 4 spaces
  113. etree.indent(root, space=" ")
  114. with open(xml_file, "wb") as f:
  115. f.write(
  116. etree.tostring(
  117. tree,
  118. pretty_print=True,
  119. encoding="UTF-8",
  120. doctype='<?xml version="1.0" encoding="UTF-8"?>',
  121. )
  122. )
  123. - name: Push flatpak update
  124. working-directory: flathub
  125. env:
  126. COMMIT_MESSAGE: ${{ steps.metadata.outputs.commit_message }}
  127. run: |
  128. git config user.name "${{ env.GIT_COMMITTER_NAME }}"
  129. git config user.email "${{ env.GIT_COMMITTER_EMAIL }}"
  130. git add .
  131. git commit -m "$COMMIT_MESSAGE"
  132. git push origin master