diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 00000000..ddb3e480 --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,4 @@ +changelog: + exclude: + authors: + - dependabot diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4d92a1ef..2e218b95 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,10 @@ name: Build on: push: - branches: [master] + branches: [ "master" ] + tags: [ "v*" ] + pull_request: + branches: [ "master" ] jobs: build: @@ -27,27 +30,26 @@ jobs: runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - target: ${{ matrix.target }} - profile: minimal - - uses: Swatinem/rust-cache@v2 - with: - key: ${{ matrix.target }} + - uses: actions/checkout@v4 - - name: Build - uses: actions-rs/cargo@v1 - with: - command: build - args: --release --target ${{ matrix.target }} + - uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} + + - uses: Swatinem/rust-cache@v2 + with: + key: ${{ matrix.target }} - - name: Upload - uses: actions/upload-artifact@v4 - with: - name: mchprs-${{ matrix.target }} - path: target/${{ matrix.target }}/release/mchprs${{ matrix.ext }} + - name: Build + env: + CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER: rust-lld.exe + run: cargo build --release --target ${{ matrix.target }} + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: mchprs-${{ matrix.target }} + path: target/${{ matrix.target }}/release/mchprs${{ matrix.ext }} build-macos-universal: needs: build @@ -62,11 +64,49 @@ jobs: name: mchprs-aarch64-apple-darwin path: aarch64 - - name: Build + - name: Create universal binary run: lipo -create -output mchprs x86_64/mchprs aarch64/mchprs - - name: Upload + - name: Upload artifact uses: actions/upload-artifact@v4 with: name: mchprs-universal-apple-darwin - path: mchprs \ No newline at end of file + path: mchprs + + publish: + needs: [build, build-macos-universal] + runs-on: ubuntu-latest + permissions: + contents: write + if: github.event_name == 'push' + steps: + - uses: actions/checkout@v3 + - uses: actions/download-artifact@v4 + with: + path: artifacts + - name: Reorganize artifacts + run: | + mkdir -p dist/ + find artifacts/ -type f -exec bash -c 'base=$(basename $1); mv $1 dist/$(basename $(dirname $1))${base#${base%.*}}' _ {} \; + + - name: Create preview release + env: + GITHUB_TOKEN: ${{ github.token }} + run: | + gh release delete preview --yes || true + gh release create preview \ + --prerelease \ + --title "${GITHUB_REPOSITORY} Preview Build" \ + --notes "🚧 **This is a preview build of the latest commit.**" \ + dist/* + + - name: Create release + if: startsWith(github.ref, 'refs/tags/') + env: + GITHUB_TOKEN: ${{ github.token }} + tag: ${{ github.ref_name }} + run: | + gh release create "$tag" \ + --title "${GITHUB_REPOSITORY} ${tag#v}" \ + --generate-notes \ + dist/* diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..c2678b92 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,58 @@ +name: CI + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +env: + CARGO_TERM_COLOR: always + +jobs: + format: + name: Check formatting + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + + - name: Check formatting + run: cargo fmt --check --all + + clippy: + name: Clippy lints + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + components: clippy + + - name: Rust cache + uses: Swatinem/rust-cache@v2 + + - name: Run clippy + # If we ever get around to fix everything clippy complains about we can start failing on warning via: -- -D warnings + run: cargo clippy --all-features --all-targets + + test: + name: Run tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + + - name: Rust cache + uses: Swatinem/rust-cache@v2 + + - name: Run tests + run: cargo test --all-features --all-targets diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index ba527e9c..90566488 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,30 +2,51 @@ name: Docker on: push: - branches: [ master ] - + branches: [ "master" ] + tags: [ "v*" ] + jobs: - build: + docker: runs-on: ubuntu-latest - + permissions: + contents: read steps: - - - name: Checkout - uses: actions/checkout@v2 - - - name: Login to Docker Hub - uses: docker/login-action@v1 + - name: Checkout + uses: actions/checkout@v4 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ secrets.DOCKER_HUB_USERNAME }}/mchprs + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=semver,pattern={{major}}.{{minor}}.{{patch}} + type=semver,pattern={{major}}.{{minor}} + type=sha,format=short + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: arm64 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Build and push latest - uses: docker/build-push-action@v2 + + - name: Build and push + uses: docker/build-push-action@v5 with: context: . file: ./docker/Dockerfile + platforms: linux/amd64,linux/arm64 push: true - tags: ${{ secrets.DOCKER_HUB_USERNAME }}/mchprs:latest \ No newline at end of file + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 18dc8a80..00000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Test - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -env: - CARGO_TERM_COLOR: always - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - - uses: Swatinem/rust-cache@v1 - - - name: Build - uses: actions-rs/cargo@v1 - with: - command: test - args: --verbose - - - name: Check formatting - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check diff --git a/crates/redstone/src/noteblock.rs b/crates/redstone/src/noteblock.rs index 6add99ea..ff2a2f4f 100644 --- a/crates/redstone/src/noteblock.rs +++ b/crates/redstone/src/noteblock.rs @@ -4,6 +4,7 @@ use mchprs_world::World; // LUT generated via f32::powf(2.0, (note as f32 - 12.0) / 12.0) // This is hardcoded because at this point floating point operations are not allowed in const contexts +#[allow(clippy::approx_constant)] const PITCHES_TABLE: [f32; 25] = [ 0.5, 0.5297315, 0.561231, 0.59460354, 0.62996054, 0.6674199, 0.70710677, 0.74915355, 0.7937005, 0.8408964, 0.8908987, 0.9438743, 1.0, 1.0594631, 1.122462, 1.1892071, 1.2599211, 1.3348398,