chore: add Nix Flake #126
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: test | |
on: | |
push: | |
paths-ignore: | |
- '**/*.md' | |
branches: | |
- main | |
pull_request: | |
paths-ignore: | |
- '**/*.md' | |
env: | |
CARGO_TERM_COLOR: always | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.event.repository.name }} | |
jobs: | |
linux: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: Swatinem/rust-cache@v2 | |
- name: Install dependencies | |
run: | | |
sudo apt-get install \ | |
pkg-config \ | |
cmake \ | |
libclang-dev \ | |
libfftw3-dev \ | |
libavutil-dev \ | |
libavformat-dev \ | |
libswresample-dev \ | |
libavcodec-dev | |
- name: Test needle | |
run: cd needle && cargo test -v | |
- name: Test needle-capi | |
run: cd needle-capi && cargo build -v && cargo test -v | |
- name: Build needle-capi examples | |
run: cd needle-capi/examples && make all | |
linux-nix-build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: cachix/install-nix-action@v22 | |
with: | |
github_access_token: ${{ secrets.GITHUB_TOKEN }} | |
nix_path: nixpkgs=channel:nixos-unstable | |
- uses: DeterminateSystems/magic-nix-cache-action@main | |
- run: nix build | |
macos: | |
runs-on: macos-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: Swatinem/rust-cache@v2 | |
- name: Install dependencies | |
run: brew install ffmpeg | |
- name: Test needle | |
run: cd needle && cargo test -v | |
- name: Test needle-capi | |
run: cd needle-capi && cargo build -v && cargo test -v | |
- name: Build needle-capi examples | |
run: cd needle-capi/examples && make all | |
windows: | |
runs-on: windows-latest | |
env: | |
VCPKG_ROOT: ${{ github.workspace }}/vcpkg | |
VCPKG_DEFAULT_BINARY_CACHE: ${{ github.workspace }}/vcpkg-bincache | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: Swatinem/rust-cache@v2 | |
- name: "Create directory '${{ env.VCPKG_DEFAULT_BINARY_CACHE }}'" | |
run: mkdir -p $VCPKG_DEFAULT_BINARY_CACHE | |
shell: bash | |
- name: Install cargo-vcpkg | |
run: cargo install cargo-vcpkg | |
- name: Restore vcpkg and its artifacts. | |
uses: actions/cache@v3 | |
env: | |
cache-name: cache-vcpkg | |
with: | |
path: | | |
${{ env.VCPKG_ROOT }} | |
!${{ env.VCPKG_ROOT }}/buildtrees | |
!${{ env.VCPKG_ROOT }}/packages | |
!${{ env.VCPKG_ROOT }}/downloads | |
!${{ env.VCPKG_ROOT }}/installed | |
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles( 'needle/Cargo.lock' ) }} | |
- name: Install dependencies | |
run: cd needle && cargo vcpkg --verbose build | |
shell: bash | |
- name: Test needle | |
run: cd needle && cargo test -v --features static | |
build-and-push-latest-image: | |
runs-on: ubuntu-latest | |
needs: | |
- linux | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Build image | |
run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" | |
- name: Log in to registry | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin | |
- name: Push image | |
run: | | |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME | |
# Change all uppercase to lowercase | |
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | |
echo IMAGE_ID=$IMAGE_ID | |
docker tag $IMAGE_NAME $IMAGE_ID:latest | |
docker push $IMAGE_ID:latest |