From 08bd1edbe1b050405de0a092d061bd3a9368d04f Mon Sep 17 00:00:00 2001
From: Nick
Date: Mon, 17 Jun 2024 21:35:58 -0400
Subject: [PATCH] 378 - Implement dates instead of xxx days
---
.github/workflows/core-build-and-draft.yml | 6 +++
.github/workflows/core-release-docker.yml | 31 +++++++++---
.../workflows/dashboard-build-and-draft.yml | 2 -
.../workflows/dashboard-release-docker.yml | 30 +++++++-----
Cargo.lock | 4 +-
Cargo.toml | 2 +-
README.md | 4 +-
core/src/command_console/mod.rs | 8 +++-
dashboard/package-lock.json | 4 +-
dashboard/package.json | 2 +-
dashboard/src-tauri/tauri.conf.json | 2 +-
.../src/components/FileViewer/FileList.tsx | 4 +-
dashboard/src/utils/util.ts | 3 +-
example-macros/README.md | 7 +++
example-macros/auto-backup/index.ts | 48 +++++++++++++++++++
15 files changed, 122 insertions(+), 35 deletions(-)
create mode 100644 example-macros/README.md
create mode 100644 example-macros/auto-backup/index.ts
diff --git a/.github/workflows/core-build-and-draft.yml b/.github/workflows/core-build-and-draft.yml
index 34bab6b9..c55fb0ea 100644
--- a/.github/workflows/core-build-and-draft.yml
+++ b/.github/workflows/core-build-and-draft.yml
@@ -35,6 +35,12 @@ jobs:
arch: "x86_64"
postfix: ""
cross: false
+ - platform: "self-hosted"
+ target: "aarch64-unknown-linux-gnu"
+ os: "linux"
+ arch: "aarch64"
+ postfix: ""
+ cross: false
runs-on: ${{ matrix.platform }}
steps:
diff --git a/.github/workflows/core-release-docker.yml b/.github/workflows/core-release-docker.yml
index 1e240d93..f9faffe7 100644
--- a/.github/workflows/core-release-docker.yml
+++ b/.github/workflows/core-release-docker.yml
@@ -1,14 +1,29 @@
name: Core - Release Docker
+
on:
release:
types: [published]
workflow_dispatch:
+ inputs:
+ version:
+ description: "Release tag to download binaries from, must be an existing release"
+ required: true
+ type: string
+ stable:
+ description: "Is this a stable release?"
+ required: true
+ type: boolean
+
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}_core
+permissions:
+ contents: read
+ packages: write
+
jobs:
core-release-docker:
runs-on: ubuntu-latest
@@ -39,10 +54,14 @@ jobs:
uses: dsaltares/fetch-gh-release-asset@master
with:
regex: true
- file: "lodestone_core_*"
- target: release/
- version: "tags/${{ github.event.release.tag_name }}"
+ file: "lodestone_core_.*"
+ target: core/release/
+ version: "tags/${{ inputs.version || github.ref_name }}"
token: ${{ secrets.GITHUB_TOKEN }}
+
+ - id: tree
+ name: List files
+ run: tree .
# https://stackoverflow.com/questions/73402042/github-action-expressions-split-string
- name: set version string
@@ -53,16 +72,16 @@ jobs:
- name: set docker version label
env:
- LABEL: ${{ !github.event.release.prerelease && 'latest-stable' || 'latest-beta' }}
+ LABEL: ${{ (inputs.stable || !github.event.release.prerelease) && 'latest-stable' || 'latest-beta' }}
id: release_type
run: echo "label=${LABEL}" >> $GITHUB_OUTPUT
- name: build and push
uses: docker/build-push-action@v3
with:
- context: .
+ context: ./core
platforms: linux/amd64,linux/arm64
- file: ./githubactions.Dockerfile
+ file: ./core/githubactions.Dockerfile
build-args: |
lodestone_version=${{ steps.release_asset.outputs.version }}
push: true
diff --git a/.github/workflows/dashboard-build-and-draft.yml b/.github/workflows/dashboard-build-and-draft.yml
index 415e9111..6d679e65 100644
--- a/.github/workflows/dashboard-build-and-draft.yml
+++ b/.github/workflows/dashboard-build-and-draft.yml
@@ -34,8 +34,6 @@ jobs:
target: "x86_64-pc-windows-msvc"
- platform: "ubuntu-latest"
target: "x86_64-unknown-linux-gnu"
- - platform: "macos-latest"
- target: "x86_64-apple-darwin"
runs-on: ${{ matrix.platform }}
diff --git a/.github/workflows/dashboard-release-docker.yml b/.github/workflows/dashboard-release-docker.yml
index eb8a567a..ae80e722 100644
--- a/.github/workflows/dashboard-release-docker.yml
+++ b/.github/workflows/dashboard-release-docker.yml
@@ -4,11 +4,24 @@ on:
release:
types: [published]
workflow_dispatch:
+ inputs:
+ version:
+ description: "Release tag to download binaries from, must be an existing release"
+ required: true
+ type: string
+ stable:
+ description: "Is this a stable release?"
+ required: true
+ type: boolean
env:
REGISTRY: ghcr.io
IMAGE_NAME: "${{ github.repository }}_dashboard"
+permissions:
+ contents: read
+ packages: write
+
jobs:
dashboard-release-docker:
runs-on: ubuntu-latest
@@ -34,29 +47,20 @@ jobs:
with:
string: ${{ env.REGISTRY}}/${{ env.IMAGE_NAME }}
- # https://stackoverflow.com/questions/73402042/github-action-expressions-split-string
- - name: set version string
- env:
- VERSION: ${{ steps.release_asset.outputs.version }}
- id: substring
- run: echo "version=${VERSION:1}" >> $GITHUB_OUTPUT
-
- name: set docker version label
env:
- LABEL: ${{ !github.event.release.prerelease && 'latest-stable' || 'latest-beta' }}
+ LABEL: ${{ (inputs.stable || !github.event.release.prerelease) && 'latest-stable' || 'latest-beta' }}
id: release_type
run: echo "label=${LABEL}" >> $GITHUB_OUTPUT
- name: build and push
uses: docker/build-push-action@v3
with:
- context: .
+ context: ./dashboard
platforms: linux/amd64,linux/arm64
- file: ./Dockerfile
- build-args: |
- lodestone_version=${{ steps.release_asset.outputs.version }}
+ file: ./dashboard/Dockerfile
push: true
tags: |
${{ steps.string_tag.outputs.lowercase }}:latest
${{ steps.string_tag.outputs.lowercase }}:${{ steps.release_type.outputs.label }}
- ${{ steps.string_tag.outputs.lowercase }}:${{ steps.substring.outputs.version }}
+ ${{ steps.string_tag.outputs.lowercase }}:${{ inputs.version || github.event.release.tag_name }}
diff --git a/Cargo.lock b/Cargo.lock
index 8ad137df..c597bbbd 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4232,7 +4232,7 @@ dependencies = [
[[package]]
name = "lodestone-client"
-version = "0.5.0"
+version = "0.5.1"
dependencies = [
"lodestone_core",
"notify-rust",
@@ -4248,7 +4248,7 @@ dependencies = [
[[package]]
name = "lodestone_core"
-version = "0.5.0"
+version = "0.5.1"
dependencies = [
"ansi_term",
"argon2",
diff --git a/Cargo.toml b/Cargo.toml
index 9259e95e..6e3fb092 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,7 +15,7 @@ lto = "thin"
codegen-units = 1
[workspace.package]
-version = "0.5.0"
+version = "0.5.1"
homepage = "https://github.com/Lodestone-Team"
readme = "README.md"
edition = "2021"
diff --git a/README.md b/README.md
index 4964c429..2dfe9d75 100644
--- a/README.md
+++ b/README.md
@@ -33,10 +33,10 @@ Have a feature request? Let us know by creating an issue!
## Supported Platforms and Architectures
- Windows (x86_64)
-- Linux (x86_64)
+- Linux (x86_64 and ARM)
- MacOS (Apple Silicon)
-We have discontinued support for Intel Macs and ARM Linux as of 0.5.0 due to the lack of hardware to test on. Get in contact with us if you would like to see support for these platforms.
+We are deprecating support for Intel Macs due to the lack of hardware to test on. Get in contact with us if you would like to see additional platform supports.
## Lodestone CLI vs Lodestone Desktop
diff --git a/core/src/command_console/mod.rs b/core/src/command_console/mod.rs
index 2fa7067e..12a49fd0 100644
--- a/core/src/command_console/mod.rs
+++ b/core/src/command_console/mod.rs
@@ -38,7 +38,11 @@ pub fn init(app_state: AppState) {
loop {
let app_state = app_state.clone();
let mut input = String::new();
- std::io::stdin().read_line(&mut input).unwrap();
+ let buf_size = std::io::stdin().read_line(&mut input).unwrap();
+ if buf_size == 0 {
+ println!("EOF");
+ break;
+ }
let input_tokens = input.split_whitespace().collect::>();
match input_tokens.first() {
Some(&"di") => {
@@ -46,7 +50,7 @@ pub fn init(app_state: AppState) {
handle_docker_command(&input_tokens[1..], app_state).await;
}
_ => {
- println!("Unknown command");
+ println!("Unknown command: {}", input);
continue;
}
}
diff --git a/dashboard/package-lock.json b/dashboard/package-lock.json
index dbd22c2e..492eefaa 100644
--- a/dashboard/package-lock.json
+++ b/dashboard/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "lodestone",
- "version": "0.5.0",
+ "version": "0.5.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "lodestone",
- "version": "0.5.0",
+ "version": "0.5.1",
"hasInstallScript": true,
"dependencies": {
"@fortawesome/fontawesome-free": "^6.1.2",
diff --git a/dashboard/package.json b/dashboard/package.json
index af2941d6..79a282f0 100644
--- a/dashboard/package.json
+++ b/dashboard/package.json
@@ -1,6 +1,6 @@
{
"name": "lodestone",
- "version": "0.5.0",
+ "version": "0.5.1",
"private": true,
"scripts": {
"dev": "next dev -p 3001",
diff --git a/dashboard/src-tauri/tauri.conf.json b/dashboard/src-tauri/tauri.conf.json
index 6074b055..d99c57e5 100644
--- a/dashboard/src-tauri/tauri.conf.json
+++ b/dashboard/src-tauri/tauri.conf.json
@@ -9,7 +9,7 @@
},
"package": {
"productName": "Lodestone",
- "version": "0.5.0"
+ "version": "0.5.1"
},
"tauri": {
"allowlist": {
diff --git a/dashboard/src/components/FileViewer/FileList.tsx b/dashboard/src/components/FileViewer/FileList.tsx
index cfe63ba3..07e818cc 100644
--- a/dashboard/src/components/FileViewer/FileList.tsx
+++ b/dashboard/src/components/FileViewer/FileList.tsx
@@ -351,7 +351,7 @@ export default function FileList({
-
+
{file.modification_time || file.creation_time
? formatTimeAgo(
Number(file.modification_time ?? file.creation_time) * 1000
@@ -359,7 +359,7 @@ export default function FileList({
: 'Unknown Creation Time'}
-
+
{file.file_type === 'Directory'
? ''
: file.size
diff --git a/dashboard/src/utils/util.ts b/dashboard/src/utils/util.ts
index c13ba71c..8a91faab 100644
--- a/dashboard/src/utils/util.ts
+++ b/dashboard/src/utils/util.ts
@@ -312,7 +312,8 @@ export const formatTimeAgo = (time_ms: number) => {
const diffMinutes = Math.floor(diff / (1000 * 60));
const diffSeconds = Math.floor(diff / 1000);
if (diffDays > 0) {
- return `${diffDays} day${diffDays > 1 ? 's' : ''} ago`;
+ const date = new Date(time_ms);
+ return `${date.toLocaleString('default', { month: 'long', year: 'numeric', day: 'numeric' })}`;
} else if (diffHours > 0) {
return `${diffHours} hour${diffHours > 1 ? 's' : ''} ago`;
} else if (diffMinutes > 0) {
diff --git a/example-macros/README.md b/example-macros/README.md
new file mode 100644
index 00000000..09102a61
--- /dev/null
+++ b/example-macros/README.md
@@ -0,0 +1,7 @@
+This folder contains example macros that can be used as a starting point for creating your own macros.
+
+Note: make sure your macro is in the correct format. The macro should be a folder with the `index.ts` or `index.js` file at the root of the folder as the entry point.
+
+PRs are welcome! If you have a macro you'd like to share, feel free to create a PR to add it to this folder.
+
+Read more about creating macros [here](https://github.com/Lodestone-Team/lodestone/wiki/Intro-to-Macro-and-Task)
\ No newline at end of file
diff --git a/example-macros/auto-backup/index.ts b/example-macros/auto-backup/index.ts
new file mode 100644
index 00000000..3d3e4c9f
--- /dev/null
+++ b/example-macros/auto-backup/index.ts
@@ -0,0 +1,48 @@
+import { format } from "https://deno.land/std@0.177.1/datetime/format.ts";
+import { copy } from "https://deno.land/std@0.191.0/fs/copy.ts";
+import { sleep } from "https://deno.land/x/sleep@v1.2.1/mod.ts";
+import { EventStream } from "https://raw.githubusercontent.com/Lodestone-Team/lodestone-macro-lib/main/events.ts";
+import { lodestoneVersion } from "https://raw.githubusercontent.com/Lodestone-Team/lodestone-macro-lib/main/prelude.ts";
+import { MinecraftJavaInstance } from "https://raw.githubusercontent.com/Lodestone-Team/lodestone-macro-lib/main/instance.ts";
+
+const currentInstance = await MinecraftJavaInstance.current();
+
+const eventStream = new EventStream(
+ currentInstance.getUUID(),
+ await currentInstance.name()
+);
+
+// Lodestone will parse the configuration class and inject the configuration into the macro
+class LodestoneConfig {
+ // Where to store the backups relative to the instance path
+ backupFolderRelative: string = "backups";
+ // How long to wait between backups in seconds
+ delaySec: number = 3600;
+}
+
+// not technically necessary, but it's a good practice to appease the linter
+declare const config: LodestoneConfig;
+
+// make sure the config is injected properly
+console.log(config);
+
+const instancePath = await currentInstance.path();
+const backupFolder = `${instancePath}/${config.backupFolderRelative}`;
+EventStream.emitDetach();
+while (true) {
+ eventStream.emitConsoleOut("[Backup Macro] Backing up world...");
+ if ((await currentInstance.state()) == "Stopped") {
+ eventStream.emitConsoleOut("[Backup Macro] Instance stopped, exiting...");
+ break;
+ }
+
+ const now = new Date();
+ const now_str = format(now, "yy-MM-dd_HH");
+ try {
+ await copy(`${instancePath}/world`, `${backupFolder}/backup_${now_str}`);
+ } catch (e) {
+ console.log(e);
+ }
+
+ await sleep(config.delaySec);
+}