flatpak.yml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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_short_hash=$(git rev-parse --short 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_short_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. yaml_file = "flathub/org.ryujinx.Ryujinx.yml"
  80. xml_file = "flathub/org.ryujinx.Ryujinx.appdata.xml"
  81. with open(yaml_file, "r") as f:
  82. data = yaml.safe_load(f)
  83. for source in data["modules"][0]["sources"]:
  84. if type(source) is str:
  85. continue
  86. if (
  87. source["type"] == "git"
  88. and source["url"] == "https://github.com/Ryujinx/Ryujinx.git"
  89. ):
  90. source["commit"] = os.environ['RYUJINX_GIT_HASH']
  91. is_same_version = data["modules"][0]["build-options"]["env"]["RYUJINX_VERSION"] == os.environ['RYUJINX_VERSION']
  92. with open(os.environ['GITHUB_OUTPUT'], "a") as gh_out:
  93. if is_same_version:
  94. gh_out.write(f"commit_message=Retry update to {os.environ['RYUJINX_VERSION']}")
  95. else:
  96. gh_out.write(f"commit_message=Update to {os.environ['RYUJINX_VERSION']}")
  97. if not is_same_version:
  98. data["modules"][0]["build-options"]["env"]["RYUJINX_VERSION"] = os.environ['RYUJINX_VERSION']
  99. with open(yaml_file, "w") as f:
  100. yaml.safe_dump(data, f, sort_keys=False)
  101. parser = etree.XMLParser(remove_blank_text=True)
  102. tree = etree.parse(xml_file, parser)
  103. root = tree.getroot()
  104. releases = root.find("releases")
  105. element = etree.Element("release")
  106. element.set("version", os.environ['RYUJINX_VERSION'])
  107. element.set("date", datetime.now().date().isoformat())
  108. releases.insert(0, element)
  109. # Ensure 4 spaces
  110. etree.indent(root, space=" ")
  111. with open(xml_file, "wb") as f:
  112. f.write(
  113. etree.tostring(
  114. tree,
  115. pretty_print=True,
  116. encoding="UTF-8",
  117. doctype='<?xml version="1.0" encoding="UTF-8"?>',
  118. )
  119. )
  120. - name: Push flatpak update
  121. working-directory: flathub
  122. env:
  123. COMMIT_MESSAGE: ${{ steps.metadata.outputs.commit_message }}
  124. run: |
  125. git config user.name "${{ env.GIT_COMMITTER_NAME }}"
  126. git config user.email "${{ env.GIT_COMMITTER_EMAIL }}"
  127. git add .
  128. git commit -m "$COMMIT_MESSAGE"
  129. git push origin master