From 17adb03913dd84d9cd423c8ce13daf08eeff67bf Mon Sep 17 00:00:00 2001 From: Samuel Burnham <45365069+samuelburnham@users.noreply.github.com> Date: Tue, 19 Mar 2024 15:11:26 -0400 Subject: [PATCH] Genericize `check-lurk-compiles.yml` --- .../workflows/check-downstream-compiles.yml | 88 +++++++++++++++++++ .github/workflows/check-lurk-compiles.yml | 54 ------------ 2 files changed, 88 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/check-downstream-compiles.yml delete mode 100644 .github/workflows/check-lurk-compiles.yml diff --git a/.github/workflows/check-downstream-compiles.yml b/.github/workflows/check-downstream-compiles.yml new file mode 100644 index 0000000..0294460 --- /dev/null +++ b/.github/workflows/check-downstream-compiles.yml @@ -0,0 +1,88 @@ +# Patches a dependent crate with any upstream changes and checks that the former compiles +# +# Example: +# When run in `arecibo`, this workflow will check out `lurk-rs`, patch it with the local `arecibo` path, +# and check whether `lurk-rs` still builds. +# +# Only supports patching Git dependencies for now, crates.io patches are a TODO +# This workflow is not intended to be a required status check, but to surface breaking changes to +# downstream repos for further review on e.g. `pull_request`. +name: Check downstream dependency compiles + +on: + workflow_call: + inputs: + runner: + required: false + default: 'ubuntu-latest' + type: string + # Downstream repo to check + repository: + required: false + default: 'lurk-lab/lurk-rs' + type: string + # List of prerequisite Ubuntu packages, separated by whitespace + packages: + required: false + type: string + +jobs: + check-lurk-compiles: + if: github.event_name == 'pull_request' + runs-on: ${{ inputs.runner }} + steps: + - uses: actions/checkout@v4 + with: + repository: lurk-lab/ci-workflows + - uses: ./.github/actions/ci-env + - uses: ./.github/actions/install-deps + if: inputs.packages != '' + with: + packages: "${{ inputs.packages }}" + - uses: actions/checkout@v4 + - name: Set env + run: | + echo "REPO_NAME=$(echo ${{ inputs.repository }} | awk -F'/' '{ print $2 }')" | tee -a $GITHUB_ENV + - uses: actions/checkout@v4 + with: + repository: ${{ inputs.repository }} + path: ./${{ env.REPO_NAME }} + submodules: recursive + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + - name: Patch Cargo.toml + working-directory: ${{ github.workspace }}/${{ env.REPO_NAME }} + run: | + URL=https://github.com/${{ github.repository }} + + # Assumes at least one dependency in the current workspace is used by the downstream crate + printf "\n[patch.'$URL']\n" >> Cargo.toml + + # Get a list of all dependencies used by the downstream crate workspace + DEPENDENCIES=$(grep -rsh "git = \"$URL\"" --include="Cargo.toml" .) + #echo "$DEPENDENCIES" + + # Extract the dependency names and check for package renames + DEP_NAMES=$(echo "$DEPENDENCIES" | awk '/package =/{for (i=1; i<=NF; i++) if ($i == "package") {name=$(i+2); print substr(name, 2, length(name)-2);} found=1} !/package =/{print $1}' | sort -u) + echo "$DEP_NAMES" + + # Get each workspace member of the upstream crate if they exist + WORKSPACE_PATHS=$(sed -n '/members = \[/,/]/ { /members = \[/d; /]/d; s/^\s*"\([^"]*\)",\?/\1/p }' ../Cargo.toml) + echo "$WORKSPACE_PATHS" + + # Write the Git patch for each dependency used downstream + for crate in $DEP_NAMES; do + result=$(echo "$WORKSPACE_PATHS" | grep -ohs "\w*$crate\w*" | cat) + if [[ -n $result ]]; then + crate_path=$result + else + crate_path="" + fi + echo "Crate $crate has path = $crate_path" + echo "$crate = { path = \"../workspace-test/$crate_path\" }" >> Cargo.toml + echo "Patched" + done + - name: Check downstream types don't break spectacularly + working-directory: ${{ github.workspace }}/${{ env.REPO_NAME }} + run: cargo check --workspace --tests --benches --examples + diff --git a/.github/workflows/check-lurk-compiles.yml b/.github/workflows/check-lurk-compiles.yml deleted file mode 100644 index 0b5f88f..0000000 --- a/.github/workflows/check-lurk-compiles.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: Check upstream `lurk-rs` compiles - -on: - workflow_call: - inputs: - runner: - required: false - default: 'ubuntu-latest' - type: string - # List of prerequisite Ubuntu packages, separated by whitespace - packages: - required: false - type: string - -jobs: - check-lurk-compiles: - if: github.event_name == 'pull_request' - runs-on: ${{ inputs.runner }} - steps: - - uses: actions/checkout@v4 - with: - repository: lurk-lab/ci-workflows - - uses: ./.github/actions/ci-env - - uses: ./.github/actions/install-deps - if: inputs.packages != '' - with: - packages: "${{ inputs.packages }}" - - uses: actions/checkout@v4 - - uses: actions/checkout@v4 - with: - repository: lurk-lab/lurk-rs - path: ./lurk-rs - submodules: recursive - - uses: dtolnay/rust-toolchain@stable - - uses: Swatinem/rust-cache@v2 - - name: Patch Cargo.toml - working-directory: ${{ github.workspace }}/lurk-rs - run: | - URL=https://github.com/${{ github.repository }} - # the dependency we want to patch is usually the same as the package, but - # we e.g. want to override dependency 'nova' with an 'arecibo' package - DEPENDENCY=$(grep "git = \"$URL\"" Cargo.toml | awk '{ print $1 }') - PACKAGE=$(grep "git = \"$URL\"" Cargo.toml | grep -oP 'package = "\K[^"]*'| cat) - echo "[patch.'$URL']" >> Cargo.toml - if [ ! -z "$PACKAGE" ]; - then - echo "$DEPENDENCY = { path='../', package='$PACKAGE' }" >> Cargo.toml - else - echo "$DEPENDENCY = { path='../' }" >> Cargo.toml - fi - - name: Check Lurk-rs types don't break spectacularly - working-directory: ${{ github.workspace }}/lurk-rs - run: cargo check --workspace --tests --benches --examples -