Skip to content

Commit 675ff25

Browse files
committed
Update wrap example
1 parent e459b84 commit 675ff25

File tree

2 files changed

+60
-28
lines changed

2 files changed

+60
-28
lines changed

.github/workflows/push.yml

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
name: Check experiment
1+
name: check-build-assets-and-publish
2+
run-name: Build assets for projects
23

34
on:
45
push
@@ -7,9 +8,7 @@ jobs:
78
check:
89
runs-on: ubuntu-latest
910

10-
strategy:
11-
matrix:
12-
project: ["str-utilities"]
11+
strategy: { matrix: { project: [str-utilities] } }
1312

1413
steps:
1514
- uses: actions/checkout@v4
@@ -34,20 +33,22 @@ jobs:
3433

3534
strategy:
3635
matrix:
37-
os: [ubuntu-latest, windows-latest]
38-
binary: [str-utilities~group]
36+
os: [ubuntu-latest, windows-latest, macos-latest]
37+
binary: [str-utilities~wrap]
3938
include:
4039
- os: windows-latest
4140
platform-name: x86_64-pc-windows
4241
executable-extension: ".exe"
4342
- os: ubuntu-latest
4443
platform-name: x86_64-unknown-linux
44+
- os: macos-latest
45+
platform-name: aarch64-apple-darwin
4546

4647
runs-on: ${{ matrix.os }}
4748

4849
env:
4950
PROFILE: dev
50-
OUT: debug
51+
OUT: target/debug
5152
GH_RELEASE: assets
5253

5354
steps:
@@ -56,24 +57,24 @@ jobs:
5657

5758
- name: Set variables
5859
id: information
60+
shell: bash
5961
run: |
6062
echo "GITHUB_RUN_DATE=$(TZ="Europe/London" date +"%Y-%m-%d %T")" >> "$GITHUB_OUTPUT"
6163
echo "GIT_LAST_COMMIT=$(git log -n 1 --format="%H")" >> "$GITHUB_OUTPUT"
6264
63-
IFS='~' read -r binary example <<< '${{ matrix.binary }}'
64-
echo "WORKING_DIRECTORY=$binary" >> "$GITHUB_OUTPUT"
65+
IFS='~' read -r project example <<< '${{ matrix.binary }}'
66+
echo "WORKING_DIRECTORY=$project" >> "$GITHUB_OUTPUT"
67+
echo "PROJECT_NAME=$project" >> "$GITHUB_OUTPUT"
6568
if [ -n "$example" ]; then
6669
echo "BUILD_SPECIFIER=--example $example" >> "$GITHUB_OUTPUT"
67-
echo "ASSET_PATH=examples/$example" >> "$GITHUB_OUTPUT"
70+
echo "ASSET_PATH=${{ env.OUT }}/examples/$example${{ matrix.executable-extension }}" >> "$GITHUB_OUTPUT"
6871
echo "ASSET_NAME=$example" >> "$GITHUB_OUTPUT"
6972
else
7073
echo "BUILD_SPECIFIER=" >> "$GITHUB_OUTPUT"
71-
echo "ASSET_PATH=$binary" >> "$GITHUB_OUTPUT"
72-
echo "ASSET_NAME=$binary" >> "$GITHUB_OUTPUT"
74+
echo "ASSET_PATH=${{ env.OUT }}/$project${{ matrix.executable-extension }}" >> "$GITHUB_OUTPUT"
75+
echo "ASSET_NAME=$project" >> "$GITHUB_OUTPUT"
7376
fi
7477
75-
shell: bash
76-
7778
- name: Build binary
7879
working-directory: ${{ steps.information.outputs.WORKING_DIRECTORY }}
7980
run: cargo build ${{ steps.information.outputs.BUILD_SPECIFIER }} --profile ${{ env.PROFILE }}
@@ -83,10 +84,11 @@ jobs:
8384

8485
- name: Publish binary
8586
working-directory: ${{ steps.information.outputs.WORKING_DIRECTORY }}
86-
run: |
87-
FROM="./target/${{ env.OUT }}/${{ steps.information.outputs.ASSET_PATH }}${{ matrix.executable-extension }}"
88-
TO="${{ steps.information.outputs.ASSET_NAME }}-${{ matrix.platform-name }}${{ matrix.executable-extension }}"
89-
gh release upload $GH_RELEASE "$FROM#$TO" --clobber
9087
shell: bash
91-
env:
92-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
env: { "GH_TOKEN": "${{ secrets.GITHUB_TOKEN }}" }
89+
run: |
90+
FROM='${{ steps.information.outputs.ASSET_PATH }}'
91+
TO='${{ steps.information.outputs.ASSET_NAME }}-${{ matrix.platform-name }}${{ matrix.executable-extension }}'
92+
LABEL="${{ steps.information.outputs.PROJECT_NAME }}-$TO"
93+
mv $FROM $TO
94+
gh release upload $GH_RELEASE "$TO#$LABEL" --clobber
Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,24 @@ fn main() {
1414

1515
let mut prefix_: String;
1616

17-
let mut break_at = 40;
17+
let mut break_after = 40;
1818
let mut prefix = "";
1919
let mut splitter = ',';
20+
let mut unstable = false;
2021

2122
while let Some(arg) = args.next() {
2223
match arg.as_str() {
23-
"--break-at" => {
24-
break_at = args.next().expect("width").parse().expect("not a number");
24+
"--break-after" => {
25+
break_after = args.next().expect("width").parse().expect("not a number");
2526
}
2627
"--prefix" => {
2728
prefix_ = args.next().expect("prefix");
2829
prefix = &prefix_;
2930
}
31+
// re-organises
32+
"--unstable" => {
33+
unstable = true;
34+
}
3035
"--splitter" => {
3136
splitter = args.next().expect("splitter").chars().next().unwrap();
3237
}
@@ -36,16 +41,37 @@ fn main() {
3641
}
3742
}
3843

39-
let out = to_buckets(&input, splitter, break_at, prefix);
44+
let out = if unstable {
45+
to_buckets(&input, splitter, break_after, prefix)
46+
} else {
47+
let mut current_width = 0;
48+
let mut buf = prefix.to_string();
49+
for part in input.split(splitter) {
50+
current_width += part.len();
51+
buf.push_str(part.trim());
52+
buf.push(splitter);
53+
// TODO
54+
if current_width > break_after {
55+
buf.push('\n');
56+
buf.push_str(prefix);
57+
current_width = 0;
58+
} else if splitter != ' ' {
59+
buf.push(' ');
60+
}
61+
}
62+
buf.truncate(buf.trim_end().len());
63+
buf
64+
};
65+
4066
println!("{out}");
4167
}
4268

43-
fn to_buckets(on: &str, splitter: char, break_at: usize, prefix: &str) -> String {
69+
fn to_buckets(on: &str, splitter: char, break_after: usize, prefix: &str) -> String {
4470
let mut parts: Vec<&str> = on.split(splitter).collect();
4571
parts.sort_by_key(|item| item.len());
4672

4773
let total = on.len(); // sort of
48-
let bucket_count = total / std::cmp::max(break_at, 1);
74+
let bucket_count = total / std::cmp::max(break_after, 1);
4975
let mut buckets: Vec<Vec<&str>> = vec![Vec::new(); bucket_count];
5076

5177
for (idx, part) in parts.drain(..).enumerate() {
@@ -54,14 +80,18 @@ fn to_buckets(on: &str, splitter: char, break_at: usize, prefix: &str) -> String
5480

5581
let mut buf = String::new();
5682
for mut bucket in buckets {
57-
buf.push_str(prefix);
5883
if !buf.is_empty() {
5984
buf.push_str("\n");
6085
}
86+
buf.push_str(prefix);
6187
bucket.sort_by_key(|part| (part.chars().next().unwrap() as u32 * 12345) % 12);
6288
for (idx, part) in bucket.into_iter().enumerate() {
6389
if idx > 0 {
64-
buf.push_str(", ");
90+
buf.push(splitter);
91+
// TODO
92+
if splitter != ' ' {
93+
buf.push(' ');
94+
}
6595
}
6696
buf.push_str(part);
6797
}

0 commit comments

Comments
 (0)