Merge branch 'PrismLauncher:main' into fix/new-support-channels

This commit is contained in:
KTrain 2024-11-24 21:45:01 +10:00 committed by GitHub
commit e9a1182914
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 1285 additions and 712 deletions

View file

@ -1,66 +0,0 @@
name: Check
on:
push:
branches: ['main']
pull_request:
jobs:
rustfmt:
name: Run rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: rustfmt
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
- name: Run rustfmt
run: cargo fmt --all -- --check
clippy:
name: Run Clippy scan
runs-on: ubuntu-latest
permissions:
security-events: write
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: clippy
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
- name: Install SARIF tools
run: cargo install clippy-sarif sarif-fmt
- name: Fetch Cargo deps
run: cargo fetch --locked
- name: Run Clippy
continue-on-error: true
run: |
cargo clippy \
--all-features \
--all-targets \
--message-format=json \
| clippy-sarif | tee /tmp/clippy.sarif | sarif-fmt
- name: Upload results
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: /tmp/clippy.sarif
wait-for-processing: true

79
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,79 @@
name: CI
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
jobs:
build:
name: Build (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
use-nix: true
- os: windows-latest
use-nix: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust
if: ${{ !matrix.use-nix }}
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Install Nix
if: ${{ matrix.use-nix }}
uses: DeterminateSystems/nix-installer-action@v16
- name: Setup Nix cache
if: ${{ matrix.use-nix }}
uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Build
if: ${{ !matrix.use-nix }}
run: cargo build --locked
- name: Build
if: ${{ matrix.use-nix }}
run: nix build --print-build-logs .#refraction-debug
flake:
name: Flake checks
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v16
- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Run checks
run: |
nix flake check --print-build-logs --show-trace
# Make sure all above jobs finished successfully
release-gate:
name: CI Release gate
needs: [build, flake]
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- name: Exit with error
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
run: exit 1

47
.github/workflows/clippy.yml vendored Normal file
View file

@ -0,0 +1,47 @@
name: Clippy
on:
push:
branches: [main]
paths:
- 'Cargo.toml'
- 'Cargo.lock'
- '**.rs'
pull_request:
paths:
- 'Cargo.toml'
- 'Cargo.lock'
- '**.rs'
workflow_dispatch:
jobs:
clippy:
name: Run scan
runs-on: ubuntu-latest
permissions:
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v16
- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Generate sarif report
id: clippy-run
run: |
nix build --print-build-logs .#clippy-report
[ -L result ] || exit 1
echo "sarif-file=$(readlink -f result)" >> "$GITHUB_OUTPUT"
- name: Upload results
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.clippy-run.outputs.sarif-file }}
wait-for-processing: true

View file

@ -2,27 +2,30 @@ name: Docker
on: on:
push: push:
branches: ['main'] branches: [main]
pull_request: pull_request:
workflow_dispatch: workflow_dispatch:
jobs: jobs:
build: build:
name: Build image name: Build image
runs-on: ubuntu-latest
strategy: strategy:
fail-fast: false
matrix: matrix:
arch: [x86_64, aarch64] arch: [amd64, arm64]
runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - name: Checkout repository
uses: actions/checkout@v4
- name: Install Nix - name: Install Nix
uses: DeterminateSystems/nix-installer-action@v13 uses: DeterminateSystems/nix-installer-action@v16
- name: Setup Nix cache - name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v7 uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Build Docker image - name: Build Docker image
id: build id: build
@ -41,10 +44,26 @@ jobs:
if-no-files-found: error if-no-files-found: error
retention-days: 3 retention-days: 3
# Make sure all above jobs finished successfully
release-gate:
name: Docker Release gate
needs: [build]
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- name: Exit with error
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
run: exit 1
push: push:
name: Push image name: Push image
needs: build needs: build
if: ${{ github.event_name == 'push' }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
@ -54,16 +73,15 @@ jobs:
REGISTRY: ghcr.io REGISTRY: ghcr.io
USERNAME: ${{ github.actor }} USERNAME: ${{ github.actor }}
if: github.event_name == 'push'
steps: steps:
- uses: actions/checkout@v4 - name: Checkout repository
uses: actions/checkout@v4
- name: Determine image name - name: Determine image name
run: | run: |
echo "IMAGE_NAME=${REPOSITORY,,}" >> "$GITHUB_ENV" echo "IMAGE_NAME=${REPOSITORY,,}" >> "$GITHUB_ENV"
env: env:
REPOSITORY: '${{ github.repository }}' REPOSITORY: ${{ github.repository }}
- name: Download images - name: Download images
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
@ -83,15 +101,15 @@ jobs:
run: | run: |
set -eu set -eu
architectures=("x86_64" "aarch64") architectures=("amd64" "arm64")
for arch in "${architectures[@]}"; do for arch in "${architectures[@]}"; do
docker load < images/container-"$arch"/*.tar.gz docker load < images/container-"$arch"/*.tar.gz
docker tag refraction:latest-"$arch" "$TAG"-"$arch" docker tag refraction:latest-"$arch" "$TAG"-"$arch"
docker push ${{ env.TAG }}-"$arch" docker push "$TAG"-"$arch"
done done
docker manifest create "$TAG" \ docker manifest create "$TAG" \
--amend "$TAG"-x86_64 \ --amend "$TAG"-amd64 \
--amend "$TAG"-aarch64 --amend "$TAG"-arm64
docker manifest push "$TAG" docker manifest push "$TAG"

View file

@ -1,52 +0,0 @@
name: Nix
on:
push:
branches: ['main']
pull_request:
workflow_dispatch:
jobs:
build:
name: Build
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v13
- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v7
- name: Build refraction
run: nix build --fallback --print-build-logs
check:
name: Check flake
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v13
- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v7
- name: Run checks
run: |
nix flake check --print-build-logs --show-trace

View file

@ -15,21 +15,18 @@ jobs:
contents: write contents: write
pull-requests: write pull-requests: write
env:
PR_BRANCH: 'update-lockfiles'
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Install Nix - name: Install Nix
uses: DeterminateSystems/nix-installer-action@v13 uses: DeterminateSystems/nix-installer-action@v16
- name: Update flake.lock - name: Update flake.lock
id: update id: update
uses: DeterminateSystems/update-flake-lock@main uses: DeterminateSystems/update-flake-lock@v24
with: with:
pr-title: "nix: update flake.lock" pr-title: 'nix: update flake.lock'
- name: Enable Pull Request Automerge - name: Enable Pull Request Automerge
uses: peter-evans/enable-pull-request-automerge@v3 uses: peter-evans/enable-pull-request-automerge@v3

1069
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -22,8 +22,8 @@ env_logger = "0.11.3"
eyre = "0.6.12" eyre = "0.6.12"
log = "0.4.21" log = "0.4.21"
poise = "0.6.1" poise = "0.6.1"
octocrab = "0.39.0" octocrab = "0.42.0"
redis = { version = "0.26.0", features = ["tokio-comp", "tokio-rustls-comp"] } redis = { version = "0.27.0", features = ["tokio-comp", "tokio-rustls-comp"] }
regex = "1.10.4" regex = "1.10.4"
reqwest = { version = "0.12.4", default-features = false, features = [ reqwest = { version = "0.12.4", default-features = false, features = [
"rustls-tls", "rustls-tls",
@ -36,6 +36,7 @@ tokio = { version = "1.37.0", features = [
"rt-multi-thread", "rt-multi-thread",
"signal", "signal",
] } ] }
rustls = "0.23.13"
[lints.rust] [lints.rust]
unsafe_code = "forbid" unsafe_code = "forbid"

49
flake.lock generated
View file

@ -1,31 +1,16 @@
{ {
"nodes": { "nodes": {
"flake-checks": {
"locked": {
"lastModified": 1722203301,
"narHash": "sha256-AErsPk8ly2tkiJPieEjN8XuDSc5nJOWv8bv13jmNih0=",
"owner": "getchoo",
"repo": "flake-checks",
"rev": "af23d7bab32b5438ba5602f0ab42dd1d596ef9d7",
"type": "github"
},
"original": {
"owner": "getchoo",
"repo": "flake-checks",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1725036679, "lastModified": 1731245184,
"narHash": "sha256-Ri79ZOEcZJFLr6+LgS3A0WYyroL/PqEuO+lI7u+G2tE=", "narHash": "sha256-vmLS8+x+gHRv1yzj3n+GTAEObwmhxmkkukB2DwtJRdU=",
"owner": "nixos", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "dac9db29e0e7ff2071ccc47b720aaffc3e74b504", "rev": "aebe249544837ce42588aa4b2e7972222ba12e8f",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nixos", "owner": "NixOS",
"ref": "nixpkgs-unstable", "ref": "nixpkgs-unstable",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
@ -33,29 +18,7 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-checks": "flake-checks", "nixpkgs": "nixpkgs"
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1724984647,
"narHash": "sha256-BC6MUq0CTdmAu/cueVcdWTI+S95s0mJcn19SoEgd7gU=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "87b6cffc276795b46ef544d7ed8d7fed6ad9c8e4",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
} }
} }
}, },

221
flake.nix
View file

@ -1,108 +1,127 @@
{ {
description = "Discord bot for Prism Launcher"; description = "Discord bot for Prism Launcher";
inputs = { inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-checks.url = "github:getchoo/flake-checks"; outputs =
{
self,
nixpkgs,
}:
let
inherit (nixpkgs) lib;
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
rust-overlay = { forAllSystems = lib.genAttrs systems;
url = "github:oxalica/rust-overlay"; nixpkgsFor = nixpkgs.legacyPackages;
inputs.nixpkgs.follows = "nixpkgs"; in
{
checks = forAllSystems (
system:
let
pkgs = nixpkgsFor.${system};
mkCheck =
name: deps: script:
pkgs.runCommand name { nativeBuildInputs = deps; } ''
${script}
touch $out
'';
in
{
actionlint = mkCheck "check-actionlint" [ pkgs.actionlint ] "actionlint ${./.github/workflows}/*";
deadnix = mkCheck "check-deadnix" [ pkgs.deadnix ] "deadnix --fail ${self}";
statix = mkCheck "check-statix" [ pkgs.statix ] "statix check ${self}";
nixfmt = mkCheck "check-nixfmt" [ pkgs.nixfmt-rfc-style ] "nixfmt --check ${self}";
rustfmt = mkCheck "check-rustfmt" [
pkgs.cargo
pkgs.rustfmt
] "cd ${self} && cargo fmt -- --check";
}
);
devShells = forAllSystems (
system:
let
pkgs = nixpkgsFor.${system};
in
{
default = pkgs.mkShell {
packages = with pkgs; [
redis
# linters & formatters
actionlint
nodePackages.prettier
# rust tools
clippy
rustfmt
rust-analyzer
# nix tools
self.formatter.${system}
nil
statix
];
inputsFrom = [ self.packages.${pkgs.system}.refraction ];
RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
};
}
);
formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style);
nixosModules.default = import ./nix/module.nix self;
# For CI
legacyPackages = forAllSystems (
system:
let
pkgs = nixpkgsFor.${system};
in
{
clippy-report = pkgs.callPackage ./nix/clippy.nix { inherit (self.packages.${system}) refraction; };
refraction-debug = (self.packages.${system}.refraction.override { lto = false; }).overrideAttrs (
finalAttrs: _: {
cargoBuildType = "debug";
cargoCheckType = finalAttrs.cargoBuildType;
}
);
}
);
packages = forAllSystems (
system:
let
pkgs = nixpkgsFor.${system};
packages' = self.packages.${system};
refractionPackages = lib.makeScope pkgs.newScope (lib.flip self.overlays.default pkgs);
mkStatic = pkgs.callPackage ./nix/static.nix { };
containerize = pkgs.callPackage ./nix/containerize.nix { };
in
{
inherit (refractionPackages) refraction;
static-x86_64 = mkStatic { arch = "x86_64"; };
static-aarch64 = mkStatic { arch = "aarch64"; };
container-amd64 = containerize packages'.static-x86_64;
container-arm64 = containerize packages'.static-aarch64;
default = packages'.refraction;
}
);
overlays.default = final: _: {
refraction = final.callPackage ./nix/package.nix { };
};
}; };
};
outputs = {
self,
nixpkgs,
flake-checks,
rust-overlay,
}: let
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = fn: nixpkgs.lib.genAttrs systems (system: fn nixpkgs.legacyPackages.${system});
in {
checks = forAllSystems (pkgs: let
flake-checks' = flake-checks.lib.mkChecks {
inherit pkgs;
root = ./.;
};
in {
check-actionlint = flake-checks'.actionlint;
check-alejandra = flake-checks'.alejandra;
check-deadnix = flake-checks'.deadnix;
check-rustfmt = flake-checks'.rustfmt;
check-statix = flake-checks'.statix;
});
devShells = forAllSystems (pkgs: {
default = pkgs.mkShell {
packages = with pkgs; [
redis
# linters & formatters
actionlint
nodePackages.prettier
# rust tools
clippy
rustfmt
rust-analyzer
# nix tools
self.formatter.${system}
deadnix
nil
statix
];
inputsFrom = [self.packages.${pkgs.system}.refraction];
RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
};
});
formatter = forAllSystems (pkgs: pkgs.alejandra);
nixosModules.default = import ./nix/module.nix self;
packages = forAllSystems ({
lib,
pkgs,
system,
...
}: let
packages' = self.packages.${system};
mkStatic = pkgs.callPackage ./nix/static.nix {
inherit (self.packages.${pkgs.system}) refraction;
rust-overlay = rust-overlay.packages.${system};
};
mkContainerFor = refraction:
pkgs.dockerTools.buildLayeredImage {
name = "refraction";
tag = "latest-${refraction.stdenv.hostPlatform.qemuArch}";
config.Cmd = [(lib.getExe refraction)];
inherit (refraction) architecture;
};
in {
refraction = pkgs.callPackage ./nix/derivation.nix {inherit self;};
static-x86_64 = mkStatic {arch = "x86_64";};
static-aarch64 = mkStatic {arch = "aarch64";};
container-x86_64 = mkContainerFor packages'.static-x86_64;
container-aarch64 = mkContainerFor packages'.static-aarch64;
default = packages'.refraction;
});
overlays.default = _: prev: {
refraction = prev.callPackage ./nix/derivation.nix {inherit self;};
};
};
} }

39
nix/clippy.nix Normal file
View file

@ -0,0 +1,39 @@
{
cargo,
clippy,
clippy-sarif,
refraction,
rustPlatform,
sarif-fmt,
stdenv,
}:
stdenv.mkDerivation {
pname = "${refraction.pname}-sarif-report";
inherit (refraction)
version
src
cargoDeps
buildInputs
;
nativeBuildInputs = [
cargo
clippy
clippy-sarif
rustPlatform.cargoSetupHook
sarif-fmt
];
buildPhase = ''
cargo clippy \
--all-features \
--all-targets \
--tests \
--message-format=json \
| clippy-sarif | tee $out | sarif-fmt
'';
dontInstall = true;
dontFixup = true;
}

9
nix/containerize.nix Normal file
View file

@ -0,0 +1,9 @@
{ lib, dockerTools }:
refraction:
dockerTools.buildLayeredImage {
name = "refraction";
tag = "latest-${refraction.passthru.dockerArchitecture}";
config.Cmd = [ (lib.getExe refraction) ];
architecture = refraction.passthru.dockerArchitecture;
}

View file

@ -1,67 +0,0 @@
{
lib,
stdenv,
go,
rustPlatform,
darwin,
self,
lto ? true,
optimizeSize ? false,
}:
rustPlatform.buildRustPackage {
pname = "refraction";
version =
(lib.importTOML ../Cargo.toml).package.version
+ "-${self.shortRev or self.dirtyShortRev or "unknown-dirty"}";
__structuredAttrs = true;
src = lib.fileset.toSource {
root = ../.;
fileset = lib.fileset.unions [
../src
../build.rs
../Cargo.lock
../Cargo.toml
../tags
];
};
cargoLock = {
lockFile = ../Cargo.lock;
};
buildInputs = lib.optionals stdenv.hostPlatform.isDarwin (with darwin.apple_sdk.frameworks; [
CoreFoundation
Security
SystemConfiguration
]);
env = let
toRustFlags = lib.mapAttrs' (
name:
lib.nameValuePair
"CARGO_PROFILE_RELEASE_${lib.toUpper (builtins.replaceStrings ["-"] ["_"] name)}"
);
in
lib.optionalAttrs lto (toRustFlags {
lto = "thin";
})
// lib.optionalAttrs optimizeSize (toRustFlags {
codegen-units = "1";
opt-level = "s";
panic = "abort";
strip = "symbols";
});
# useful for container images
passthru.architecture = go.GOARCH;
meta = with lib; {
mainProgram = "refraction";
description = "Discord bot for Prism Launcher";
homepage = "https://github.com/PrismLauncher/refraction";
license = licenses.gpl3Plus;
maintainers = with maintainers; [getchoo Scrumplex];
};
}

View file

@ -1,17 +1,17 @@
self: { self:
{
config, config,
lib, lib,
pkgs, pkgs,
... ...
}: let }:
let
cfg = config.services.refraction; cfg = config.services.refraction;
defaultUser = "refraction"; defaultUser = "refraction";
inherit inherit (lib)
(lib)
getExe getExe
literalExpression literalExpression
mdDoc
mkEnableOption mkEnableOption
mkIf mkIf
mkOption mkOption
@ -19,13 +19,14 @@ self: {
optionals optionals
types types
; ;
in { in
{
options.services.refraction = { options.services.refraction = {
enable = mkEnableOption "refraction"; enable = mkEnableOption "refraction";
package = mkPackageOption self.packages.${pkgs.stdenv.hostPlatform.system} "refraction" {}; package = mkPackageOption self.packages.${pkgs.stdenv.hostPlatform.system} "refraction" { };
user = mkOption { user = mkOption {
description = mdDoc '' description = ''
User under which the service should run. If this is the default value, User under which the service should run. If this is the default value,
the user will be created, with the specified group as the primary the user will be created, with the specified group as the primary
group. group.
@ -38,7 +39,7 @@ in {
}; };
group = mkOption { group = mkOption {
description = mdDoc '' description = ''
Group under which the service should run. If this is the default value, Group under which the service should run. If this is the default value,
the group will be created. the group will be created.
''; '';
@ -50,7 +51,7 @@ in {
}; };
redisUrl = mkOption { redisUrl = mkOption {
description = mdDoc '' description = ''
Connection to a redis server. If this needs to include credentials Connection to a redis server. If this needs to include credentials
that shouldn't be world-readable in the Nix store, set environmentFile that shouldn't be world-readable in the Nix store, set environmentFile
and override the `REDIS_URL` entry. and override the `REDIS_URL` entry.
@ -64,7 +65,7 @@ in {
}; };
environmentFile = mkOption { environmentFile = mkOption {
description = mdDoc '' description = ''
Environment file as defined in {manpage}`systemd.exec(5)` Environment file as defined in {manpage}`systemd.exec(5)`
''; '';
type = types.nullOr types.path; type = types.nullOr types.path;
@ -84,10 +85,8 @@ in {
systemd.services."refraction" = { systemd.services."refraction" = {
enable = true; enable = true;
wantedBy = ["multi-user.target"]; wantedBy = [ "multi-user.target" ];
after = after = [ "network.target" ] ++ optionals (cfg.redisUrl == "local") [ "redis-refraction.service" ];
["network.target"]
++ optionals (cfg.redisUrl == "local") ["redis-refraction.service"];
script = '' script = ''
${getExe cfg.package} ${getExe cfg.package}
@ -95,9 +94,10 @@ in {
environment = { environment = {
BOT_REDIS_URL = BOT_REDIS_URL =
if cfg.redisUrl == "local" if cfg.redisUrl == "local" then
then "unix:${config.services.redis.servers.refraction.unixSocket}" "unix:${config.services.redis.servers.refraction.unixSocket}"
else cfg.redisUrl; else
cfg.redisUrl;
}; };
serviceConfig = { serviceConfig = {
@ -141,9 +141,7 @@ in {
}; };
}; };
groups = mkIf (cfg.group == defaultUser) { groups = mkIf (cfg.group == defaultUser) { ${defaultUser} = { }; };
${defaultUser} = {};
};
}; };
}; };
} }

68
nix/package.nix Normal file
View file

@ -0,0 +1,68 @@
{
lib,
stdenv,
go,
rustPlatform,
lto ? !optimizeSize,
optimizeSize ? false,
}:
let
fs = lib.fileset;
toRustFlags = flags: toString (lib.mapAttrsToList (name: value: "-C ${name}=${value}") flags);
in
assert lib.assertMsg (lto -> !optimizeSize) "`lto` and `optimizeSize` are mutually exclusive";
rustPlatform.buildRustPackage rec {
pname = "refraction";
inherit (passthru.cargoToml.package) version;
src = fs.toSource {
root = ../.;
fileset = fs.intersection (fs.gitTracked ../.) (
fs.unions [
../src
../build.rs
../Cargo.lock
../Cargo.toml
../tags
]
);
};
cargoLock.lockFile = ../Cargo.lock;
# `panic=abort` breaks tests womp womp
doCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform && !optimizeSize;
env = {
RUSTFLAGS = toRustFlags (
lib.optionalAttrs lto {
lto = "thin";
embed-bitcode = "yes";
}
// lib.optionalAttrs optimizeSize {
codegen-units = "1";
opt-level = "s";
panic = "abort";
strip = "symbols";
}
);
};
passthru = {
cargoToml = lib.importTOML ../Cargo.toml;
# For container images
dockerArchitecture = go.GOARCH;
};
meta = {
description = "Discord bot for Prism Launcher";
homepage = "https://github.com/PrismLauncher/refraction";
license = lib.licenses.gpl3Plus;
maintainers = with lib.maintainers; [
getchoo
Scrumplex
];
mainProgram = "refraction";
};
}

View file

@ -1,27 +1,9 @@
{ { pkgsCross }:
lib, let
refraction, crossPlatformFor = with pkgsCross; {
rust-overlay,
pkgsCross,
}: {arch}: let
targets = with pkgsCross; {
x86_64 = musl64.pkgsStatic; x86_64 = musl64.pkgsStatic;
aarch64 = aarch64-multiplatform.pkgsStatic; aarch64 = aarch64-multiplatform.pkgsStatic;
}; };
getRustcTarget = pkgs: pkgs.stdenv.hostPlatform.rust.rustcTarget;
toolchain = rust-overlay.rust.minimal.override {
extensions = ["rust-std"];
targets = lib.mapAttrsToList (lib.const getRustcTarget) targets;
};
mkRustPlatformWith = pkgs:
pkgs.makeRustPlatform (
lib.genAttrs ["cargo" "rustc"] (lib.const toolchain)
);
rustPlatforms = lib.mapAttrs (lib.const mkRustPlatformWith) targets;
in in
refraction.override { { arch }:
rustPlatform = rustPlatforms.${arch}; crossPlatformFor.${arch}.callPackage ./package.nix { optimizeSize = true; }
optimizeSize = true;
}

View file

@ -1,4 +1,7 @@
{ {
"$schema": "https://docs.renovatebot.com/renovate-schema.json", "$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:base", "config:recommended", ":automergeMinor"] "extends": ["config:base", "config:recommended", ":automergeMinor"],
"lockFileMaintenance": {
"enabled": true
}
} }

View file

@ -32,6 +32,7 @@ pub async fn find(log: &str, data: &Data) -> Result<Vec<(String, String)>> {
java_32_bit, java_32_bit,
intermediary_mappings, intermediary_mappings,
old_forge_new_java, old_forge_new_java,
checksum_mismatch,
]; ];
let mut res: Vec<(String, String)> = issues.iter().filter_map(|issue| issue(log)).collect(); let mut res: Vec<(String, String)> = issues.iter().filter_map(|issue| issue(log)).collect();
@ -123,9 +124,9 @@ fn java_option(log: &str) -> Issue {
if let Some(captures) = vm_option.captures(log) { if let Some(captures) = vm_option.captures(log) {
let title = if &captures[1] == "UseShenandoahGC" { let title = if &captures[1] == "UseShenandoahGC" {
"Wrong Java Arguments"
} else {
"Java 8 and below don't support ShenandoahGC" "Java 8 and below don't support ShenandoahGC"
} else {
"Wrong Java Arguments"
}; };
return Some(( return Some((
title.to_string(), title.to_string(),
@ -370,7 +371,8 @@ fn java_32_bit(log: &str) -> Issue {
); );
let found = log.contains("Could not reserve enough space for ") let found = log.contains("Could not reserve enough space for ")
|| log.contains("Invalid maximum heap size: "); || log.contains("Invalid maximum heap size: ")
|| log.contains("Invalid initial heap size: ");
found.then_some(issue) found.then_some(issue)
} }
@ -399,3 +401,15 @@ fn old_forge_new_java(log: &str) -> Issue {
); );
found.then_some(issue) found.then_some(issue)
} }
fn checksum_mismatch(log: &str) -> Issue {
let issue = (
"Outdated cached files".to_string(),
"It looks like you need to delete cached files.
To do that, press Folders View Launcher Root Folder, and **after closing the launcher** delete the folder named \"meta\"."
.to_string(),
);
let found = log.contains("Checksum mismatch, download is bad.");
found.then_some(issue)
}

View file

@ -41,6 +41,8 @@ pub async fn handle(ctx: &Context, message: &Message, data: &Data) -> Result<()>
return Ok(()); return Ok(());
}; };
let log = log.replace("\r\n", "\n");
let issues = issues::find(&log, data).await?; let issues = issues::find(&log, data).await?;
let embed = { let embed = {

View file

@ -42,7 +42,7 @@ pub async fn handle(
// ignore new messages from bots // ignore new messages from bots
// note: the webhook_id check allows us to still respond to PK users // note: the webhook_id check allows us to still respond to PK users
if (new_message.author.bot && new_message.webhook_id.is_none()) if (new_message.author.bot && new_message.webhook_id.is_none())
|| new_message.is_own(ctx) || (new_message.author == **ctx.cache.current_user())
{ {
trace!("Ignoring message {} from bot", new_message.id); trace!("Ignoring message {} from bot", new_message.id);
return Ok(()); return Ok(());

View file

@ -58,7 +58,7 @@ async fn setup(
trace!("Redis connection looks good!"); trace!("Redis connection looks good!");
} }
let http_client = api::HttpClient::default(); let http_client = <api::HttpClient as api::HttpClientExt>::default();
let octocrab = octocrab::instance(); let octocrab = octocrab::instance();
let data = Data { let data = Data {
@ -85,6 +85,9 @@ async fn main() -> eyre::Result<()> {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
color_eyre::install()?; color_eyre::install()?;
env_logger::init(); env_logger::init();
rustls::crypto::aws_lc_rs::default_provider()
.install_default()
.expect("Couldn't initialize crypto provider");
let token = let token =
std::env::var("DISCORD_BOT_TOKEN").wrap_err("Couldn't find bot token in environment!")?; std::env::var("DISCORD_BOT_TOKEN").wrap_err("Couldn't find bot token in environment!")?;

View file

@ -35,7 +35,7 @@ impl Storage {
let mut con = self.client.get_multiplexed_async_connection().await?; let mut con = self.client.get_multiplexed_async_connection().await?;
// Just store some value. We only care about the presence of this key // Just store some value. We only care about the presence of this key
con.set_ex(key, 0, 7 * 24 * 60 * 60).await?; // 1 week () = con.set_ex(key, 0, 7 * 24 * 60 * 60).await?; // 1 week
Ok(()) Ok(())
} }
@ -54,7 +54,8 @@ impl Storage {
debug!("Caching launcher version as {version}"); debug!("Caching launcher version as {version}");
let mut con = self.client.get_multiplexed_async_connection().await?; let mut con = self.client.get_multiplexed_async_connection().await?;
con.set_ex(LAUNCHER_VERSION_KEY, version, 24 * 60 * 60) () = con
.set_ex(LAUNCHER_VERSION_KEY, version, 24 * 60 * 60)
.await?; // 1 day .await?; // 1 day
Ok(()) Ok(())
@ -73,7 +74,8 @@ impl Storage {
debug!("Caching stargazer count as {stargazers}"); debug!("Caching stargazer count as {stargazers}");
let mut con = self.client.get_multiplexed_async_connection().await?; let mut con = self.client.get_multiplexed_async_connection().await?;
con.set_ex(LAUNCHER_STARGAZER_KEY, stargazers, 60 * 60) () = con
.set_ex(LAUNCHER_STARGAZER_KEY, stargazers, 60 * 60)
.await?; .await?;
Ok(()) Ok(())

View file

@ -1,10 +0,0 @@
---
title: Prism Launcher is always offline?
color: orange
---
If you recently updated Prism Launcher on Windows and you are now unable to do anything in Prism Launcher that would require an internet connection (i.e. logging in, downloading mods/modpacks and more), try uninstalling the launcher and then reinstalling it again.
If you are using a portable installation, it should be sufficient to delete the `tls` folder and then extract the zip again.
See [this GitHub issue](https://github.com/PrismLauncher/PrismLauncher/issues/660) for more information.

View file

@ -3,4 +3,4 @@ title: Java Instructions
color: orange color: orange
--- ---
Currently, Prism Launcher does not bundle Java with itself. The instructions to setup and install Java can be found [here](https://prismlauncher.org/wiki/getting-started/installing-java/). As of 9.0, Prism Launcher will automatically download and configure Java for the version of Minecraft you are using. The instructions to manually setup and install Java can be found [here](https://prismlauncher.org/wiki/getting-started/installing-java/).

View file

@ -1,10 +0,0 @@
---
title: Forge Bugfix
color: yellow
image: https://media.discordapp.net/attachments/1040383700845740072/1057840239751729172/Fix.png
---
1. Click the instance that is broken, then select `Edit`.
2. Choose `Version` and then click `Forge`, then click the change version button.
3. You can then change the version, choose the latest, and click OK.
4. You are good to go! <a:minecraftpartyparrotr:1032312401577652274>

10
tags/login_fix.md Normal file
View file

@ -0,0 +1,10 @@
---
title: Microsoft login
color: orange
---
If you have trouble with Microsoft login make sure:
* The age stated in your account is over 21.
* Microsoft auth servers are not experiencing downtime.
For more possible solutions check this GitHub issue [#2302](https://github.com/PrismLauncher/PrismLauncher/issues/2302).

View file

@ -0,0 +1,7 @@
---
title: Minecraft Launcher Comparison
color: green
---
Here is a comparison of the features of various launchers, including Prism Launcher:
https://mc-launcher.tayou.org/

20
tags/prism_logs.md Normal file
View file

@ -0,0 +1,20 @@
---
title: Upload Logs
color: orange
fields:
- name: Portable (Windows / Linux)
value: '`./logs/PrismLauncher-0.log` In the PrismLauncher folder'
- name: Windows
value: '`%APPDATA%/PrismLauncher/logs/PrismLauncher-0.log`'
- name: Scoop
value: '`%HOMEPATH%\scoop\persist\prismlauncher\logs\PrismLauncher-0.log`'
- name: macOS
value: '`~/Library/Application Support/PrismLauncher/logs/PrismLauncher-0.log`'
- name: Linux
value: '`~/.local/share/PrismLauncher/logs/PrismLauncher-0.log`'
- name: Flatpak
value: '`~/.var/app/org.prismlauncher.PrismLauncher/data/PrismLauncher/logs/PrismLauncher-0.log`'
---
Please send logs! The recommended site to upload your logs to is [mclo.gs](https://mclo.gs/).