Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package & distribute frontend bundle when doing releases for Linux #2500

Merged
merged 4 commits into from
Jun 4, 2024
Merged
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pnpm-lock.yaml -diff
package-lock.json -diff
.github/actions/publish-artifacts/dist/index.js -diff
39 changes: 21 additions & 18 deletions .github/actions/publish-artifacts/dist/index.js

Large diffs are not rendered by default.

26 changes: 19 additions & 7 deletions .github/actions/publish-artifacts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import client from '@actions/artifact';
import * as core from '@actions/core';
import * as glob from '@actions/glob';
import * as io from '@actions/io';
import { exists } from '@actions/io/lib/io-util';

type OS = 'darwin' | 'windows' | 'linux';
type Arch = 'x64' | 'arm64';
Expand Down Expand Up @@ -43,21 +44,32 @@ const PROFILE = core.getInput('profile');
const BUNDLE_DIR = `target/${TARGET}/${PROFILE}/bundle`;
const ARTIFACTS_DIR = '.artifacts';
const ARTIFACT_BASE = `Spacedrive-${OS}-${ARCH}`;
const FRONT_END_BUNDLE = 'apps/desktop/dist.tar.xz';
const UPDATER_ARTIFACT_NAME = `Spacedrive-Updater-${OS}-${ARCH}`;
const FRONTEND_ARCHIVE_NAME = `Spacedrive-frontend-${OS}-${ARCH}`;

async function globFiles(pattern: string) {
const globber = await glob.create(pattern);
return await globber.glob();
}

async function uploadFrontend() {
if (!(await exists(FRONT_END_BUNDLE))) {
console.error(`Frontend archive not found`);
return;
}

await client.uploadArtifact(FRONTEND_ARCHIVE_NAME, [FRONT_END_BUNDLE], 'apps/desktop');
}

async function uploadUpdater(updater: BuildTarget['updater']) {
if (!updater) return;
const { bundle, bundleExt, archiveExt } = updater;
const fullExt = `${bundleExt}.${archiveExt}`;
const files = await globFiles(`${BUNDLE_DIR}/${bundle}/*.${fullExt}*`);

const updaterPath = files.find((file) => file.endsWith(fullExt));
if (!updaterPath) return console.error(`Updater path not found. Files: ${files}`);
if (!updaterPath) throw new Error(`Updater path not found. Files: ${files}`);

const artifactPath = `${ARTIFACTS_DIR}/${UPDATER_ARTIFACT_NAME}.${archiveExt}`;

Expand All @@ -76,7 +88,7 @@ async function uploadStandalone({ bundle, ext }: TargetConfig) {
const files = await globFiles(`${BUNDLE_DIR}/${bundle}/*.${ext}*`);

const standalonePath = files.find((file) => file.endsWith(ext));
if (!standalonePath) return console.error(`Standalone path not found. Files: ${files}`);
if (!standalonePath) throw new Error(`Standalone path not found. Files: ${files}`);

const artifactName = `${ARTIFACT_BASE}.${ext}`;
const artifactPath = `${ARTIFACTS_DIR}/${artifactName}`;
Expand All @@ -90,10 +102,10 @@ async function run() {

const { updater, standalone } = OS_TARGETS[OS];

await uploadUpdater(updater);

for (const config of standalone) {
await uploadStandalone(config);
}
await Promise.all([
uploadUpdater(updater),
uploadFrontend(),
...standalone.map((config) => uploadStandalone(config))
]);
}
run();
2 changes: 1 addition & 1 deletion .github/actions/publish-artifacts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"lint": "eslint . --cache"
},
"dependencies": {
"@actions/artifact": "^2.1.3",
"@actions/artifact": "^2.1.7",
"@actions/core": "^1.10.1",
"@actions/glob": "^0.4.0",
"@actions/io": "^1.1.3"
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: Release

on:
pull_request:
paths:
- '.github/workflows/release.yml'
workflow_dispatch:
# NOTE: For Linux builds, we can only build with Ubuntu. It should be the oldest base system we intend to support. See PR-759 & https://tauri.app/v1/guides/building/linux for reference.

# From: https://github.com/rust-lang/rust-analyzer/blob/master/.github/workflows/release.yaml#L13-L21
env:
Expand Down Expand Up @@ -112,6 +114,12 @@ jobs:
APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}

- name: Package frontend
if: ${{ runner.os == 'Linux' }}
run: |
set -eux
XZ_OPT='-T0 -7' tar -cJf apps/desktop/dist.tar.xz -C apps/desktop/dist .

- name: Publish Artifacts
uses: ./.github/actions/publish-artifacts
with:
Expand Down
Loading
Loading