Skip to content

refactor(ci): release proposal dispatch wf #19660

refactor(ci): release proposal dispatch wf

refactor(ci): release proposal dispatch wf #19660

Workflow file for this run

name: Lint
on:
pull_request:
push:
branches:
- main
- mq-working-branch-*
env:
CARGO_TERM_COLOR: always
jobs:
setup:
runs-on: ubuntu-latest
outputs:
crates-count: ${{ steps.set-packages.outputs.crates-count }}
fmt-packages: ${{ steps.set-packages.outputs.fmt-packages }}
clippy-packages: ${{ steps.set-packages.outputs.clippy-packages }}
rust-version: ${{ steps.rust-version.outputs.version }}
nightly-version: ${{ steps.nightly-version.outputs.version }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
with:
fetch-depth: 0
- name: Read Rust version from rust-toolchain.toml
id: rust-version
run: echo "version=$(grep -Po '^channel = "\K[^"]+' rust-toolchain.toml)" >> $GITHUB_OUTPUT
- name: Read nightly version from nightly-toolchain.toml
id: nightly-version
run: echo "version=$(grep -Po '^channel = "\K[^"]+' nightly-toolchain.toml)" >> $GITHUB_OUTPUT
- name: Get crate report
id: changed-crates
uses: ./.github/actions/crates-reporter
- name: Set lint packages
id: set-packages
env:
CHANGED_CRATES_STATUS: ${{ steps.changed-crates.outputs.status }}
CHANGED_CRATES_COUNT: ${{ steps.changed-crates.outputs.crates_count }}
CHANGED_CRATES: ${{ steps.changed-crates.outputs.crates }}
AFFECTED_CRATES: ${{ steps.changed-crates.outputs.affected_crates }}
run: |
if [[ "$CHANGED_CRATES_STATUS" == "skipped" ]]; then
COUNT="1"
FMT_PACKAGES=""
CLIPPY_PACKAGES=""
elif [[ "$CHANGED_CRATES_COUNT" == "0" ]]; then
COUNT="0"
FMT_PACKAGES=""
CLIPPY_PACKAGES=""
else
COUNT="$CHANGED_CRATES_COUNT"
# rustfmt: only directly changed crates — dependants were not modified by this PR
FMT_PACKAGES=$(echo "$CHANGED_CRATES" | jq -r '[.[].name] | map("-p " + .) | join(" ")')
# clippy: affected crates — a change can introduce warnings in dependants
CLIPPY_PACKAGES=$(echo "$AFFECTED_CRATES" | jq -r 'map("-p " + .) | join(" ")')
fi
{
echo "crates-count=$COUNT"
echo "fmt-packages=$FMT_PACKAGES"
echo "clippy-packages=$CLIPPY_PACKAGES"
} >> $GITHUB_OUTPUT
actionlint:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
with:
submodules: recursive
- name: Run actionlint
uses: devops-actions/actionlint@c6744a34774e4e1c1df0ff66bdb07ec7ee480ca0 # 0.1.9
with:
shellcheck_opts: '-e SC2086'
rustfmt:
needs: setup
if: needs.setup.outputs.crates-count != '0'
runs-on: ubuntu-latest
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
steps:
- name: Checkout sources
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
with:
submodules: recursive
- name: Install ${{ needs.setup.outputs.nightly-version }} toolchain and rustfmt
run: |
rustup set profile minimal
rustup install ${{ needs.setup.outputs.nightly-version }}
rustup component add rustfmt --toolchain ${{ needs.setup.outputs.nightly-version }}
- name: Cache [rust]
uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # 2.8.1
with:
cache-targets: true # cache build artifacts
cache-bin: true # cache the ~/.cargo/bin directory
- name: Run rustfmt
env:
FMT_PACKAGES: ${{ needs.setup.outputs.fmt-packages }}
# Override rust-toolchain.toml so rustfmt runs on nightly (required by
# the unstable_features in rustfmt.toml) instead of the workspace MSRV.
RUSTUP_TOOLCHAIN: ${{ needs.setup.outputs.nightly-version }}
run: |
if [[ -z "$FMT_PACKAGES" ]]; then
cargo fmt --all -- --check
else
# shellcheck disable=SC2086
cargo fmt $FMT_PACKAGES -- --check
fi
clippy:
needs: setup
if: needs.setup.outputs.crates-count != '0'
name: "clippy #${{ matrix.platform }} ${{ matrix.rust_version }}"
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
rust_version: ["msrv", "stable", "nightly"]
platform: [windows-latest, ubuntu-latest]
steps:
- name: Checkout sources
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
with:
submodules: recursive
- name: Install ${{ matrix.rust_version }} toolchain and clippy
id: install-toolchain
shell: bash
run: |
VERSION="${{ matrix.rust_version }}"
if [ "$VERSION" = "msrv" ]; then
VERSION="${{ needs.setup.outputs.rust-version }}"
elif [ "$VERSION" = "nightly" ]; then
VERSION="${{ needs.setup.outputs.nightly-version }}"
fi
rustup set profile minimal
rustup install "$VERSION"
rustup component add clippy --toolchain "$VERSION"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Cache [rust]
uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # 2.8.1
with:
cache-targets: true # cache build artifacts
cache-bin: true # cache the ~/.cargo/bin directory
- name: Run clippy on ${{ matrix.platform }} ${{ matrix.rust_version }}
shell: bash
env:
CLIPPY_PACKAGES: ${{ needs.setup.outputs.clippy-packages }}
# Override rust-toolchain.toml so each matrix entry actually runs on
# its chosen toolchain instead of falling back to the workspace MSRV.
RUSTUP_TOOLCHAIN: ${{ steps.install-toolchain.outputs.version }}
run: |
if [[ "${{ matrix.platform }}" == "windows-latest" ]]; then
export AWS_LC_FIPS_SYS_NO_ASM=1
fi
if [[ -z "$CLIPPY_PACKAGES" ]]; then
cargo clippy --workspace --all-targets --all-features --keep-going -- -D warnings
else
# shellcheck disable=SC2086
cargo clippy $CLIPPY_PACKAGES --all-targets --all-features --keep-going -- -D warnings
fi
licensecheck:
needs: setup
if: needs.setup.outputs.crates-count != '0'
runs-on: ubuntu-latest
name: "Presence of licence headers"
steps:
- name: Checkout sources
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
- name: Install licensecheck
run: sudo apt-get install -y licensecheck
- name: Check licenses
# Exclude symbolizer-ffi from the checks (mostly imported code)
run: '! find . \( -name "*.rs" -o -name "*.c" -o -name "*.sh" \) -not -path "./symbolizer-ffi/*" -not -path "./datadog-ipc/plugins/*" -not -path "./datadog-ipc/tarpc/*" -print0 | xargs -0 licensecheck -c ".*" | grep -v "Apache License 2.0"'
license-3rdparty:
needs: setup
if: needs.setup.outputs.crates-count != '0'
runs-on: ubuntu-latest
name: "Valid LICENSE-3rdparty.csv"
steps:
- name: Checkout sources
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
# Keep version in sync with: scripts/update_license_3rdparty.sh (TOOL_VERSION) and scripts/Dockerfile.license (ARG TOOL_VERSION)
- name: Cache dd-rust-license-tool
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # 4.2.2
with:
path: |
~/.cargo/registry/
~/.cargo/git/db/
~/.cargo/bin/dd-rust-license-tool
~/.cargo/.crates.toml
~/.cargo/.crates2.json
key: dd-rust-license-tool-1.0.6-v2
- run: cargo install --list | grep -qF "dd-rust-license-tool v1.0.6" || cargo install dd-rust-license-tool --version "1.0.6" --locked
- name: Generate new LICENSE-3rdparty.csv and check against the previous
run: |
if ! dd-rust-license-tool dump > /tmp/CI.csv 2> /tmp/CI.error; then
echo "ERROR: dd-rust-license-tool dump failed! See error output below:"
cat /tmp/CI.error
exit 1
fi
if ! diff /tmp/CI.csv LICENSE-3rdparty.csv; then
echo "Differences detected in LICENSE-3rdparty.csv."
echo "Please run './scripts/update_license_3rdparty.sh' to update the file and commit the changes."
exit 1
fi
echo "No differences found."
- name: Export generated license file on failure
if: failure()
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
with:
name: LICENSE-3rdparty.csv
path: /tmp/CI.csv
overwrite: true
codeowners-validator:
runs-on: ubuntu-latest
name: "Validate CODEOWNERS"
steps:
- name: Checkout sources
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
- name: GitHub CODEOWNERS Validator
uses: mszostok/codeowners-validator@7f3f5e28c6d7b8dfae5731e54ce2272ca384592f #v0.7.4
# input parameters
with:
github_app_id: ${{ secrets.CODEOWNERS_VALIDATOR_APP_ID }}
github_app_installation_id: ${{ secrets.CODEOWNERS_VALIDATOR_APP_INSTALLATION_ID }}
github_app_private_key: ${{ secrets.CODEOWNERS_VALIDATOR_APP_PRIVATE_KEY }}
# "The list of checks that will be executed. By default, all checks are executed. Possible values: files,owners,duppatterns,syntax"
checks: "files,duppatterns,syntax"
# "The comma-separated list of experimental checks that should be executed. By default, all experimental checks are turned off. Possible values: notowned."
experimental_checks: "notowned"
# The repository path in which CODEOWNERS file should be validated."
repository_path: "."