Skip to content

Commit

Permalink
ci: build and test all platforms (#124)
Browse files Browse the repository at this point in the history
* ci: improve ci pipeline
* build on mac and windows too
* cache cargo dependencies
* turn clippy warnings to errors
* docs: add note about running tests as plain `cargo test` is not enough
* ci: fix clippy warning about unreachable code
* ci: use color for cargo output
* ci: install ffmpeg for all runner platforms
* docs: format readme to follow markdown best practices
* docs: platform-independent temp file to fix doctest on windows
  • Loading branch information
Esgrove authored and polyfloyd committed Feb 16, 2024
1 parent fdd100d commit 785a271
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 32 deletions.
85 changes: 67 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,84 @@ on:
- main
workflow_call:

jobs:
env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
fail-fast: false

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

steps:
- uses: actions/checkout@v4
- run: sudo apt update
- run: sudo apt install -y ffmpeg
- run: rustup update
- run: cargo build
- run: cargo test --all-features
- name: Check out source repository
uses: actions/checkout@v4

- name: Install FFmpeg (Ubuntu)
if: runner.os == 'Linux'
run: |
sudo apt update
sudo apt install -y ffmpeg
- name: Install FFmpeg (macOS)
if: runner.os == 'macOS'
run: |
brew install ffmpeg
- name: Install FFmpeg (Windows)
if: runner.os == 'Windows'
run: |
choco install ffmpeg
shell: powershell

- name: Set up Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Build
run: cargo build --verbose

- name: Run tests
run: cargo test --all-features --no-fail-fast

style:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- run: cargo fmt -- --check
- run: cargo clippy
- run: "! grep -r 'dbg!' ./src"
- name: Check out source repository
uses: actions/checkout@v4

- name: Set up Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- run: cargo fmt -- --check
- run: cargo clippy -- -Dwarnings
- run: "! grep -r 'dbg!' ./src"

conventional-commits:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: pip3 install -U Commitizen
# The commit hash here is that of the commit where we started using conventional commits.
- run: cz check --rev-range 16610ddb..HEAD
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: pip3 install -U Commitizen
# The commit hash here is that of the commit where we started using conventional commits.
- run: cz check --rev-range 16610ddb..HEAD
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
rust-id3
========
# rust-id3

[![Build Status](https://github.com/polyfloyd/rust-id3/workflows/CI/badge.svg)](https://github.com/polyfloyd/rust-id3/actions)
[![Crate](https://img.shields.io/crates/v/id3.svg)](https://crates.io/crates/id3)
[![Documentation](https://docs.rs/id3/badge.svg)](https://docs.rs/id3/)

A library for reading and writing ID3 metadata.


## Implemented Features

* ID3v1 reading
* ID3v2.2, ID3v2.3, ID3v2.4 reading/writing
* MP3, WAV and AIFF files
Expand All @@ -27,10 +27,10 @@ A library for reading and writing ID3 metadata.
* MPEG Location Lookup Table frames
* Tag and File Alter Preservation bits


## Examples

### Reading tag frames

```rust
use id3::{Tag, TagLike};

Expand All @@ -56,48 +56,53 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
```

### Modifying any existing tag.
### Modifying any existing tag

```rust
use id3::{Error, ErrorKind, Tag, TagLike, Version};
use std::fs::copy;

fn main() -> Result<(), Box<dyn std::error::Error>> {
copy("testdata/quiet.mp3", "/tmp/music.mp3")?;
let temp_file = std::env::temp_dir().join("music.mp3");
copy("testdata/quiet.mp3", &temp_file)?;

let mut tag = match Tag::read_from_path("/tmp/music.mp3") {
let mut tag = match Tag::read_from_path(&temp_file) {
Ok(tag) => tag,
Err(Error{kind: ErrorKind::NoTag, ..}) => Tag::new(),
Err(err) => return Err(Box::new(err)),
};

tag.set_album("Fancy Album Title");

tag.write_to_path("/tmp/music.mp3", Version::Id3v24)?;
tag.write_to_path(temp_file, Version::Id3v24)?;
Ok(())
}
```

### Creating a new tag, overwriting any old tag.
### Creating a new tag, overwriting any old tag

```rust
use id3::{Tag, TagLike, Frame, Version};
use id3::frame::Content;
use std::fs::copy;

fn main() -> Result<(), Box<dyn std::error::Error>> {
copy("testdata/quiet.mp3", "/tmp/music.mp3")?;
let temp_file = std::env::temp_dir().join("music.mp3");
copy("testdata/quiet.mp3", &temp_file)?;

let mut tag = Tag::new();
tag.set_album("Fancy Album Title");

// Set the album the hard way.
tag.add_frame(Frame::text("TALB", "album"));

tag.write_to_path("/tmp/music.mp3", Version::Id3v24)?;
tag.write_to_path(temp_file, Version::Id3v24)?;
Ok(())
}
```

### Handling damaged or files without a tag

```rust
use id3::{Tag, TagLike, partial_tag_ok, no_tag_ok};

Expand All @@ -118,10 +123,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
```


## Contributing

Do you think you have found a bug? Then please report it via the Github issue tracker. Make sure to
Do you think you have found a bug? Then please report it via the GitHub issue tracker. Make sure to
attach any problematic files that can be used to reproduce the issue. Such files are also used to
create regression tests that ensure that your bug will never return.

Expand All @@ -130,3 +134,9 @@ fixes and new features respectively. This is the
[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) scheme that is used to
automate some maintenance chores such as generating the changelog and inferring the next version
number.

## Running tests

```shell
cargo test --all-features
```
1 change: 0 additions & 1 deletion src/stream/frame/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,6 @@ impl<'a> Decoder<'a> {
let r = match self.r.len() {
0..=8 => self.r,
9.. => &self.r[..8],
_ => unreachable!(),
};
let mut bin = [0; 8];
bin[8 - r.len()..].copy_from_slice(r);
Expand Down

0 comments on commit 785a271

Please sign in to comment.