diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..cac1614 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,63 @@ +name: Release crate + +on: + release: + types: [published] + +jobs: + release: + name: Publish to crates.io and create GitHub Release + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + + - name: Cache cargo registry and git index + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: Build and test + run: cargo test --workspace --verbose + + - name: Install cargo-edit and set crate version + id: set_version + run: | + # install cargo-edit (provides `cargo set-version`) + cargo install cargo-edit --locked --force + TAG="${{ github.event.release.tag_name }}" + # strip a leading 'v' if present + VERSION="${TAG#v}" + cargo set-version "$VERSION" --workspace + # expose the version for later steps + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Publish to crates.io + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + run: | + if [ -z "$CARGO_REGISTRY_TOKEN" ]; then + echo "CARGO_REGISTRY_TOKEN is not set. Set it in repository secrets to publish to crates.io" + exit 1 + fi + cargo publish --token "$CARGO_REGISTRY_TOKEN" --allow-dirty + + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{ github.ref_name }} + name: Release ${{ steps.set_version.outputs.version }} + body: | + This release publishes the crate version `${{ steps.set_version.outputs.version }}` to crates.io: + + https://crates.io/crates/schafkopf-logic/${{ steps.set_version.outputs.version }} + + Git tag: ${{ github.ref_name }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index aa47946..c12b89c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ target Cargo.lock shell.nix dist -generated_cards \ No newline at end of file +generated_cards +main.rs \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index a96f12c..1ae2ec7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "schafkopf-logic" -version = "0.1.0" +version = "0.0.0" edition = "2024" description = "Logic and rules for the Schafkopf card game: deck, suits, ranks and game modes." license = "MIT" diff --git a/README.md b/README.md index fa2a345..36e95ad 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Logic and rules for the German card game Schafkopf. This crate provides types and helpers for deck construction, common game modes and basic trick-taking logic. -**Crate:** `schafkopf-logic` • **Version:** 0.1.0 +**Crate:** [`schafkopf-logic`](https://crates.io/crates/schafkopf-logic) ## Features @@ -36,13 +36,13 @@ fn main() { deck.shuffle(); let hands = deck.deal_4x8().expect("deck should contain 32 cards"); - // form a sample trick from the first card of each hand + // Form a sample trick from the first card of each hand and print it let trick = [&hands[0][0], &hands[1][0], &hands[2][0], &hands[3][0]]; - let winner = Gamemode::Sauspiel(Suit::Herz).winning_card(trick); - println!("Winning card: {}", winner); + println!("Trick: {}, {}, {}, {}", trick[0], trick[1], trick[2], trick[3]); - // rank points example - assert_eq!(Rank::Ass.points(), 11); + // Determine the winner for a sample game mode (Sauspiel with Schell) + let winner = Gamemode::Sauspiel(Suit::Schell).winning_card(trick); + println!("Winning card: {}", winner); } ```