Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

378 - Implement dates instead of xxx days #402

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/core-build-and-draft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
31 changes: 25 additions & 6 deletions .github/workflows/core-release-docker.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/dashboard-build-and-draft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
30 changes: 17 additions & 13 deletions .github/workflows/dashboard-release-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions core/src/command_console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,19 @@ 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::<Vec<&str>>();
match input_tokens.first() {
Some(&"di") => {
// send input tokens without the first element
handle_docker_command(&input_tokens[1..], app_state).await;
}
_ => {
println!("Unknown command");
println!("Unknown command: {}", input);
continue;
}
}
Expand Down
4 changes: 2 additions & 2 deletions dashboard/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lodestone",
"version": "0.5.0",
"version": "0.5.1",
"private": true,
"scripts": {
"dev": "next dev -p 3001",
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"package": {
"productName": "Lodestone",
"version": "0.5.0"
"version": "0.5.1"
},
"tauri": {
"allowlist": {
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/components/FileViewer/FileList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,15 @@ export default function FileList({
</p>
<div className="grow"></div>

<p className="hidden min-w-[8ch] text-left text-gray-500 @xs:inline">
<p className="@xs:inline hidden min-w-[8ch] text-right text-gray-500">
{file.modification_time || file.creation_time
? formatTimeAgo(
Number(file.modification_time ?? file.creation_time) * 1000
)
: 'Unknown Creation Time'}
</p>

<p className="hidden min-w-[8ch] text-right text-gray-500 @sm:inline">
<p className="@sm:inline hidden min-w-[8ch] text-right text-gray-500">
{file.file_type === 'Directory'
? ''
: file.size
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions example-macros/README.md
Original file line number Diff line number Diff line change
@@ -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)
48 changes: 48 additions & 0 deletions example-macros/auto-backup/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { format } from "https://deno.land/[email protected]/datetime/format.ts";
import { copy } from "https://deno.land/[email protected]/fs/copy.ts";
import { sleep } from "https://deno.land/x/[email protected]/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);
}
Loading