Skip to content

Commit 97ccff4

Browse files
authored
Merge pull request #470 from Nifury/patch
2 parents 023510e + 4aa0a42 commit 97ccff4

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

.github/actions/winget/index.js

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const exec = require('@actions/exec');
33
const core = require("@actions/core");
44
const glob = require('@actions/glob');
55
const path = require('path');
6-
const compareVersions = require('compare-versions');
6+
const compareVersions = require('compare-versions').compareVersions;
77
const fs = require('fs/promises');
88
const fsSync = require('fs');
99
const io = require('@actions/io');
@@ -21,18 +21,17 @@ async function run() {
2121
});
2222
const idx = newVersion.lastIndexOf('-');
2323
if (idx !== -1)
24-
newVersion = newVersion.substr(0, idx);
24+
newVersion = newVersion.substring(0, idx);
2525
const assets = JSON.parse(core.getInput('assets', {
2626
required: true,
2727
}));
28-
let x86Url, x64Url;
28+
const typeToUrl = new Map();
2929
for (const data of assets) {
30-
if (data.browser_download_url.endsWith('.exe')) {
31-
if (data.browser_download_url.includes('x86'))
32-
x86Url = data.browser_download_url;
33-
else
34-
x64Url = data.browser_download_url;
35-
}
30+
const type = data.name.split('_').pop();
31+
typeToUrl.set(type, {
32+
url: data.browser_download_url,
33+
digest: data.digest,
34+
});
3635
}
3736

3837
await syncRepo(token);
@@ -49,7 +48,7 @@ async function run() {
4948
} catch (e) {
5049
}
5150

52-
await updateInstaller(latestVersionPath, newVersionPath, latestVersion, newVersion, x86Url, x64Url);
51+
await updateInstaller(latestVersionPath, newVersionPath, latestVersion, newVersion, typeToUrl);
5352
await replaceContent(latestVersionPath, newVersionPath, latestVersion, newVersion, 'eloston.ungoogled-chromium.locale.en-US.yaml');
5453
await replaceContent(latestVersionPath, newVersionPath, latestVersion, newVersion, 'eloston.ungoogled-chromium.yaml');
5554

@@ -72,30 +71,26 @@ async function replaceContent(latestVersionPath, newVersionPath, latestVersion,
7271
await fs.writeFile(path.join(newVersionPath, fileName), newContent, {encoding: 'utf-8'});
7372
}
7473

75-
async function updateInstaller(latestVersionPath, newVersionPath, latestVersion, newVersion, x86Url, x64Url) {
76-
const x86Hash = await calculateSHA256(x86Url);
77-
const x64Hash = await calculateSHA256(x64Url);
74+
async function updateInstaller(latestVersionPath, newVersionPath, latestVersion, newVersion, typeToUrl) {
7875
const content = await fs.readFile(path.join(latestVersionPath, 'eloston.ungoogled-chromium.installer.yaml'), {encoding: 'utf-8'});
7976
const data = yaml.load(content);
80-
let oldX86Url, oldX64Url, oldX86Hash, oldX64Hash;
77+
data.PackageVersion = newVersion;
78+
data.ReleaseDate = new Date().toLocaleDateString('en-CA');
8179
for (const installer of data.Installers) {
82-
if (installer.Architecture === 'x86') {
83-
oldX86Url = installer.InstallerUrl;
84-
oldX86Hash = installer.InstallerSha256;
80+
const type = `${installer.Architecture}.${installer.InstallerType}`;
81+
const {url, digest} = typeToUrl.get(type);
82+
installer.InstallerUrl = url;
83+
let sha256 = '';
84+
if (digest.startsWith('sha256:')) {
85+
sha256 = digest.slice(7).toUpperCase();
8586
} else {
86-
oldX64Url = installer.InstallerUrl;
87-
oldX64Hash = installer.InstallerSha256;
87+
sha256 = await calculateSHA256(url);
8888
}
89+
installer.InstallerSha256 = sha256;
8990
}
9091

91-
const newContent = content
92-
.replaceAll(`PackageVersion: ${data.PackageVersion}`, `PackageVersion: ${newVersion}`)
93-
.replaceAll(`ReleaseDate: ${data.ReleaseDate}`, `ReleaseDate: ${new Date().toLocaleDateString('en-CA')}`)
94-
.replaceAll(oldX86Url, x86Url)
95-
.replaceAll(oldX86Hash, x86Hash)
96-
.replaceAll(oldX64Url, x64Url)
97-
.replaceAll(oldX64Hash, x64Hash);
98-
92+
// Update verions in RelativeFilePath
93+
const newContent = yaml.dump(data, {noRefs: true, lineWidth: -1, condenseFlow: true}).replaceAll(latestVersion, newVersion);
9994
await fs.writeFile(path.join(newVersionPath, 'eloston.ungoogled-chromium.installer.yaml'), newContent, {encoding: 'utf-8'});
10095
}
10196

@@ -117,4 +112,4 @@ async function syncRepo(token) {
117112
await exec.exec('git', ['push', 'origin', 'master', '--force'], {cwd: '.\\winget-pkgs'});
118113
}
119114

120-
run().catch(err => core.setFailed(err.message));
115+
run().catch(err => core.setFailed(err.message));
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"dependencies": {
3-
"@actions/core": "^1.8.2",
3+
"@actions/core": "^1.11.1",
44
"@actions/exec": "^1.1.1",
5-
"@actions/glob": "^0.3.0",
6-
"@actions/io": "^1.1.2",
5+
"@actions/glob": "^0.5.0",
6+
"@actions/io": "^1.1.3",
77
"js-yaml": "^4.1.0",
8-
"compare-versions": "^4.1.3",
8+
"compare-versions": "^6.1.1",
99
"follow-redirects": "^1.15.1"
1010
}
1111
}

0 commit comments

Comments
 (0)