From 1ec102a09cdb98e1b681dafd597478f813b3d767 Mon Sep 17 00:00:00 2001 From: robot9001 Date: Sat, 7 Oct 2023 22:18:32 +0200 Subject: [PATCH] ci: Add and use `setup-libmagic` Action Signed-off-by: robot9001 --- .github/actions/setup-libmagic/action.yml | 87 +++++++++++++++++++++++ .github/workflows/linux.yml | 1 + .github/workflows/mac.yml | 5 +- .github/workflows/windows.yml | 5 +- 4 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 .github/actions/setup-libmagic/action.yml diff --git a/.github/actions/setup-libmagic/action.yml b/.github/actions/setup-libmagic/action.yml new file mode 100644 index 0000000..d6def2e --- /dev/null +++ b/.github/actions/setup-libmagic/action.yml @@ -0,0 +1,87 @@ +name: setup-libmagic +description: Setup some version of `libmagic` for `magic-sys` + +runs: + using: 'composite' + steps: + # setup cache + - name: setup cache + if: ${{ runner.os == 'Windows' }} + uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1 + with: + script: | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); + + + # update packages + + - name: update packages + if: ${{ runner.os == 'Linux' }} + run: sudo apt-get update + shell: bash + + - name: update packages + if: ${{ runner.os == 'Windows' }} + run: vcpkg update + shell: bash + + - name: update packages + if: ${{ runner.os == 'macOS' }} + run: brew update + shell: bash + + + # install packages + + - name: install packages + if: ${{ runner.os == 'Linux' }} + run: sudo apt-get install libmagic1 libmagic-dev pkg-config + shell: bash + + - name: install packages + if: ${{ runner.os == 'Windows' }} + run: | + vcpkg install libmagic:x64-windows-static-md + echo "VCPKG_ROOT=${VCPKG_INSTALLATION_ROOT}" >> "${GITHUB_ENV}" + shell: bash + + - name: install packages + if: ${{ runner.os == 'macOS' }} + run: brew install libmagic pkg-config + shell: bash + + + # setup environment + + - name: setup environment + if: ${{ runner.os == 'Linux' }} + run: echo "VCPKGRS_NO_LIBMAGIC=1" >> "${GITHUB_ENV}" + shell: bash + + - name: setup environment + if: ${{ runner.os == 'Windows' }} + run: echo "LIBMAGIC_NO_PKG_CONFIG=1" >> "${GITHUB_ENV}" + shell: bash + + - name: setup environment + if: ${{ runner.os == 'macOS' }} + run: echo "VCPKGRS_NO_LIBMAGIC=1" >> "${GITHUB_ENV}" + shell: bash + + # setup static build + + - name: setup static build + if: ${{ runner.os == 'Linux' }} + run: echo "LIBMAGIC_STATIC=1" >> "${GITHUB_ENV}" + shell: bash + + - name: setup static build + if: ${{ runner.os == 'Windows' }} + run: echo "Static builds are the default for vcpkg-rs" + shell: bash + + - name: setup static build + if: ${{ runner.os == 'macOS' }} + run: echo "LIBMAGIC_STATIC=1" >> "${GITHUB_ENV}" + shell: bash diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 0775229..38952de 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -16,6 +16,7 @@ jobs: steps: - uses: actions/checkout@v2 + - uses: ./.github/actions/setup-libmagic - name: Build run: cargo build --verbose - name: Run tests diff --git a/.github/workflows/mac.yml b/.github/workflows/mac.yml index a353813..6d78e90 100644 --- a/.github/workflows/mac.yml +++ b/.github/workflows/mac.yml @@ -16,10 +16,7 @@ jobs: steps: - uses: actions/checkout@v2 - - name: brew - run: | - brew update - brew install libmagic + - uses: ./.github/actions/setup-libmagic - name: install Rust MSRV uses: actions-rs/toolchain@b2417cde72dcf67f306c0ae8e0828a81bf0b189f # v1.0.6 with: diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 31e752f..3c26075 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -16,10 +16,7 @@ jobs: steps: - uses: actions/checkout@v2 - - name: vcpkg - run: | - cargo +stable install cargo-vcpkg - cargo vcpkg build + - uses: ./.github/actions/setup-libmagic - name: Build run: cargo build --verbose - name: Run tests