Skip to content

Commit

Permalink
refactor(trunk): refactor the entire project idk
Browse files Browse the repository at this point in the history
  • Loading branch information
pauliesnug committed Oct 15, 2023
1 parent 06f51cc commit 2582162
Show file tree
Hide file tree
Showing 69 changed files with 4,568 additions and 14,603 deletions.
23 changes: 23 additions & 0 deletions .cargo/config.toml.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{#isMacOS}}
[target.x86_64-apple-darwin]
rustflags = ["-L", "{{{nativeDeps}}}/lib"]

[target.aarch64-apple-darwin]
rustflags = ["-L", "{{{nativeDeps}}}/lib"]
{{/isMacOS}}

{{#isWin}}
[target.x86_64-pc-windows-msvc]
rustflags = ["-L", "{{{nativeDeps}}}\\lib"]
{{/isWin}}

{{#isLinux}}
[target.x86_64-unknown-linux-gnu]
rustflags = ["-L", "{{{nativeDeps}}}/lib", "-C", "link-arg=-Wl,-rpath=${ORIGIN}/../lib/nexus"]

[target.aarch64-unknown-linux-gnu]
rustflags = ["-L", "{{{nativeDeps}}}/lib", "-C", "link-arg=-Wl,-rpath=${ORIGIN}/../lib/nexus"]
{{/isLinux}}

[alias]
prisma = "run -p prisma-cli --bin prisma --"
3 changes: 3 additions & 0 deletions .cargo/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# (i): note

make sure to execute the `::setup` script after any modifications to `cargo.toml`.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ trim_trailing_whitespace = true
# https://prettier.io
[*.{cjs,js,json,jsx,mjs,ts,tsx}]
indent_size = 4
tab_width = 4
indent_style = tab

# Kotlin
# https://android.github.io/kotlin-guides/style.html#indentation
Expand Down
61 changes: 61 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: 🐞 Bug Report
description: Report a bug
labels:
- kind/bug
- status/needs-triage

body:
- type: checkboxes
id: product
attributes:
label: Product name
description: What Polyfrost product are you using?
options:
- label: Website
- label: Launcher
- label: Installer

- type: markdown
attributes:
value: |
## First of all
1. Please search for [existing issues](https://github.com/polyfrost/nexus/issues?q=is%3Aissue) about this problem first.
2. Make sure it's an issue with our products and not something else you are using.
3. Remember to follow our community guidelines and be friendly.
- type: textarea
id: description
attributes:
label: Describe the bug
description: A clear description of what the bug is. Include screenshots if applicable.
placeholder: Bug description
validations:
required: true

- type: textarea
id: reproduction
attributes:
label: Reproduction
description: Steps to reproduce the behavior.
placeholder: |
1. Go to ...
2. Click on ...
3. See error
- type: textarea
id: expected-behavior
attributes:
label: Expected behavior
description: A clear description of what you expected to happen.

- type: textarea
id: logs
attributes:
label: Stack trace (optional)
render: Shell

- type: textarea
id: context
attributes:
label: Additional context
description: Add any other context about the problem here.
13 changes: 13 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# tell yaml plugin that this is the config file and not a template of its own:
# yaml-language-server: $schema=https://json.schemastore.org/github-issue-config.json
blank_issues_enabled: false
contact_links:
- name: 🙏 Get Help
url: https://github.com/polyfrost/nexus/discussions/new?category=help
about: If you can't get something to work the way you expect, open a question in our discussion forums.
- name: 💡 Feature Request
url: https://github.com/polyfrost/nexus/discussions/new?category=ideas
about: Suggest any ideas you have using our discussion forums.
- name: 💬 Discord Chat
url: https://polyfrost.cc/discord
about: Ask questions and talk to other Polyfrost product users and the devs.
2 changes: 2 additions & 0 deletions .github/actions/publish-artifacts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# pls tell me there is a better way
!dist
14 changes: 14 additions & 0 deletions .github/actions/publish-artifacts/action.yaml
Original file line number Diff line number Diff line change
@@ -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
101 changes: 101 additions & 0 deletions .github/actions/publish-artifacts/index.ts
Original file line number Diff line number Diff line change
@@ -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();
17 changes: 17 additions & 0 deletions .github/actions/publish-artifacts/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
11 changes: 11 additions & 0 deletions .github/actions/publish-artifacts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "ES2015",
"module": "ESNext",
"moduleResolution": "Node",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
28 changes: 28 additions & 0 deletions .github/actions/setup-pnpm/action.yml
Original file line number Diff line number Diff line change
@@ -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
52 changes: 52 additions & 0 deletions .github/actions/setup-rust/action.yaml
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions .github/actions/setup-system/action.yml
Original file line number Diff line number Diff line change
@@ -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
Empty file added .github/scripts/setup.ps1
Empty file.
Empty file added .github/scripts/setup.sh
Empty file.
Loading

0 comments on commit 2582162

Please sign in to comment.