Skip to content

Commit

Permalink
Merge pull request #12 from bpmb82/bb/feature/github_actions
Browse files Browse the repository at this point in the history
Bb/feature/GitHub actions
  • Loading branch information
bpmb82 authored Jul 27, 2024
2 parents ab7af8f + 3f522ff commit cfb9f2c
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]

- 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/[email protected]
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

16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
5 changes: 5 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cfb9f2c

Please sign in to comment.