diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml new file mode 100644 index 0000000..b28ccb3 --- /dev/null +++ b/.github/workflows/action.yml @@ -0,0 +1,82 @@ +name: Build + +on: + push: + tags: + - 'v*' + +jobs: + build: + runs-on: ${{ matrix.runner }} + + strategy: + matrix: + include: + - name: linux-amd64 + runner: ubuntu-latest + target: x86_64-unknown-linux-gnu + artifact_name: ${{ github.event.repository.name }}-linux-amd64.tar.gz + asset_extension: "" + compression_type: tar + - name: win-amd64 + runner: windows-latest + target: x86_64-pc-windows-msvc + artifact_name: ${{ github.event.repository.name }}-windows-amd64.zip + asset_extension: ".exe" + compression_type: zip + - name: macos-amd64 + runner: macos-latest + target: x86_64-apple-darwin + artifact_name: ${{ github.event.repository.name }}-macos-amd64.tar.gz + asset_extension: "" + compression_type: tar + - name: macos-arm64 + runner: macos-latest + target: aarch64-apple-darwin + artifact_name: ${{ github.event.repository.name }}-macos-aarch64.tar.gz + asset_extension: "" + compression_type: tar + + steps: + + - name: Get tag + id: tag + uses: devops-actions/action-get-tag@v1.0.3 + + - name: Install dependencies if target is Linux x86_64 + shell: bash + run: | + sudo apt update && sudo apt install -y gcc curl libasound2-dev libasound2 openssl pkg-config + if: ${{ matrix.target == 'x86_64-unknown-linux-gnu' }} + + - name: Checkout + uses: actions/checkout@v3 + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + targets: "${{ matrix.target }}" + + - name: Setup Cache + uses: Swatinem/rust-cache@v2 + + - name: Build Binary + run: cargo build --verbose --release --target ${{ matrix.target }} + + - name: Archive Release + uses: thedoctor0/zip-release@0.7.6 + with: + type: ${{ matrix.compression_type }} + directory: target/${{ matrix.target }}/release/ + path: ${{ github.event.repository.name }}${{ matrix.asset_extension }} + filename: '${{ matrix.artifact_name }}' + + - name: Create Github Release + uses: ncipollo/release-action@v1 + with: + name: ${{ steps.tag.outputs.tag }} + artifacts: target/${{ matrix.target }}/release/${{ matrix.artifact_name }} + replacesArtifacts: true + token: ${{ secrets.GITHUB_TOKEN }} + allowUpdates: true + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..49a7f21 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM debian:bookworm-slim + +# Install Rust system-wide +ENV RUSTUP_HOME=/opt/rust +ENV CARGO_HOME=/opt/rust +ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse + +RUN apt update && apt install -y gcc curl libasound2-dev libasound2 openssl pkg-config && \ + curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path +ENV PATH="/opt/rust/bin:${PATH}" + +COPY entrypoint.sh /entrypoint.sh + +WORKDIR /mqtt2midi + +CMD [ "/entrypoint.sh" ] \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..62fd1ea --- /dev/null +++ b/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +docker build --load -t mqtt2midi:latest . + +docker run -ti -v $PWD:/mqtt2midi -w /mqtt2midi --env USERID=$(id -u ${USER}) --env DIR=$PWD mqtt2midi:latest \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..f4c4a1e --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +cargo build --release --target-dir /mqtt2midi/target +echo "Release was built to $DIR/target/" +chown -R ${USERID}:${USERID} /mqtt2midi/target \ No newline at end of file