Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve GitHub Actions Workflows #175

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changelog:
exclude:
authors:
- dependabot
86 changes: 63 additions & 23 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ name: Build

on:
push:
branches: [master]
branches: [ "master" ]
tags: [ "v*" ]
pull_request:
branches: [ "master" ]

jobs:
build:
Expand All @@ -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
Expand All @@ -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
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/*
58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
55 changes: 38 additions & 17 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha
33 changes: 0 additions & 33 deletions .github/workflows/test.yml

This file was deleted.

1 change: 1 addition & 0 deletions crates/redstone/src/noteblock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading