aboutsummaryrefslogtreecommitdiff
path: root/.github/actions
diff options
context:
space:
mode:
authorPauline <git@ethanlibs.co>2023-10-14 22:27:27 -0400
committerPauline <git@ethanlibs.co>2023-10-14 22:27:27 -0400
commit2582162cea2b3a59cd21c78f8b73cb03d0acad40 (patch)
tree432057475f3b51850a85e2cba9969bcb79f3a8e6 /.github/actions
parent06f51ccdc496a6581d098edc424f3973e550221d (diff)
downloadNexus-2582162cea2b3a59cd21c78f8b73cb03d0acad40.tar.gz
Nexus-2582162cea2b3a59cd21c78f8b73cb03d0acad40.tar.bz2
Nexus-2582162cea2b3a59cd21c78f8b73cb03d0acad40.zip
refactor(trunk): refactor the entire project idk
Diffstat (limited to '.github/actions')
-rw-r--r--.github/actions/publish-artifacts/.gitignore2
-rw-r--r--.github/actions/publish-artifacts/action.yaml14
-rw-r--r--.github/actions/publish-artifacts/index.ts101
-rw-r--r--.github/actions/publish-artifacts/package.json17
-rw-r--r--.github/actions/publish-artifacts/tsconfig.json11
-rw-r--r--.github/actions/setup-pnpm/action.yml28
-rw-r--r--.github/actions/setup-rust/action.yaml52
-rw-r--r--.github/actions/setup-system/action.yml36
8 files changed, 261 insertions, 0 deletions
diff --git a/.github/actions/publish-artifacts/.gitignore b/.github/actions/publish-artifacts/.gitignore
new file mode 100644
index 0000000..5c4b4fd
--- /dev/null
+++ b/.github/actions/publish-artifacts/.gitignore
@@ -0,0 +1,2 @@
+# pls tell me there is a better way
+!dist
diff --git a/.github/actions/publish-artifacts/action.yaml b/.github/actions/publish-artifacts/action.yaml
new file mode 100644
index 0000000..c3679af
--- /dev/null
+++ b/.github/actions/publish-artifacts/action.yaml
@@ -0,0 +1,14 @@
+name: Publish artifacts
+description: Publishes artifacts after CI process
+inputs:
+ target:
+ description: target triples for built artifact
+ profile:
+ description: "'debug' or 'release'"
+ os:
+ description: "'darwin', 'windows', or 'linux'"
+ arch:
+ description: "'x86_64' or 'aarch64'"
+runs:
+ using: node20
+ main: dist/index.js
diff --git a/.github/actions/publish-artifacts/index.ts b/.github/actions/publish-artifacts/index.ts
new file mode 100644
index 0000000..8509194
--- /dev/null
+++ b/.github/actions/publish-artifacts/index.ts
@@ -0,0 +1,101 @@
+import * as artifact from '@actions/artifact';
+import * as core from '@actions/core';
+import * as glob from '@actions/glob';
+import * as io from '@actions/io';
+
+// script to build tauri bundles without pain
+
+type OS = 'darwin' | 'windows' | 'linux';
+type Arch = 'x64' | 'arm64'; // 'aarch64';
+// i could type this with tauri's config but idrc
+type TargetConfig = { bundle: string; ext: string };
+type BuildTarget = {
+ updater: TargetConfig;
+ standalone: Array<TargetConfig>;
+};
+
+const OS_TARGETS = {
+ darwin: {
+ updater: {
+ bundle: 'macos',
+ ext: 'app.tar.gz'
+ },
+ standalone: [{ ext: 'dmg', bundle: 'dmg' }]
+ },
+ windows: {
+ updater: {
+ bundle: 'msi',
+ ext: 'msi.zip'
+ },
+ standalone: [{ ext: 'msi', bundle: 'msi' }]
+ },
+ linux: {
+ updater: {
+ bundle: 'appimage',
+ ext: 'AppImage.tar.gz'
+ },
+ standalone: [
+ { ext: 'deb', bundle: 'deb' },
+ { ext: 'AppImage', bundle: 'appimage' }
+ ]
+ }
+} satisfies Record<OS, BuildTarget>;
+
+const OS: OS = core.getInput('os') as any;
+const ARCH: Arch = core.getInput('arch') as any;
+const TARGET = core.getInput('target');
+const PROFILE = core.getInput('profile');
+
+const BUNDLE_DIR = `target/${TARGET}/${PROFILE}/bundle`;
+const ARTIFACTS_DIR = '.artifacts';
+const ARTIFACT_BASE = `Nexus-${OS}-${ARCH}`;
+const UPDATER_ARTIFACT_NAME = `Nexus-Updater-${OS}-${ARCH}`;
+
+const client = artifact.create();
+
+// globby glob globber :3
+const globFiles = async (pattern: string) => {
+ const globber = await glob.create(pattern);
+ return await globber.glob();
+};
+
+const uploadUpdater = async ({ bundle, ext }: TargetConfig) => {
+ const files = await globFiles(`${BUNDLE_DIR}/${bundle}/*.${ext}*`);
+ const updaterPath = files.find((f) => f.endsWith(ext));
+
+ if (!updaterPath) return console.error(`updater path not found. ${files}`);
+
+ const artifactPath = `${ARTIFACTS_DIR}/${UPDATER_ARTIFACT_NAME}.${ext}`;
+
+ await io.cp(updaterPath, artifactPath);
+ await io.cp(`${updaterPath}.sig`, `${artifactPath}.sig`);
+
+ await client.uploadArtifact(
+ UPDATER_ARTIFACT_NAME,
+ [artifactPath, `${artifactPath}.sig`],
+ ARTIFACTS_DIR
+ );
+};
+
+const uploadStandalone = async ({ bundle, ext }: TargetConfig) => {
+ const files = await globFiles(`${BUNDLE_DIR}/${bundle}/*.${ext}*`);
+ const standalonePath = files.find((f) => f.endsWith(ext));
+
+ if (!standalonePath) return console.error(`standalone path not found. ${files}`);
+
+ const artifactName = `${ARTIFACT_BASE}.${ext}`;
+ const artifactPath = `${ARTIFACTS_DIR}/${artifactName}`;
+
+ await io.cp(standalonePath, artifactPath, { recursive: true });
+ await client.uploadArtifact(artifactName, [artifactPath], ARTIFACTS_DIR);
+};
+
+const run = async () => {
+ await io.mkdirP(ARTIFACTS_DIR);
+ const { updater, standalone } = OS_TARGETS[OS];
+
+ await uploadUpdater(updater);
+ for (const f of standalone) await uploadStandalone(f);
+};
+
+run();
diff --git a/.github/actions/publish-artifacts/package.json b/.github/actions/publish-artifacts/package.json
new file mode 100644
index 0000000..a02cff9
--- /dev/null
+++ b/.github/actions/publish-artifacts/package.json
@@ -0,0 +1,17 @@
+{
+ "private": true,
+ "scripts": {
+ "_build_comment": "there has to be a better way to do this lol",
+ "build": "ncc build index.ts --minify"
+ },
+ "dependencies": {
+ "@actions/artifact": "^1.1.2",
+ "@actions/core": "^1.10.1",
+ "@actions/github": "^6.0.0",
+ "@actions/glob": "^0.4.0",
+ "@actions/io": "^1.1.3"
+ },
+ "devDependencies": {
+ "@vercel/ncc": "^0.38.0"
+ }
+}
diff --git a/.github/actions/publish-artifacts/tsconfig.json b/.github/actions/publish-artifacts/tsconfig.json
new file mode 100644
index 0000000..8b4fecf
--- /dev/null
+++ b/.github/actions/publish-artifacts/tsconfig.json
@@ -0,0 +1,11 @@
+{
+ "compilerOptions": {
+ "target": "ES2015",
+ "module": "ESNext",
+ "moduleResolution": "Node",
+ "esModuleInterop": true,
+ "forceConsistentCasingInFileNames": true,
+ "strict": true,
+ "skipLibCheck": true
+ }
+}
diff --git a/.github/actions/setup-pnpm/action.yml b/.github/actions/setup-pnpm/action.yml
new file mode 100644
index 0000000..97f462e
--- /dev/null
+++ b/.github/actions/setup-pnpm/action.yml
@@ -0,0 +1,28 @@
+name: Setup Node.js, pnpm and dependencies
+description: Setup Node.js, pnpm and dependencies
+inputs:
+ token:
+ description: Github token
+ required: false
+ default: ''
+runs:
+ using: 'composite'
+ steps:
+ - name: Install pnpm
+ uses: pnpm/action-setup@v2
+ with:
+ version: 8.x.x
+
+ - name: Install Node.js
+ uses: actions/setup-node@v3
+ with:
+ token: ${{ inputs.token }}
+ check-latest: true
+ node-version-file: '.nvmrc'
+
+ - name: Install pnpm deps
+ shell: ${{ runner.os == 'Windows' && 'powershell' || 'bash' }}
+ env:
+ NODE_ENV: debug
+ GITHUB_TOKEN: ${{ inputs.token }}
+ run: pnpm i --frozen-lockfile
diff --git a/.github/actions/setup-rust/action.yaml b/.github/actions/setup-rust/action.yaml
new file mode 100644
index 0000000..8cf9997
--- /dev/null
+++ b/.github/actions/setup-rust/action.yaml
@@ -0,0 +1,52 @@
+name: Setup Rust
+description: Setup Rust
+inputs:
+ target:
+ description: toolchain target triple
+ required: false
+ save-cache:
+ description: Whether to save the Rust cache
+ required: false
+ default: 'false'
+runs:
+ using: 'composite'
+ steps:
+ - name: Install Rust
+ id: toolchain
+ uses: dtolnay/rust-toolchain@stable
+ with:
+ target: ${{ inputs.target }}
+ toolchain: stable
+ components: clippy, rustfmt
+
+ - name: Cache Rust Dependencies
+ uses: Swatinem/rust-cache@v2
+ with:
+ save-if: ${{ inputs.save-cache }}
+ prefix-key: 'v0-rust-deps'
+ shared-key: ${{ inputs.target }}
+
+ - name: Cargo config.toml
+ shell: bash
+ run: echo '{}' | npx -y mustache - .cargo/config.toml.mustache .cargo/config.toml
+
+ - name: Restore cached Prisma codegen
+ id: cache-prisma-restore
+ uses: actions/cache/restore@v3
+ with:
+ key: prisma-1-${{ runner.os }}-${{ hashFiles('./core/prisma/*', './Cargo.toml') }}
+ path: crates/prisma/src/**/*.rs
+
+ - name: Generate Prisma client
+ working-directory: core
+ if: ${{ steps.cache-prisma-restore.outputs.cache-hit != 'true' }}
+ shell: bash
+ run: cargo prisma generate
+
+ - name: Save Prisma codegen
+ id: cache-prisma-save
+ if: ${{ inputs.save-cache == 'true' }}
+ uses: actions/cache/save@v3
+ with:
+ key: ${{ steps.cache-prisma-restore.outputs.cache-primary-key }}
+ path: crates/prisma/src/**/*.rs
diff --git a/.github/actions/setup-system/action.yml b/.github/actions/setup-system/action.yml
new file mode 100644
index 0000000..3b33c82
--- /dev/null
+++ b/.github/actions/setup-system/action.yml
@@ -0,0 +1,36 @@
+name: Setup System and Rust
+description: Setup System and Rust
+inputs:
+ token:
+ description: Github token
+ required: false
+ default: ''
+ target:
+ description: toolchain target triple
+ required: false
+ setup-arg:
+ description: Argument for the system setup script
+ required: false
+ default: ''
+ save-cache:
+ description: Whether to save the System cache
+ required: false
+ default: 'false'
+runs:
+ using: 'composite'
+ steps:
+ - name: Setup Rust and Dependencies
+ uses: ./.github/actions/setup-rust
+ with:
+ target: ${{ inputs.target }}
+ save-cache: ${{ inputs.save-cache }}
+
+ - name: Run setup.sh script
+ shell: bash
+ if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
+ run: ./.github/scripts/setup.sh ${{ inputs.setup-arg }}
+
+ - name: Run setup.ps1 script
+ shell: powershell
+ if: ${{ runner.os == 'Windows' }}
+ run: ./.github/scripts/setup.ps1