Skip to content

Commit ca4d3a7

Browse files
committed
Version 1.0.3
Adds GitHub Action
1 parent 43c4c5f commit ca4d3a7

File tree

6 files changed

+73
-27
lines changed

6 files changed

+73
-27
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ This project adheres to [Semantic Versioning](https://semver.org).
66

77
## [Unreleased]
88

9+
## [1.0.3] - 2022-10-14
10+
11+
* Now has an associated GitHub Action for easy CI running
12+
913
## [1.0.2] - 2022-10-14
1014

1115
* Now displays the filepath for the warnings generated by the `--warn-read` flag

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description = "Simple CI tool to check that all DMIs in a directory do not have
44
repository = "https://github.com/spacestation13/dmi-duplicate-state-checker"
55
authors = ["ZeWaka <zewakagamer@gmail.com>"]
66
license = "MIT"
7-
version = "1.0.2"
7+
version = "1.0.3"
88
edition = "2021"
99

1010
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,22 @@ Simple CI tool to check that all DMIs in a directory do not have duplicate icon
44
Example:
55

66
![](https://i.imgur.com/ZZt6Enq.png)
7+
8+
## Action
9+
10+
There is a bundled GitHub Action with this repository, found via the button or [this link](https://github.com/marketplace/actions/check-duplicate-dmi-icon-states).
11+
Here is the simplest example usage within a workflow:
12+
```yml
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- name: Check Duplicate DMI Icon States
17+
uses: spacestation13/dmi-duplicate-state-checker@v1.0.3
18+
with:
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
```
21+
Possible arguments:
22+
* `GITHUB_TOKEN` [REQUIRED] - This should always just be passed the `secrets.GITHUB_TOKEN`, used for fetching and installing the tool.
23+
* `folders_to_search` - Folders to search, comma delineated (default: `./`)
24+
* `flags` - Put other flags for the program here (default: `--warn_read --actions-fmt` (for old/corrupt DMI detection & gh-actions))
25+
* `version` - A release/tag of the binary tool you want to use, in case you don't want to use the corresponding version.

action.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,27 @@ inputs:
99
required: true
1010
folders_to_search:
1111
description: 'Folders to search, comma delineated (default: root folder)'
12-
required: true
1312
default: '.'
1413
flags:
1514
description: Put other flags for the duplicate checker here
16-
default: '--warn_read'
15+
default: '--warn-read --actions-fmt'
1716
version:
1817
description: 'Version of the tool to use (default: latest)'
19-
default: 'v1.0.2'
20-
outputs:
21-
duplicates:
22-
description: "Number of duplicate icons as a string"
23-
value: "0"
18+
default: 'v1.0.3'
2419
runs:
2520
using: "composite"
2621
steps:
2722
- name: Install Duplicate Checker
28-
uses: jaxxstorm/action-install-gh-release@v1.5.0
23+
uses: jaxxstorm/action-install-gh-release@v1.7.1
2924
with:
3025
repo: spacestation13/dmi-duplicate-state-checker
3126
tag: ${{ inputs.version }}
3227
cache: enable
28+
arch: x86_64
3329
env:
3430
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
31+
3532
- run: |
36-
echo "::set-output name=duplicates::$(./dmi-duplicate-state-checker -p ${{ inputs.folders_to_search }} ${{ inputs.flags }})"
37-
shell: bash
33+
os_str=$(echo 'console.log("${{ runner.os }}".toLowerCase())' | node -);
34+
/opt/hostedtoolcache/spacestation13/dmi-duplicate-state-checker/${{ inputs.version }}/${os_str}-x86_64/dmi-duplicate-state-checker -p ${{ inputs.folders_to_search }} ${{ inputs.flags }}
35+
shell: bash

src/main.rs

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ struct Args {
1414
paths: Vec<PathBuf>,
1515

1616
/// Exit with a code of 0 instead of how many duplicates were detected
17-
#[arg(short, long, default_value_t = true)]
17+
#[arg(short, long, default_value_t = false)]
1818
donterror: bool,
1919

2020
/// If a file is encountered that can't be read, output a warning
21-
#[arg(short, long, default_value_t = false)]
21+
#[arg(short, long, default_value_t = true)]
2222
warn_read: bool,
23+
24+
/// Message formatting is in the correct format for GitHub Actions error reporting
25+
#[arg(long)]
26+
actions_fmt: bool,
2327
}
2428

2529
/// Will continue a loop if the passed expr is an error and warn with a message
@@ -61,14 +65,26 @@ fn main() {
6165
args.warn_read
6266
);
6367

64-
let dmi = skip_fail_yell!(
65-
Icon::load(file),
66-
"Couldn't read DMI at {} : {}",
67-
path.to_string_lossy(),
68-
args.warn_read
69-
);
68+
let dmi = match Icon::load(file) {
69+
Ok(val) => val,
70+
Err(e) => {
71+
if args.warn_read {
72+
if args.actions_fmt {
73+
println!(
74+
"::error file={},title=Weird DMI format::Couldn't read DMI at {} : {}",
75+
path.to_string_lossy(),
76+
path.to_string_lossy(),
77+
e
78+
)
79+
} else {
80+
println!("Couldn't read DMI at {} : {}", path.to_string_lossy(), e)
81+
}
82+
}
83+
continue;
84+
}
85+
};
7086

71-
check_dmi(dmi, path, &mut error_count);
87+
check_dmi(dmi, path, &mut error_count, args.actions_fmt);
7288
}
7389
}
7490
println!("Complete, {} duplicates found.", error_count);
@@ -79,7 +95,7 @@ fn main() {
7995
}
8096

8197
/// Checks that a given DMI at a given path has no duplicate states
82-
fn check_dmi(dmi: Icon, path: &Path, error_count: &mut i32) {
98+
fn check_dmi(dmi: Icon, path: &Path, error_count: &mut i32, actions_fmt: bool) {
8399
let mut state_names = Vec::with_capacity(dmi.states.len());
84100

85101
for state in dmi.states {
@@ -88,11 +104,20 @@ fn check_dmi(dmi: Icon, path: &Path, error_count: &mut i32) {
88104
.any(|(name, movement)| (name == &state.name) && (movement == &state.movement))
89105
{
90106
*error_count += 1;
91-
println!(
92-
"Duplicate state in {} : {}",
93-
path.to_string_lossy(),
94-
state.name
95-
);
107+
if actions_fmt {
108+
println!(
109+
"::error file={},title=Duplicate Icon State::Duplicate state in {} : {}",
110+
path.to_string_lossy(),
111+
path.to_string_lossy(),
112+
state.name
113+
)
114+
} else {
115+
println!(
116+
"Duplicate state in {} : {}",
117+
path.to_string_lossy(),
118+
state.name
119+
)
120+
}
96121
} else {
97122
state_names.push((state.name, state.movement));
98123
}

0 commit comments

Comments
 (0)