Skip to content

Commit

Permalink
Configure Action
Browse files Browse the repository at this point in the history
  • Loading branch information
CaveNightingale committed Feb 15, 2024
1 parent 36457bf commit fee20fa
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 36 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/action-rs/grcov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
branch: true
ignore-not-existing: true
llvm: true
filter: covered
output-type: lcov
output-path: ./lcov.info
prefix-dir: /home/user/build
109 changes: 109 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Rust

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
env:
CARGO_INCREMENTAL: '0'
RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
- name: Run grcov
id: coverage
uses: actions-rs/grcov@v0.1
- name: Coveralls upload
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ${{ steps.coverage.outputs.report }}
- name: Run clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --verbose
- name: Run formatting
uses: actions-rs/cargo@v1
with:
command: fmt
args: --check
- name: Build release
uses: actions-rs/cargo@v1
with:
command: build
args: --release
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: uuid-remapper-x86_64-linux
path: target/release/uuid-remapper

windows:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
- name: Test
uses: actions-rs/cargo@v1
with:
command: test
- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --release
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: uuid-remapper-x86_64-windows.exe
path: target/release/uuid-remapper.exe

macos:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
- name: Test
uses: actions-rs/cargo@v1
with:
command: test
- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --release
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: uuid-remapper-x86_64-macos
path: target/release/uuid-remapper
22 changes: 13 additions & 9 deletions src/anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ impl Anvil {
.next()
.and_then(|s| s.parse::<i64>().ok())
.context("Invalid z coordinate")?;
Ok(self
.path
.with_file_name(format!("c.{}.{}.mcc", x * 32 + local.0 as i64, z * 32 + local.1 as i64)))
Ok(self.path.with_file_name(format!(
"c.{}.{}.mcc",
x * 32 + local.0 as i64,
z * 32 + local.1 as i64
)))
}

/// Open an anvil file
Expand Down Expand Up @@ -317,12 +319,14 @@ fn test() {
assert_eq!(chunk.timestamp, chunk_read.timestamp);
assert_eq!(chunk.uncompressed, chunk_read.uncompressed);
assert_eq!(true, chunk_read.external);
anvil.write(&Chunk {
external: true,
location: (0, 0),
timestamp: 0,
uncompressed: vec![0; 1024],
}).unwrap();
anvil
.write(&Chunk {
external: true,
location: (0, 0),
timestamp: 0,
uncompressed: vec![0; 1024],
})
.unwrap();
assert!(!Path::new("c.-32.-32.mcc").exists());

// TODO: Poor test coverage
Expand Down
12 changes: 8 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ fn main() {
.unwrap();

if std::mem::size_of::<usize>() < 8 {
log::error!("usize is less than 64-bit, you may encounter integer overflow when \
dealing with some malformed NBT");
log::error!(
"usize is less than 64-bit, you may encounter integer overflow when \
dealing with some malformed NBT"
);
log::error!("Do not report this issue to the author, as it is not worth fixing");
log::error!("Since Minecraft almost can't run on 32-bit devices, \
running this program, which is designed to work with Minecraft, is meaningless");
log::error!(
"Since Minecraft almost can't run on 32-bit devices, \
running this program, which is designed to work with Minecraft, is meaningless"
);
}

let path = cli.path;
Expand Down
47 changes: 27 additions & 20 deletions src/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,35 +155,35 @@ pub fn get_mapping(kind: MappingKind, path: &Path) -> anyhow::Result<HashMap<Uui
MappingKind::Json => {
let map = std::fs::read_to_string(path)?;
Ok(serde_json::from_str(&map)?)
},
}
MappingKind::ListToOffline => {
let names = load_name_list(path)?;
Ok(a_compose_b_inverse(
&online_uuids(&names),
&offline_uuids(&names),
))
},
}
MappingKind::ListToOnline => {
let names = load_name_list(path)?;
Ok(a_compose_b_inverse(
&offline_uuids(&names),
&online_uuids(&names),
))
},
}
MappingKind::UsercacheToOffline => {
let names = load_name_list_from_usercache(path)?;
Ok(a_compose_b_inverse(
&online_uuids(&names),
&offline_uuids(&names),
))
},
}
MappingKind::UsercacheToOnline => {
let names = load_name_list_from_usercache(path)?;
Ok(a_compose_b_inverse(
&offline_uuids(&names),
&online_uuids(&names),
))
},
}
MappingKind::OfflineRenameCsv => load_offline_rename(path),
}
}
Expand All @@ -199,8 +199,14 @@ fn test() {
assert_eq!(
get_mapping(MappingKind::Csv, &csv_path).unwrap(),
vec![
(Uuid::from_str("00000000-0000-0000-0000-000000000000").unwrap(), Uuid::from_str("00000000-0000-0000-0000-000000000001").unwrap()),
(Uuid::from_str("00000000-0000-0000-0000-000000000002").unwrap(), Uuid::from_str("00000000-0000-0000-0000-000000000003").unwrap()),
(
Uuid::from_str("00000000-0000-0000-0000-000000000000").unwrap(),
Uuid::from_str("00000000-0000-0000-0000-000000000001").unwrap()
),
(
Uuid::from_str("00000000-0000-0000-0000-000000000002").unwrap(),
Uuid::from_str("00000000-0000-0000-0000-000000000003").unwrap()
),
]
.into_iter()
.collect()
Expand All @@ -216,8 +222,14 @@ fn test() {
assert_eq!(
get_mapping(MappingKind::Json, &json_path).unwrap(),
vec![
(Uuid::from_str("00000000-0000-0000-0000-000000000000").unwrap(), Uuid::from_str("00000000-0000-0000-0000-000000000001").unwrap()),
(Uuid::from_str("00000000-0000-0000-0000-000000000002").unwrap(), Uuid::from_str("00000000-0000-0000-0000-000000000003").unwrap()),
(
Uuid::from_str("00000000-0000-0000-0000-000000000000").unwrap(),
Uuid::from_str("00000000-0000-0000-0000-000000000001").unwrap()
),
(
Uuid::from_str("00000000-0000-0000-0000-000000000002").unwrap(),
Uuid::from_str("00000000-0000-0000-0000-000000000003").unwrap()
),
]
.into_iter()
.collect()
Expand All @@ -229,11 +241,7 @@ fn test() {
std::fs::write(&list_path, list_file).unwrap();
assert_eq!(
load_name_list(&list_path).unwrap(),
vec![
"a".to_string(),
"b".to_string(),
"c".to_string(),
]
vec!["a".to_string(), "b".to_string(), "c".to_string(),]
);
std::fs::remove_file(list_path).unwrap();

Expand All @@ -242,11 +250,7 @@ fn test() {
std::fs::write(&usercache_path, usercache_file).unwrap();
assert_eq!(
load_name_list_from_usercache(&usercache_path).unwrap(),
vec![
"a".to_string(),
"b".to_string(),
"c".to_string(),
]
vec!["a".to_string(), "b".to_string(), "c".to_string(),]
);
std::fs::remove_file(usercache_path).unwrap();

Expand All @@ -264,6 +268,9 @@ fn test() {
);
std::fs::remove_file(offline_rename_path).unwrap();

assert_eq!(offline_uuid("CaveNightingale"), Uuid::from_str("2d318504-1a7b-39dc-8c18-44df798a5c06").unwrap());
assert_eq!(
offline_uuid("CaveNightingale"),
Uuid::from_str("2d318504-1a7b-39dc-8c18-44df798a5c06").unwrap()
);
// Online UUIDs are not tested because it requires network access
}
2 changes: 1 addition & 1 deletion src/nbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ fn test_visit_nbt() {
de.get("yyUUIDLeast"),
Some(&Value::Long(FROM.as_u64_pair().1 as i64))
); // Should not be replaced
// No root tag
// No root tag
let mut nbt = vec![];
assert!(visit_nbt(&mut nbt, &mut |_| None).is_err());
// Non-long UUIDMost/UUIDLeast
Expand Down
3 changes: 2 additions & 1 deletion src/remap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@ fn test() {
None
}
},
).unwrap();
)
.unwrap();
}
2 changes: 1 addition & 1 deletion src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn visit_text(text: &mut [u8], cb: &impl Fn(Uuid) -> Option<Uuid>) {
macro_rules! dfa_trans_table {
{$( $current:pat => $next:expr; $other:expr; )*} => {
matched = match matched {
$($current => if text[i] == b'_' {
$($current => if text[i] == b'-' {
$next
} else {
$other
Expand Down

0 comments on commit fee20fa

Please sign in to comment.