mirror of
https://github.com/sharkdp/bat.git
synced 2025-03-14 14:48:21 +01:00
Extract crate metadata with cargo
This commit is contained in:
parent
e49235e119
commit
87e87a349a
85
.github/workflows/CICD.yml
vendored
85
.github/workflows/CICD.yml
vendored
@ -14,6 +14,26 @@ on:
|
|||||||
- '*'
|
- '*'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
crate_metadata:
|
||||||
|
name: Extract crate metadata
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Extract crate information
|
||||||
|
id: crate_metadata
|
||||||
|
run: |
|
||||||
|
cargo metadata --no-deps --format-version 1 | jq -r '"name=" + .packages[0].name' | tee -a $GITHUB_OUTPUT
|
||||||
|
cargo metadata --no-deps --format-version 1 | jq -r '"version=" + .packages[0].version' | tee -a $GITHUB_OUTPUT
|
||||||
|
cargo metadata --no-deps --format-version 1 | jq -r '"maintainer=" + .packages[0].authors[0]' | tee -a $GITHUB_OUTPUT
|
||||||
|
cargo metadata --no-deps --format-version 1 | jq -r '"homepage=" + .packages[0].homepage' | tee -a $GITHUB_OUTPUT
|
||||||
|
cargo metadata --no-deps --format-version 1 | jq -r '"msrv=" + .packages[0].rust_version' | tee -a $GITHUB_OUTPUT
|
||||||
|
outputs:
|
||||||
|
name: ${{ steps.crate_metadata.outputs.name }}
|
||||||
|
version: ${{ steps.crate_metadata.outputs.version }}
|
||||||
|
maintainer: ${{ steps.crate_metadata.outputs.maintainer }}
|
||||||
|
homepage: ${{ steps.crate_metadata.outputs.homepage }}
|
||||||
|
msrv: ${{ steps.crate_metadata.outputs.msrv }}
|
||||||
|
|
||||||
ensure_cargo_fmt:
|
ensure_cargo_fmt:
|
||||||
name: Ensure 'cargo fmt' has been run
|
name: Ensure 'cargo fmt' has been run
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
@ -27,17 +47,15 @@ jobs:
|
|||||||
min_version:
|
min_version:
|
||||||
name: Minimum supported rust version
|
name: Minimum supported rust version
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
|
needs: crate_metadata
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout source code
|
- name: Checkout source code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Get the MSRV from the package metadata
|
- name: Install rust toolchain (v${{ needs.crate_metadata.outputs.msrv }})
|
||||||
id: msrv
|
|
||||||
run: cargo metadata --no-deps --format-version 1 | jq -r '"version=" + (.packages[] | select(.name == "bat")).rust_version' >> $GITHUB_OUTPUT
|
|
||||||
- name: Install rust toolchain (v${{ steps.msrv.outputs.version }})
|
|
||||||
uses: dtolnay/rust-toolchain@master
|
uses: dtolnay/rust-toolchain@master
|
||||||
with:
|
with:
|
||||||
toolchain: ${{ steps.msrv.outputs.version }}
|
toolchain: ${{ needs.crate_metadata.outputs.msrv }}
|
||||||
components: clippy
|
components: clippy
|
||||||
- name: Run clippy (on minimum supported rust version to prevent warnings we can't fix)
|
- name: Run clippy (on minimum supported rust version to prevent warnings we can't fix)
|
||||||
run: cargo clippy --locked --all-targets ${{ env.MSRV_FEATURES }}
|
run: cargo clippy --locked --all-targets ${{ env.MSRV_FEATURES }}
|
||||||
@ -116,6 +134,7 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
name: ${{ matrix.job.target }} (${{ matrix.job.os }})
|
name: ${{ matrix.job.target }} (${{ matrix.job.os }})
|
||||||
runs-on: ${{ matrix.job.os }}
|
runs-on: ${{ matrix.job.os }}
|
||||||
|
needs: crate_metadata
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
@ -145,14 +164,6 @@ jobs:
|
|||||||
aarch64-unknown-linux-gnu) sudo apt-get -y update ; sudo apt-get -y install gcc-aarch64-linux-gnu ;;
|
aarch64-unknown-linux-gnu) sudo apt-get -y update ; sudo apt-get -y install gcc-aarch64-linux-gnu ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
- name: Extract crate information
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
echo "PROJECT_NAME=$(sed -n 's/^name = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV
|
|
||||||
echo "PROJECT_VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV
|
|
||||||
echo "PROJECT_MAINTAINER=$(sed -n 's/^authors = \["\(.*\)"\]/\1/p' Cargo.toml)" >> $GITHUB_ENV
|
|
||||||
echo "PROJECT_HOMEPAGE=$(sed -n 's/^homepage = "\(.*\)"/\1/p' Cargo.toml)" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Install Rust toolchain
|
- name: Install Rust toolchain
|
||||||
uses: dtolnay/rust-toolchain@stable
|
uses: dtolnay/rust-toolchain@stable
|
||||||
with:
|
with:
|
||||||
@ -194,7 +205,7 @@ jobs:
|
|||||||
esac;
|
esac;
|
||||||
|
|
||||||
# Setup paths
|
# Setup paths
|
||||||
BIN_NAME="${{ env.PROJECT_NAME }}${EXE_suffix}"
|
BIN_NAME="${{ needs.crate_metadata.outputs.name }}${EXE_suffix}"
|
||||||
BIN_PATH="target/${{ matrix.job.target }}/release/${BIN_NAME}"
|
BIN_PATH="target/${{ matrix.job.target }}/release/${BIN_NAME}"
|
||||||
|
|
||||||
# Let subsequent steps know where to find the binary
|
# Let subsequent steps know where to find the binary
|
||||||
@ -207,7 +218,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
# test only library unit tests and binary for arm-type targets
|
# test only library unit tests and binary for arm-type targets
|
||||||
unset CARGO_TEST_OPTIONS
|
unset CARGO_TEST_OPTIONS
|
||||||
unset CARGO_TEST_OPTIONS ; case ${{ matrix.job.target }} in arm-* | aarch64-*) CARGO_TEST_OPTIONS="--lib --bin ${PROJECT_NAME}" ;; esac;
|
unset CARGO_TEST_OPTIONS ; case ${{ matrix.job.target }} in arm-* | aarch64-*) CARGO_TEST_OPTIONS="--lib --bin ${{ needs.crate_metadata.outputs.name }}" ;; esac;
|
||||||
echo "CARGO_TEST_OPTIONS=${CARGO_TEST_OPTIONS}" >> $GITHUB_OUTPUT
|
echo "CARGO_TEST_OPTIONS=${CARGO_TEST_OPTIONS}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
@ -247,7 +258,7 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
PKG_suffix=".tar.gz" ; case ${{ matrix.job.target }} in *-pc-windows-*) PKG_suffix=".zip" ;; esac;
|
PKG_suffix=".tar.gz" ; case ${{ matrix.job.target }} in *-pc-windows-*) PKG_suffix=".zip" ;; esac;
|
||||||
PKG_BASENAME=${PROJECT_NAME}-v${PROJECT_VERSION}-${{ matrix.job.target }}
|
PKG_BASENAME=${{ needs.crate_metadata.outputs.name }}-v${{ needs.crate_metadata.outputs.version }}-${{ matrix.job.target }}
|
||||||
PKG_NAME=${PKG_BASENAME}${PKG_suffix}
|
PKG_NAME=${PKG_BASENAME}${PKG_suffix}
|
||||||
echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_OUTPUT
|
echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
@ -263,13 +274,13 @@ jobs:
|
|||||||
cp "README.md" "LICENSE-MIT" "LICENSE-APACHE" "CHANGELOG.md" "$ARCHIVE_DIR"
|
cp "README.md" "LICENSE-MIT" "LICENSE-APACHE" "CHANGELOG.md" "$ARCHIVE_DIR"
|
||||||
|
|
||||||
# Man page
|
# Man page
|
||||||
cp 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'-*/out/assets/manual/bat.1 "$ARCHIVE_DIR"
|
cp 'target/${{ matrix.job.target }}/release/build/${{ needs.crate_metadata.outputs.name }}'-*/out/assets/manual/bat.1 "$ARCHIVE_DIR"
|
||||||
|
|
||||||
# Autocompletion files
|
# Autocompletion files
|
||||||
cp 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'-*/out/assets/completions/bat.bash "$ARCHIVE_DIR/autocomplete/${{ env.PROJECT_NAME }}.bash"
|
cp 'target/${{ matrix.job.target }}/release/build/${{ needs.crate_metadata.outputs.name }}'-*/out/assets/completions/bat.bash "$ARCHIVE_DIR/autocomplete/${{ needs.crate_metadata.outputs.name }}.bash"
|
||||||
cp 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'-*/out/assets/completions/bat.fish "$ARCHIVE_DIR/autocomplete/${{ env.PROJECT_NAME }}.fish"
|
cp 'target/${{ matrix.job.target }}/release/build/${{ needs.crate_metadata.outputs.name }}'-*/out/assets/completions/bat.fish "$ARCHIVE_DIR/autocomplete/${{ needs.crate_metadata.outputs.name }}.fish"
|
||||||
cp 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'-*/out/assets/completions/_bat.ps1 "$ARCHIVE_DIR/autocomplete/_${{ env.PROJECT_NAME }}.ps1"
|
cp 'target/${{ matrix.job.target }}/release/build/${{ needs.crate_metadata.outputs.name }}'-*/out/assets/completions/_bat.ps1 "$ARCHIVE_DIR/autocomplete/_${{ needs.crate_metadata.outputs.name }}.ps1"
|
||||||
cp 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'-*/out/assets/completions/bat.zsh "$ARCHIVE_DIR/autocomplete/${{ env.PROJECT_NAME }}.zsh"
|
cp 'target/${{ matrix.job.target }}/release/build/${{ needs.crate_metadata.outputs.name }}'-*/out/assets/completions/bat.zsh "$ARCHIVE_DIR/autocomplete/${{ needs.crate_metadata.outputs.name }}.zsh"
|
||||||
|
|
||||||
# base compressed package
|
# base compressed package
|
||||||
pushd "${PKG_STAGING}/" >/dev/null
|
pushd "${PKG_STAGING}/" >/dev/null
|
||||||
@ -292,10 +303,10 @@ jobs:
|
|||||||
DPKG_DIR="${DPKG_STAGING}/dpkg"
|
DPKG_DIR="${DPKG_STAGING}/dpkg"
|
||||||
mkdir -p "${DPKG_DIR}"
|
mkdir -p "${DPKG_DIR}"
|
||||||
|
|
||||||
DPKG_BASENAME=${PROJECT_NAME}
|
DPKG_BASENAME=${{ needs.crate_metadata.outputs.name }}
|
||||||
DPKG_CONFLICTS=${PROJECT_NAME}-musl
|
DPKG_CONFLICTS=${{ needs.crate_metadata.outputs.name }}-musl
|
||||||
case ${{ matrix.job.target }} in *-musl) DPKG_BASENAME=${PROJECT_NAME}-musl ; DPKG_CONFLICTS=${PROJECT_NAME} ;; esac;
|
case ${{ matrix.job.target }} in *-musl) DPKG_BASENAME=${{ needs.crate_metadata.outputs.name }}-musl ; DPKG_CONFLICTS=${{ needs.crate_metadata.outputs.name }} ;; esac;
|
||||||
DPKG_VERSION=${PROJECT_VERSION}
|
DPKG_VERSION=${{ needs.crate_metadata.outputs.version }}
|
||||||
|
|
||||||
unset DPKG_ARCH
|
unset DPKG_ARCH
|
||||||
case ${{ matrix.job.target }} in
|
case ${{ matrix.job.target }} in
|
||||||
@ -313,13 +324,13 @@ jobs:
|
|||||||
install -Dm755 "${{ steps.bin.outputs.BIN_PATH }}" "${DPKG_DIR}/usr/bin/${{ steps.bin.outputs.BIN_NAME }}"
|
install -Dm755 "${{ steps.bin.outputs.BIN_PATH }}" "${DPKG_DIR}/usr/bin/${{ steps.bin.outputs.BIN_NAME }}"
|
||||||
|
|
||||||
# Man page
|
# Man page
|
||||||
install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'-*/out/assets/manual/bat.1 "${DPKG_DIR}/usr/share/man/man1/${{ env.PROJECT_NAME }}.1"
|
install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ needs.crate_metadata.outputs.name }}'-*/out/assets/manual/bat.1 "${DPKG_DIR}/usr/share/man/man1/${{ needs.crate_metadata.outputs.name }}.1"
|
||||||
gzip -n --best "${DPKG_DIR}/usr/share/man/man1/${{ env.PROJECT_NAME }}.1"
|
gzip -n --best "${DPKG_DIR}/usr/share/man/man1/${{ needs.crate_metadata.outputs.name }}.1"
|
||||||
|
|
||||||
# Autocompletion files
|
# Autocompletion files
|
||||||
install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'-*/out/assets/completions/bat.bash "${DPKG_DIR}/usr/share/bash-completion/completions/${{ env.PROJECT_NAME }}"
|
install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ needs.crate_metadata.outputs.name }}'-*/out/assets/completions/bat.bash "${DPKG_DIR}/usr/share/bash-completion/completions/${{ needs.crate_metadata.outputs.name }}"
|
||||||
install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'-*/out/assets/completions/bat.fish "${DPKG_DIR}/usr/share/fish/vendor_completions.d/${{ env.PROJECT_NAME }}.fish"
|
install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ needs.crate_metadata.outputs.name }}'-*/out/assets/completions/bat.fish "${DPKG_DIR}/usr/share/fish/vendor_completions.d/${{ needs.crate_metadata.outputs.name }}.fish"
|
||||||
install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'-*/out/assets/completions/bat.zsh "${DPKG_DIR}/usr/share/zsh/vendor-completions/_${{ env.PROJECT_NAME }}"
|
install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ needs.crate_metadata.outputs.name }}'-*/out/assets/completions/bat.zsh "${DPKG_DIR}/usr/share/zsh/vendor-completions/_${{ needs.crate_metadata.outputs.name }}"
|
||||||
|
|
||||||
# README and LICENSE
|
# README and LICENSE
|
||||||
install -Dm644 "README.md" "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/README.md"
|
install -Dm644 "README.md" "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/README.md"
|
||||||
@ -330,12 +341,12 @@ jobs:
|
|||||||
|
|
||||||
cat > "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/copyright" <<EOF
|
cat > "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/copyright" <<EOF
|
||||||
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||||
Upstream-Name: ${{ env.PROJECT_NAME }}
|
Upstream-Name: ${{ needs.crate_metadata.outputs.name }}
|
||||||
Source: ${{ env.PROJECT_HOMEPAGE }}
|
Source: ${{ needs.crate_metadata.outputs.homepage }}
|
||||||
|
|
||||||
Files: *
|
Files: *
|
||||||
Copyright: ${{ env.PROJECT_MAINTAINER }}
|
Copyright: ${{ needs.crate_metadata.outputs.maintainer }}
|
||||||
Copyright: $COPYRIGHT_YEARS ${{ env.PROJECT_MAINTAINER }}
|
Copyright: $COPYRIGHT_YEARS ${{ needs.crate_metadata.outputs.maintainer }}
|
||||||
License: Apache-2.0 or MIT
|
License: Apache-2.0 or MIT
|
||||||
|
|
||||||
License: Apache-2.0
|
License: Apache-2.0
|
||||||
@ -376,10 +387,10 @@ jobs:
|
|||||||
Version: ${DPKG_VERSION}
|
Version: ${DPKG_VERSION}
|
||||||
Section: utils
|
Section: utils
|
||||||
Priority: optional
|
Priority: optional
|
||||||
Maintainer: ${{ env.PROJECT_MAINTAINER }}
|
Maintainer: ${{ needs.crate_metadata.outputs.maintainer }}
|
||||||
Homepage: ${{ env.PROJECT_HOMEPAGE }}
|
Homepage: ${{ needs.crate_metadata.outputs.homepage }}
|
||||||
Architecture: ${DPKG_ARCH}
|
Architecture: ${DPKG_ARCH}
|
||||||
Provides: ${{ env.PROJECT_NAME }}
|
Provides: ${{ needs.crate_metadata.outputs.name }}
|
||||||
Conflicts: ${DPKG_CONFLICTS}
|
Conflicts: ${DPKG_CONFLICTS}
|
||||||
Description: cat(1) clone with wings.
|
Description: cat(1) clone with wings.
|
||||||
A cat(1) clone with syntax highlighting and Git integration.
|
A cat(1) clone with syntax highlighting and Git integration.
|
||||||
|
Loading…
Reference in New Issue
Block a user