From f02646552333044b6019473ecf3457ad681b697b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Fearn?= <26871415+flavioislima@users.noreply.github.com> Date: Sun, 31 Mar 2024 23:23:19 +0200 Subject: [PATCH] [CI] Fix Flathub Workflow (#3661) * [CI] Fix Flathub Workflow * Update versionNames in package.json --------- Co-authored-by: Flavio F Lima --- flathub/update-flathub.ts | 89 +++++++++++++++++++++++++-------------- package.json | 8 ++-- yarn.lock | 19 ++++++--- 3 files changed, 73 insertions(+), 43 deletions(-) diff --git a/flathub/update-flathub.ts b/flathub/update-flathub.ts index 3e41f1d6b8..6932017f63 100644 --- a/flathub/update-flathub.ts +++ b/flathub/update-flathub.ts @@ -3,8 +3,7 @@ import * as crypto from 'crypto' import * as os from 'os' import * as child_process from 'child_process' import axios from 'axios' -import * as convert from 'xml-js' -import { Element } from 'xml-js' +import { XMLParser, XMLBuilder } from 'fast-xml-parser' async function main() { console.log('tag name: ', process.env.RELEASE_VERSION) @@ -15,12 +14,12 @@ async function main() { console.log('updating url in com.heroicgameslauncher.hgl.yml') const ymlFilePath = './com.heroicgameslauncher.hgl/com.heroicgameslauncher.hgl.yml' - let hpYml = fs.readFileSync(ymlFilePath).toString() + let heroicYml = fs.readFileSync(ymlFilePath).toString() const releaseString = `https://github.com/${repoName}/releases/download/${ process.env.RELEASE_VERSION }/Heroic-${process.env.RELEASE_VERSION?.substring(1)}.AppImage` - hpYml = hpYml.replace( + heroicYml = heroicYml.replace( /https:\/\/github.com\/Heroic-Games-Launcher\/HeroicGamesLauncher\/releases\/download\/v.*..*..*\/Heroic-.*..*..*.AppImage/, releaseString ) @@ -47,9 +46,9 @@ async function main() { const sha512 = hashSum.digest('hex') fs.rmSync(outputFile) - hpYml = hpYml.replace(/sha512: [0-9, a-f]{128}/, `sha512: ${sha512}`) + heroicYml = heroicYml.replace(/sha512: [0-9, a-f]{128}/, `sha512: ${sha512}`) - fs.writeFileSync(ymlFilePath, hpYml) + fs.writeFileSync(ymlFilePath, heroicYml) // update release version and date on xml tag in com.heroicgameslauncher.hgl.metainfo.xml console.log( @@ -57,16 +56,16 @@ async function main() { ) const xmlFilePath = './com.heroicgameslauncher.hgl/com.heroicgameslauncher.hgl.metainfo.xml' - let hpXml = fs.readFileSync(xmlFilePath).toString() + let heroicXml = fs.readFileSync(xmlFilePath).toString() const date = new Date() const isoDate = date.toISOString().slice(0, 10) - hpXml = hpXml.replace( + heroicXml = heroicXml.replace( /release version="v.*..*..*" date="[0-9]{4}-[0-9]{2}-[0-9]{2}"/, `release version="${process.env.RELEASE_VERSION}" date="${isoDate}"` ) - fs.writeFileSync(xmlFilePath, hpXml) + fs.writeFileSync(xmlFilePath, heroicXml) console.log( 'Finished updating flathub release! Be sure to update release notes manually before merging.' ) @@ -101,43 +100,69 @@ async function main() { ) const releaseNotesJson = JSON.parse(releaseNotesStdOut) - const releaseNotesComponents = releaseNotesJson.body.split('\n') + const releaseNotesComponents: string[] = releaseNotesJson.body.split('\n') - const hpXmlJson = convert.xml2js(hpXml, { compact: false }) as Element - const releaseNotesElements: Element[] = [] + // XML Modification with fast-xml-parser + heroicXml = fs.readFileSync(xmlFilePath).toString() + + const parserOptions = { + ignoreAttributes: false, + preserveOrder: true, + format: true, // Enable formatting + indentBy: ' ' // Use two spaces for indentation + } + + const parser = new XMLParser(parserOptions) + + const heroicXmlJson = parser.parse(heroicXml) + + const builder = new XMLBuilder(parserOptions) + + const releaseNotesElements: Record>>[] = + [] // An array to hold generated
  • elements for (const [i, releaseComponent_i] of releaseNotesComponents.entries()) { - //update metainfo hpXml if (i === 0) continue if (!releaseComponent_i.startsWith('*')) continue if (releaseComponent_i.includes('http')) continue - const releaseNoteElement: Element = { - type: 'element', - name: 'li', - elements: [ - { - type: 'text', - text: releaseComponent_i.slice(1) //remove the asterisk - } + + const li = releaseComponent_i + .replace(/\n/g, '') + .replace(/\r/g, '') + .replace(/\t/g, '') + .slice(1) + .trim() + + // Creating the
  • element (compatible with fast-xml-parser) + const releaseNoteElement = { + li: [ + { '#text': li } // Directly set the text within the
  • element ] } + releaseNotesElements.push(releaseNoteElement) } - const componentsTag = hpXmlJson.elements?.[0] - const releasesTag = componentsTag?.elements?.find( - (val) => val.name === 'releases' - ) //.releases.release.description.ul = - const releaseListTag = - releasesTag?.elements?.[0].elements?.[0].elements?.find( - (val) => val.name === 'ul' - ) + const componentsTag = heroicXmlJson[1].component + // Locate the 'releases' element within the 'componentsTag' + const releasesTag = componentsTag.find((val) => val.releases !== undefined) + + // Proceed to find the
      element as before + const releaseListTag = releasesTag?.releases[0].release[0].description[1] + if (releaseListTag === undefined) { throw 'releaseListTag ul undefined' } - releaseListTag.elements = releaseNotesElements - hpXml = convert.js2xml(hpXmlJson) - fs.writeFileSync(xmlFilePath, hpXml) + + releaseListTag.ul = [...releaseNotesElements] // Set the
        element to the generated
      • elements + + console.log('new releaseListTag = ', JSON.stringify(releaseListTag, null, 2)) + + const updatedHeroicXml = builder.build(heroicXmlJson) + + console.log('updatedheroicXml = ', updatedHeroicXml) + + fs.writeFileSync(xmlFilePath, updatedHeroicXml) console.log( 'Finished updating flathub release! Please review and merge the flathub repo PR manually.' diff --git a/package.json b/package.json index 3f189246e2..58a3d63a6f 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "heroic", - "version": "2.13.0", + "version": "2.14.0", "versionNames": { - "stable": "Dorry & Broggy", + "stable": "Flame Emperor Sabo", "beta": "Caesar Clown" }, "private": false, @@ -131,6 +131,7 @@ "eslint-config-prettier": "8.7.0", "eslint-plugin-import": "2.27.5", "eslint-plugin-react": "7.31.11", + "fast-xml-parser": "^4.3.6", "husky": "8.0.3", "i18next-parser": "7.7.0", "jest": "29.5.0", @@ -147,8 +148,7 @@ "unimported": "1.26.0", "vite": "3.2.8", "vite-plugin-electron": "0.10.2", - "vite-plugin-svgr": "2.4.0", - "xml-js": "1.6.11" + "vite-plugin-svgr": "2.4.0" }, "resolutions": { "ts-morph": "17.0.1" diff --git a/yarn.lock b/yarn.lock index bfa508c93e..4573dea9d1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4292,6 +4292,13 @@ fast-levenshtein@^2.0.6: resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" integrity sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw== +fast-xml-parser@^4.3.6: + version "4.3.6" + resolved "https://registry.yarnpkg.com/fast-xml-parser/-/fast-xml-parser-4.3.6.tgz#190f9d99097f0c8f2d3a0e681a10404afca052ff" + integrity sha512-M2SovcRxD4+vC493Uc2GZVcZaj66CCJhWurC4viynVSTvrpErCShNcDz1lAho6n9REQKvL/ll4A4/fw6Y9z8nw== + dependencies: + strnum "^1.0.5" + fastq@^1.6.0: version "1.15.0" resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.15.0.tgz#d04d07c6a2a68fe4599fea8d2e103a937fae6b3a" @@ -8326,6 +8333,11 @@ strip-json-comments@^3.1.0, strip-json-comments@^3.1.1: resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006" integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== +strnum@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/strnum/-/strnum-1.0.5.tgz#5c4e829fe15ad4ff0d20c3db5ac97b73c9b072db" + integrity sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA== + strtok3@^6.2.4: version "6.3.0" resolved "https://registry.yarnpkg.com/strtok3/-/strtok3-6.3.0.tgz#358b80ffe6d5d5620e19a073aa78ce947a90f9a0" @@ -9269,13 +9281,6 @@ ws@^7.3.1: resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.9.tgz#54fa7db29f4c7cec68b1ddd3a89de099942bb591" integrity sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q== -xml-js@1.6.11: - version "1.6.11" - resolved "https://registry.yarnpkg.com/xml-js/-/xml-js-1.6.11.tgz#927d2f6947f7f1c19a316dd8eea3614e8b18f8e9" - integrity sha512-7rVi2KMfwfWFl+GpPg6m80IVMWXLRjO+PxTq7V2CDhoGak0wzYzFgUY2m4XJ47OGdXd8eLE8EmwfAmdjw7lC1g== - dependencies: - sax "^1.2.4" - xmlbuilder@>=11.0.1, xmlbuilder@^15.1.1: version "15.1.1" resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-15.1.1.tgz#9dcdce49eea66d8d10b42cae94a79c3c8d0c2ec5"