Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .github/workflows/desktop.release.reuse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ jobs:
run: |
yarn run electron-builder --mac --x64 --publish=never --c.extraMetadata.version=${{ env.APP_VERSION }}
node scripts/fixMacZip.js ${{ env.APP_VERSION }}
mkdir -p dist/update-meta && cp dist/latest-mac.yml dist/update-meta/mac-x64.yml
- name: MacArm64
run: yarn run electron-builder --mac --arm64 --publish=never --c.extraMetadata.version=${{ env.APP_VERSION }}
run: |
yarn run electron-builder --mac --arm64 --publish=never --c.extraMetadata.version=${{ env.APP_VERSION }}
mkdir -p dist/update-meta && cp dist/latest-mac.yml dist/update-meta/mac-arm64.yml

- name: Upload
uses: actions/upload-artifact@v4.0.0
Expand All @@ -55,6 +58,7 @@ jobs:
packages/desktop/dist/*.blockmap
packages/desktop/dist/*.yml
packages/desktop/dist/*.yaml
packages/desktop/dist/update-meta/**

Linux-AppImage-X64:
name: Linux AppImage X64
Expand Down Expand Up @@ -91,6 +95,7 @@ jobs:
- name: AppImageX64
run: |
yarn run electron-builder --linux --x64 -c.linux.target=AppImage --publish=never --c.extraMetadata.version=${{ env.APP_VERSION }}
mkdir -p dist/update-meta && cp dist/latest-linux.yml dist/update-meta/linux-appimage-x64.yml

- name: Upload
uses: actions/upload-artifact@v4.0.0
Expand All @@ -100,6 +105,7 @@ jobs:
packages/desktop/dist/*.AppImage
packages/desktop/dist/*.yml
packages/desktop/dist/*.yaml
packages/desktop/dist/update-meta/**

Linux-AppImage-ARM64:
name: Linux AppImage ARM64
Expand Down Expand Up @@ -136,6 +142,7 @@ jobs:
- name: AppImageArm64
run: |
yarn run electron-builder --linux --arm64 -c.linux.target=AppImage --publish=never --c.extraMetadata.version=${{ env.APP_VERSION }}
mkdir -p dist/update-meta && cp dist/latest-linux-arm64.yml dist/update-meta/linux-appimage-arm64.yml

- name: Upload
uses: actions/upload-artifact@v4.0.0
Expand All @@ -145,6 +152,7 @@ jobs:
packages/desktop/dist/*.AppImage
packages/desktop/dist/*.yml
packages/desktop/dist/*.yaml
packages/desktop/dist/update-meta/**

Linux-Dir-X64:
name: Linux Dir X64
Expand Down Expand Up @@ -247,6 +255,7 @@ jobs:
run: |
yarn run webpack --config desktop.webpack.prod.js --env deb
yarn run electron-builder --linux --x64 -c.linux.target=deb --publish=never --c.extraMetadata.version=${{ env.APP_VERSION }}
mkdir -p dist/update-meta && cp dist/latest-linux.yml dist/update-meta/linux-deb-x64.yml

- name: Upload
uses: actions/upload-artifact@v4.0.0
Expand All @@ -256,6 +265,7 @@ jobs:
packages/desktop/dist/*.deb
packages/desktop/dist/*.yml
packages/desktop/dist/*.yaml
packages/desktop/dist/update-meta/**

Linux-Deb-ARM64:
name: Linux Deb ARM64
Expand Down Expand Up @@ -292,6 +302,7 @@ jobs:
run: |
yarn run webpack --config desktop.webpack.prod.js --env deb
yarn run electron-builder --linux --arm64 -c.linux.target=deb --publish=never --c.extraMetadata.version=${{ env.APP_VERSION }}
mkdir -p dist/update-meta && cp dist/latest-linux-arm64.yml dist/update-meta/linux-deb-arm64.yml

- name: Upload
uses: actions/upload-artifact@v4.0.0
Expand All @@ -301,6 +312,7 @@ jobs:
packages/desktop/dist/*.deb
packages/desktop/dist/*.yml
packages/desktop/dist/*.yaml
packages/desktop/dist/update-meta/**

Linux-Snap:
name: Linux Snap
Expand Down Expand Up @@ -397,6 +409,9 @@ jobs:
- name: Generate Checksums
run: node scripts/sums.mjs

- name: Merge update manifests
run: node scripts/merge-update-manifests.mjs

- name: Generate Release Notes
uses: ./actions/release-notes
with:
Expand Down
81 changes: 81 additions & 0 deletions packages/desktop/scripts/merge-update-manifests.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import yaml from 'js-yaml'

const distDir = path.join(path.dirname(fileURLToPath(import.meta.url)), '../dist')
const metaDir = path.join(distDir, 'update-meta')

/** output manifest -> preserved fragment ids in dist/update-meta/ */
const MANIFESTS = {
'latest-mac.yml': ['mac-x64', 'mac-arm64'],
'latest-linux.yml': ['linux-appimage-x64', 'linux-deb-x64'],
'latest-linux-arm64.yml': ['linux-appimage-arm64', 'linux-deb-arm64'],
}

/** preferred top-level path for electron-updater */
const PRIMARY_URL = {
'latest-mac.yml': [/-mac-x64\.zip$/i, /-mac-arm64\.zip$/i],
'latest-linux.yml': [/-linux-x86_64\.AppImage$/i, /-linux-amd64\.deb$/i],
'latest-linux-arm64.yml': [/-linux-arm64\.AppImage$/i, /-linux-arm64\.deb$/i],
}

function readMeta(id) {
const filePath = path.join(metaDir, `${id}.yml`)
return fs.existsSync(filePath) ? yaml.load(fs.readFileSync(filePath, 'utf8')) : null
}

function mergeFiles(docs) {
const byUrl = new Map()
for (const doc of docs) {
for (const entry of doc?.files ?? []) {
if (entry?.url) {
byUrl.set(entry.url, { ...byUrl.get(entry.url), ...entry })
}
}
}
return [...byUrl.values()].sort((a, b) => a.url.localeCompare(b.url))
}

function pickPrimary(files, manifestName) {
for (const pattern of PRIMARY_URL[manifestName] ?? []) {
const match = files.find((f) => pattern.test(f.url))
if (match) {
return match
}
}
return files[0]
}

for (const [manifestName, fragmentIds] of Object.entries(MANIFESTS)) {
const docs = fragmentIds.map(readMeta).filter(Boolean)
if (docs.length === 0) {
continue
}

const versions = [...new Set(docs.map((d) => d.version).filter(Boolean))]
if (versions.length > 1) {
throw new Error(`${manifestName}: conflicting versions ${versions.join(', ')}`)
}

const files = mergeFiles(docs)
if (files.length === 0) {
continue
}

const primary = pickPrimary(files, manifestName)
const merged = {
version: versions[0],
files,
path: primary.url,
sha512: primary.sha512,
releaseDate: docs
.map((d) => d.releaseDate)
.filter(Boolean)
.sort()
.at(-1),
}

fs.writeFileSync(path.join(distDir, manifestName), yaml.dump(merged, { lineWidth: Infinity }))
console.log(`${manifestName}: ${files.length} file(s)`)
}
Loading