Files
spacedrive/scripts/git.mjs
Vítor Vasconcellos d75a6e9b12 [ENG-1054] libheif for Linux (plus fixes) + Webp update (#1405)
* Move postinstall script to a preprep script
 - Fix libheif crate failing to build with our libheif
 - Rework CI due to postinstall to preprep changes

* Linux heif build script + Update webp

* Fix ctrl+c/ctrl+v bug

* Improve libheif linux script
 - Add support for linux aarch64
 - Add CI workflow to build libheif for linux
 - Some other misc fixes

* Fix libheif CI requires sudo

* Fix wrong path for libheif build.rs override in Windows

* Fix wrong path manipulations in libheif build script

* 🤦

* Use ubuntu-latest in libheif action
 - Specify glib version in target triple to support old distros
 - Fix libheif artifact publishing

* Fix artifact upload path again

* Add musl support for libheif
 - Remove unused files from libheif artifact
 - Add setup logic for libheif in postinstall script

* Build libheif for linux as a shared lib

* Fix meson not building the correct arch
 - Add logic to get git branch from githubs CI env vars

* libheif finnaly works on linux
 - Make spacedrive binary rpath point to where appimage and deb expects our libs to be
 - Add some logic to tauri.js to convince tauri to bundle our shared libs
 - Work-around appimage bundling step breaking sometimes
 - Add logic to handle sigint in tauri.js to ensure we clean up after ourselves
 - Rename postinstall.mjs to setup.mjs
 - Add logic to setup.mjs to point our dev build to our shared libs in linux

* Fix windows dekstop dev
 - Rename setup.mjs to preprep.mjs

* test cache-factory

* Fix preprep script not parsing the cross compilation target triple and always using the host info to download dependencies
 - Fix action env vars not being correctly passed
 - Remove possibility to pass multiple targests to rust action

* Don't compile mobile crates on desktop targets

* Remove cache-factory pull_request trigger

* remove patched tauri cli

* Use git plumbing command to get remote branch name
 - Fallback to reading .git/HEAD if remote name was not retrieved

* fix type

---------

Co-authored-by: Brendan Allan <brendonovich@outlook.com>
2023-10-03 17:31:33 +00:00

87 lines
2.2 KiB
JavaScript

import { exec as execCb } from 'node:child_process';
import * as fs from 'node:fs/promises';
import * as path from 'node:path';
import { env } from 'node:process';
import { promisify } from 'node:util';
const __debug = env.NODE_ENV === 'debug';
const exec = promisify(execCb);
/**
* @param {string} repoPath
* @returns {string?}
*/
async function getRemoteBranchName(repoPath) {
let branchName;
try {
branchName = (await exec('git symbolic-ref --short HEAD', { cwd: repoPath })).stdout.trim();
if (!branchName) throw 'Empty local branch name';
} catch (error) {
if (__debug) {
console.warn(`Failed to read git local branch name`);
console.error(error);
}
return null;
}
let remoteBranchName;
try {
remoteBranchName = (
await exec(`git for-each-ref --format="%(upstream:short)" refs/heads/${branchName}`, {
cwd: repoPath
})
).stdout.trim();
const [remote, branch] = remoteBranchName.split('/');
if (!branch) throw 'Empty remote branch name';
remoteBranchName = branch;
} catch (error) {
if (__debug) {
console.warn(`Failed to read git remote branch name`);
console.error(error);
}
return null;
}
return remoteBranchName;
}
// https://stackoverflow.com/q/3651860#answer-67151923
const REF_REGEX = /ref:\s+refs\/heads\/(?<branch>[^\s\x00-\x1F\:\?\[\\\^\~]+)/;
const GITHUB_REF_REGEX = /^refs\/heads\//;
/**
* @param {string} repoPath
* @returns {Promise<string[]>}
*/
export async function getGitBranches(repoPath) {
const branches = ['main', 'master'];
if (env.GITHUB_HEAD_REF) {
branches.unshift(env.GITHUB_HEAD_REF);
} else if (env.GITHUB_REF) {
branches.unshift(env.GITHUB_REF.replace(GITHUB_REF_REGEX, ''));
}
const remoteBranchName = await getRemoteBranchName(repoPath);
if (remoteBranchName) {
branches.unshift(remoteBranchName);
} else {
let head;
try {
head = await fs.readFile(path.join(repoPath, '.git', 'HEAD'), { encoding: 'utf8' });
} catch (error) {
if (__debug) {
console.warn(`Failed to read git HEAD file`);
console.error(error);
}
return branches;
}
const match = REF_REGEX.exec(head);
if (match?.groups?.branch) branches.unshift(match.groups.branch);
}
return branches;
}