chore(ci): update sync

This commit is contained in:
omo50
2026-04-18 15:04:53 -06:00
parent a5dbd2cc7c
commit b67ff493d0
2 changed files with 120 additions and 42 deletions

View File

@@ -1,12 +1,13 @@
name: "CoreSync"
name: "Sync"
on:
push:
branches: [ "main" ]
branches: ["main"]
paths:
- 'modpacks/lce-core/**/mods/**'
- 'modpacks/lce-core/**/resourcepacks/**'
- 'modpacks/lce-core/**/resources/**'
workflow_dispatch:
jobs:
sync:
@@ -15,21 +16,62 @@ jobs:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
fetch-depth: 1
filter: blob:none
sparse-checkout: |
modpacks
src/actions/coresync
- name: Rust Cache
uses: Swatinem/rust-cache@v2
- name: Cache CoreSync Binary
id: cache-coresync
uses: actions/cache@v4
with:
# Point to the new src/actions location
workspaces: "src/actions/coresync -> target"
path: ./coresync-bin
key: coresync-v1-${{ runner.os }}-${{ hashFiles('src/actions/coresync/**/*.rs', 'src/actions/coresync/Cargo.toml', 'src/actions/coresync/Cargo.lock') }}
- name: Install Rust
if: steps.cache-coresync.outputs.cache-hit != 'true'
uses: dtolnay/rust-toolchain@stable
- name: Rust Cache (Compiler Internals)
if: steps.cache-coresync.outputs.cache-hit != 'true'
uses: Swatinem/rust-cache@v2
with:
workspaces: "src/actions/coresync -> target"
- name: Build CoreSync
if: steps.cache-coresync.outputs.cache-hit != 'true'
run: |
cargo build --release --manifest-path src/actions/coresync/Cargo.toml --bin coresync
mkdir -p ./coresync-bin
cp src/actions/coresync/target/release/coresync ./coresync-bin/coresync
- name: Cache Packwiz Binaries
id: cache-go
uses: actions/cache@v4
with:
path: ~/go/bin
key: go-bin-packwiz-v1-${{ runner.os }}
- name: Setup Go
if: steps.cache-go.outputs.cache-hit != 'true'
uses: actions/setup-go@v5
with:
go-version: 'stable'
cache: true
- name: Install Packwiz
if: steps.cache-go.outputs.cache-hit != 'true'
run: go install github.com/packwiz/packwiz@latest
- name: Add Go bin to PATH
run: echo "$HOME/go/bin" >> $GITHUB_PATH
- name: Run CoreSync
run: |
cargo run --release --manifest-path src/actions/coresync/Cargo.toml
chmod +x ./coresync-bin/coresync
./coresync-bin/coresync
- name: Commit and Push
uses: https://github.com/EndBug/add-and-commit@v9

View File

@@ -1,68 +1,104 @@
use anyhow::{bail, Context, Result};
use std::fs;
use std::path::{Path, PathBuf};
use std::path::Path;
use std::process::Command;
use walkdir::WalkDir;
fn main() {
let sync_map = vec![
("modpacks/lce-core/1.21.10-mr", vec![
const SUBFOLDERS: &[&str] = &["mods", "resourcepacks", "resources"];
const SYNC_MAP: &[(&str, &[&str])] = &[
(
"modpacks/lce-core/1.21.10-mr",
&[
"modpacks/simply/1.21.10-mr",
"modpacks/rc-plus/1.21.10-mr",
]),
("modpacks/lce-core/1.21.10-cf", vec![
],
),
(
"modpacks/lce-core/1.21.10-cf",
&[
"modpacks/simply/1.21.10-cf",
"modpacks/rc-plus/1.21.10-cf",
]),
];
],
),
];
for (src_str, targets) in sync_map {
fn main() -> Result<()> {
for (src_str, targets) in SYNC_MAP {
let src_path = Path::new(src_str);
if !src_path.exists() {
println!("Skipping source {}: Not found", src_str);
println!("skipping source {src_str}: not found");
continue;
}
for target_str in targets {
for target_str in *targets {
let target_path = Path::new(target_str);
if !target_path.exists() { continue; }
if !target_path.exists() {
println!("skipping target {target_str}: not found");
continue;
}
println!("Syncing {} -> {}", src_str, target_str);
sync_subfolder(src_path, target_path, "mods");
sync_subfolder(src_path, target_path, "resourcepacks");
sync_subfolder(src_path, target_path, "resources");
println!("syncing {src_str} -> {target_str}");
refresh_packwiz(target_path);
for folder in SUBFOLDERS {
sync_subfolder(src_path, target_path, folder)
.with_context(|| format!("failed syncing '{folder}' to {target_str}"))?;
}
refresh_packwiz(target_path)
.with_context(|| format!("packwiz refresh failed in {target_str}"))?;
}
}
println!("all syncs completed.");
Ok(())
}
fn sync_subfolder(src_root: &Path, dst_root: &Path, folder: &str) {
fn sync_subfolder(src_root: &Path, dst_root: &Path, folder: &str) -> Result<()> {
let src = src_root.join(folder);
let dst = dst_root.join(folder);
if !src.exists() {
return Ok(());
}
if !src.exists() { return; }
let mut copied = 0usize;
for entry in WalkDir::new(&src)
.into_iter()
.filter_map(|e| e.ok())
.filter(|e| !e.path().is_dir())
{
let src_file = entry.path();
let relative = src_file.strip_prefix(src_root).unwrap();
for entry in WalkDir::new(&src) {
let entry = entry.context("walkdir error")?;
let path = entry.path();
if path.is_dir() {
continue;
}
let relative = path.strip_prefix(src_root).context("strip_prefix failed")?;
let target_file = dst_root.join(relative);
if let Some(parent) = target_file.parent() {
fs::create_dir_all(parent).expect("Failed to create dirs");
fs::create_dir_all(parent)
.with_context(|| format!("failed to create {}", parent.display()))?;
}
fs::copy(src_file, &target_file).expect("Failed to copy file");
fs::copy(path, &target_file).with_context(|| {
format!(
"failed to copy {} -> {}",
path.display(),
target_file.display()
)
})?;
copied += 1;
}
println!(" {folder}: {copied} file(s) copied");
Ok(())
}
fn refresh_packwiz(dir: &Path) {
let _ = Command::new("packwiz")
.arg("refresh")
fn refresh_packwiz(dir: &Path) -> Result<()> {
let status = Command::new("packwiz")
.args(["refresh", "-y"])
.current_dir(dir)
.status();
.status()
.context("failed to invoke packwiz")?;
if !status.success() {
bail!("packwiz refresh exited with {status}");
}
Ok(())
}