From 7fa958fd3fd068b85213d104de178300f713f73f 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 1/7] Genericize `check-lurk-compiles.yml` --- .../workflows/check-downstream-compiles.yml | 92 +++++++++++++++++++ .github/workflows/check-lurk-compiles.yml | 54 ----------- 2 files changed, 92 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..79fa367 --- /dev/null +++ b/.github/workflows/check-downstream-compiles.yml @@ -0,0 +1,92 @@ +# 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 }}" + - name: Set env + run: | + echo "DOWNSTREAM_REPO=$(echo ${{ inputs.repository }} | awk -F'/' '{ print $2 }')" | tee -a $GITHUB_ENV + echo "UPSTREAM_REPO=$(echo ${{ github.repository }} | awk -F'/' '{ print $2 }')" | tee -a $GITHUB_ENV + - uses: actions/checkout@v4 + with: + path: ${{ github.workspace }}/${{ env.UPSTREAM_REPO }} + submodules: recursive + - uses: actions/checkout@v4 + with: + repository: ${{ inputs.repository }} + path: ${{ github.workspace }}/${{ env.DOWNSTREAM_REPO }} + submodules: recursive + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + - name: Patch Cargo.toml + working-directory: ${{ github.workspace }}/${{ env.DOWNSTREAM_REPO }} + 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 }' ../${{ env.UPSTREAM_REPO }}/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 = \"../${{ env.UPSTREAM_REPO }}/$crate_path\" }" >> Cargo.toml + echo "Patched" + done + - name: Check downstream types don't break spectacularly + working-directory: ${{ github.workspace }}/${{ env.DOWNSTREAM_REPO }} + 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 - From 21ac0f1d7e3433aab3872f9d74efeeb4ebaf5a74 Mon Sep 17 00:00:00 2001 From: Samuel Burnham <45365069+samuelburnham@users.noreply.github.com> Date: Tue, 19 Mar 2024 16:37:55 -0400 Subject: [PATCH 2/7] Add ssh-key option --- .../workflows/check-downstream-compiles.yml | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/.github/workflows/check-downstream-compiles.yml b/.github/workflows/check-downstream-compiles.yml index 79fa367..f610228 100644 --- a/.github/workflows/check-downstream-compiles.yml +++ b/.github/workflows/check-downstream-compiles.yml @@ -11,6 +11,10 @@ name: Check downstream dependency compiles on: workflow_call: + secrets: + SSH_PRIVATE_KEY: + required: false + description: '' inputs: runner: required: false @@ -21,13 +25,18 @@ on: required: false default: 'lurk-lab/lurk-rs' type: string + # Used to checkout private repos + ssh-key: + required: false + default: false + type: boolean # List of prerequisite Ubuntu packages, separated by whitespace packages: required: false type: string jobs: - check-lurk-compiles: + check-downstream-compiles: if: github.event_name == 'pull_request' runs-on: ${{ inputs.runner }} steps: @@ -39,6 +48,10 @@ jobs: if: inputs.packages != '' with: packages: "${{ inputs.packages }}" + - uses: webfactory/ssh-agent@v0.9.0 + if: inputs.ssh-key + with: + ssh-private-key: "${{ secrets.SSH_PRIVATE_KEY }}" - name: Set env run: | echo "DOWNSTREAM_REPO=$(echo ${{ inputs.repository }} | awk -F'/' '{ print $2 }')" | tee -a $GITHUB_ENV @@ -48,10 +61,18 @@ jobs: path: ${{ github.workspace }}/${{ env.UPSTREAM_REPO }} submodules: recursive - uses: actions/checkout@v4 + if: inputs.ssh-key != true + with: + repository: ${{ inputs.repository }} + path: ${{ github.workspace }}/${{ env.DOWNSTREAM_REPO }} + submodules: recursive + - uses: actions/checkout@v4 + if: inputs.ssh-key with: repository: ${{ inputs.repository }} path: ${{ github.workspace }}/${{ env.DOWNSTREAM_REPO }} submodules: recursive + ssh-key: "${{ secrets.SSH_PRIVATE_KEY }}" - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - name: Patch Cargo.toml @@ -60,19 +81,16 @@ jobs: 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 + printf "\n[patch.'$URL']\n" | tee -a Cargo.toml - # Get a list of all dependencies used by the downstream crate workspace + # Get a list of all upstream 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 }' ../${{ env.UPSTREAM_REPO }}/Cargo.toml) - echo "$WORKSPACE_PATHS" # Write the Git patch for each dependency used downstream for crate in $DEP_NAMES; do @@ -82,9 +100,7 @@ jobs: else crate_path="" fi - echo "Crate $crate has path = $crate_path" - echo "$crate = { path = \"../${{ env.UPSTREAM_REPO }}/$crate_path\" }" >> Cargo.toml - echo "Patched" + echo "$crate = { path = \"../${{ env.UPSTREAM_REPO }}/$crate_path\" }" | tee -a Cargo.toml done - name: Check downstream types don't break spectacularly working-directory: ${{ github.workspace }}/${{ env.DOWNSTREAM_REPO }} From 12ad5917970d64c9e588486c6742479385dc73eb Mon Sep 17 00:00:00 2001 From: Samuel Burnham <45365069+samuelburnham@users.noreply.github.com> Date: Wed, 20 Mar 2024 13:24:31 -0400 Subject: [PATCH 3/7] Try using a PAT --- .github/workflows/check-downstream-compiles.yml | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/.github/workflows/check-downstream-compiles.yml b/.github/workflows/check-downstream-compiles.yml index f610228..db89fcc 100644 --- a/.github/workflows/check-downstream-compiles.yml +++ b/.github/workflows/check-downstream-compiles.yml @@ -12,7 +12,7 @@ name: Check downstream dependency compiles on: workflow_call: secrets: - SSH_PRIVATE_KEY: + REPO_TOKEN: required: false description: '' inputs: @@ -26,7 +26,7 @@ on: default: 'lurk-lab/lurk-rs' type: string # Used to checkout private repos - ssh-key: + token: required: false default: false type: boolean @@ -48,10 +48,6 @@ jobs: if: inputs.packages != '' with: packages: "${{ inputs.packages }}" - - uses: webfactory/ssh-agent@v0.9.0 - if: inputs.ssh-key - with: - ssh-private-key: "${{ secrets.SSH_PRIVATE_KEY }}" - name: Set env run: | echo "DOWNSTREAM_REPO=$(echo ${{ inputs.repository }} | awk -F'/' '{ print $2 }')" | tee -a $GITHUB_ENV @@ -61,18 +57,18 @@ jobs: path: ${{ github.workspace }}/${{ env.UPSTREAM_REPO }} submodules: recursive - uses: actions/checkout@v4 - if: inputs.ssh-key != true + if: inputs.token != true with: repository: ${{ inputs.repository }} path: ${{ github.workspace }}/${{ env.DOWNSTREAM_REPO }} submodules: recursive - uses: actions/checkout@v4 - if: inputs.ssh-key + if: inputs.token with: repository: ${{ inputs.repository }} path: ${{ github.workspace }}/${{ env.DOWNSTREAM_REPO }} submodules: recursive - ssh-key: "${{ secrets.SSH_PRIVATE_KEY }}" + token: "${{ secrets.REPO_TOKEN }}" - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - name: Patch Cargo.toml @@ -84,9 +80,10 @@ jobs: printf "\n[patch.'$URL']\n" | tee -a Cargo.toml # Get a list of all upstream dependencies used by the downstream crate workspace + # This is done by checking for each instance of `git = ` in any of the downstream `Cargo.toml` files DEPENDENCIES=$(grep -rsh "git = \"$URL\"" --include="Cargo.toml" .) - # Extract the dependency names and check for package renames + # Extract the dependency names and check for package renames, removing duplicates 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) # Get each workspace member of the upstream crate if they exist From b07896fe7c6ec326063f4540c11f9f6a9691929d Mon Sep 17 00:00:00 2001 From: Samuel Burnham <45365069+samuelburnham@users.noreply.github.com> Date: Wed, 20 Mar 2024 13:39:10 -0400 Subject: [PATCH 4/7] Add an SSH patch option --- .../workflows/check-downstream-compiles.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-downstream-compiles.yml b/.github/workflows/check-downstream-compiles.yml index db89fcc..f7508df 100644 --- a/.github/workflows/check-downstream-compiles.yml +++ b/.github/workflows/check-downstream-compiles.yml @@ -34,6 +34,11 @@ on: packages: required: false type: string + # Patch with SSH instead of HTTPS + patch-ssh: + required: false + default: false + type: boolean jobs: check-downstream-compiles: @@ -74,7 +79,11 @@ jobs: - name: Patch Cargo.toml working-directory: ${{ github.workspace }}/${{ env.DOWNSTREAM_REPO }} run: | - URL=https://github.com/${{ github.repository }} + if [[ "${{ inputs.patch-ssh }}" == "true" ]]; then + URL=ssh://git@github.com/${{ github.repository }} + else + URL=https://github.com/${{ github.repository }} + fi # Assumes at least one dependency in the current workspace is used by the downstream crate printf "\n[patch.'$URL']\n" | tee -a Cargo.toml @@ -82,16 +91,23 @@ jobs: # Get a list of all upstream dependencies used by the downstream crate workspace # This is done by checking for each instance of `git = ` in any of the downstream `Cargo.toml` files DEPENDENCIES=$(grep -rsh "git = \"$URL\"" --include="Cargo.toml" .) + echo "DEPENDENCIES" + echo $DEPENDENCIES # Extract the dependency names and check for package renames, removing duplicates 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" + 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 }' ../${{ env.UPSTREAM_REPO }}/Cargo.toml) + echo "WORKSPACE_PATHS" + 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) + echo "Result for crate $crate: $result" if [[ -n $result ]]; then crate_path=$result else From 8a33b57ef1ac7055d6778a0c421b41e045c17538 Mon Sep 17 00:00:00 2001 From: Samuel Burnham <45365069+samuelburnham@users.noreply.github.com> Date: Wed, 20 Mar 2024 14:36:10 -0400 Subject: [PATCH 5/7] Support workspace packages with different names vs. paths --- .../workflows/check-downstream-compiles.yml | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/.github/workflows/check-downstream-compiles.yml b/.github/workflows/check-downstream-compiles.yml index f7508df..89f5c8e 100644 --- a/.github/workflows/check-downstream-compiles.yml +++ b/.github/workflows/check-downstream-compiles.yml @@ -12,7 +12,7 @@ name: Check downstream dependency compiles on: workflow_call: secrets: - REPO_TOKEN: + PRIVATE_PULL_TOKEN: required: false description: '' inputs: @@ -73,12 +73,13 @@ jobs: repository: ${{ inputs.repository }} path: ${{ github.workspace }}/${{ env.DOWNSTREAM_REPO }} submodules: recursive - token: "${{ secrets.REPO_TOKEN }}" + token: "${{ secrets.PRIVATE_PULL_TOKEN }}" - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - name: Patch Cargo.toml working-directory: ${{ github.workspace }}/${{ env.DOWNSTREAM_REPO }} run: | + # Get each workspace package and relative path of the upstream crate, storing them in a map of former to latter if [[ "${{ inputs.patch-ssh }}" == "true" ]]; then URL=ssh://git@github.com/${{ github.repository }} else @@ -91,28 +92,27 @@ jobs: # Get a list of all upstream dependencies used by the downstream crate workspace # This is done by checking for each instance of `git = ` in any of the downstream `Cargo.toml` files DEPENDENCIES=$(grep -rsh "git = \"$URL\"" --include="Cargo.toml" .) - echo "DEPENDENCIES" - echo $DEPENDENCIES # Extract the dependency names and check for package renames, removing duplicates 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" - 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 }' ../${{ env.UPSTREAM_REPO }}/Cargo.toml) - echo "WORKSPACE_PATHS" - echo $WORKSPACE_PATHS + shopt -s nullglob + # Collect the `package path` pairs for each subcrate in the directory, regardless of whether it's a workspace member + SUBCRATES=$(grep -r -A1 --no-group-separator "\[package\]" --exclude-dir='.' --exclude-dir='target' ../${{ env.UPSTREAM_REPO }}/*/Cargo.toml | sed -n 'n;p' | awk -F'/' '{split($NF,a,"\""); print a[2], $(NF-1)}') + shopt -u nullglob - # Write the Git patch for each dependency used downstream + # Store the subcrates in associative array for retrieval when patching `Cargo.toml` + declare -A subcrates + while IFS= read -r line; do + pair=($line) + subcrates[${pair[0]}]=${pair[1]} + done <<< "$SUBCRATES" + + # Write Git patches for each dependency used downstream + # Note: The top-level workspace package if used will be included in `DEP_NAMES`, but not in `subcrates` + # Therefore, below will append an empty string to the top-level path and patch it correctly for crate in $DEP_NAMES; do - result=$(echo "$WORKSPACE_PATHS" | grep -ohs "\w*$crate\w*" | cat) - echo "Result for crate $crate: $result" - if [[ -n $result ]]; then - crate_path=$result - else - crate_path="" - fi + crate_path="${subcrates[$crate]}" echo "$crate = { path = \"../${{ env.UPSTREAM_REPO }}/$crate_path\" }" | tee -a Cargo.toml done - name: Check downstream types don't break spectacularly From b72c68399bdfd2ae8bade104dd08c24a5ac6c8a5 Mon Sep 17 00:00:00 2001 From: Samuel Burnham <45365069+samuelburnham@users.noreply.github.com> Date: Wed, 24 Apr 2024 20:53:38 -0400 Subject: [PATCH 6/7] Switch to composite action --- .../check-downstream-compiles/action.yml | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/actions/check-downstream-compiles/action.yml diff --git a/.github/actions/check-downstream-compiles/action.yml b/.github/actions/check-downstream-compiles/action.yml new file mode 100644 index 0000000..dcc9045 --- /dev/null +++ b/.github/actions/check-downstream-compiles/action.yml @@ -0,0 +1,67 @@ +# Default use case: run on `pull_request` and check the changes don't break a downstream crate +name: Check downstream compiles + +description: Patch dependent crate with upstream changes and check it builds + +inputs: + # Path to the upstream repo relative to `${{ github.workspace }}` + upstream-path: + description: 'path to upstream repo' + required: true + type: string + # Path to the downstream repo relative to `${{ github.workspace }}` + downstream-path: + description: 'Path to upstream repo' + required: true + type: string + # Patch with an HTTPS or SSH URL. Defaults to HTTPS + patch-ssh: + description: 'Patch with HTTPS or SSH' + required: false + default: false + type: boolean + +runs: + using: "composite" + steps: + - name: Patch Cargo.toml + shell: bash + working-directory: ${{ github.workspace }}/${{ inputs.downstream-path }} + run: | + if [[ "${{ inputs.patch-ssh }}" == "true" ]]; then + URL=ssh://git@github.com/${{ github.repository }} + else + URL=https://github.com/${{ github.repository }} + fi + + # Assumes at least one dependency in the current workspace is used by the downstream crate + printf "\n[patch.'$URL']\n" | tee -a Cargo.toml + + # Get a list of all upstream dependencies used by the downstream crate workspace + # This is done by checking for each instance of `git = ` in any of the downstream `Cargo.toml` files + DEPENDENCIES=$(grep -rsh "git = \"$URL" --include="Cargo.toml" .) + + # Extract the dependency names and check for package renames, removing duplicates + 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) + + shopt -s nullglob + # Collect the `(path, package)` pairs for most subcrates in the upstream directory, regardless of whether they are workspace members + SUBCRATES=$(find ${{ github.workspace }}/${{ inputs.upstream-path }} \( -type d \( -name target -o -name examples -o -name tests -o -name cli \) -prune \) -o -name Cargo.toml -exec awk '/^\[package\]/{flag=1} flag && /name\s*=/ {gsub(/"/, "", $3); package=$3} /^\[[^p]/ && flag {exit} END{if(package != "") print FILENAME, package}' {} \; | sed 's|/Cargo.toml | |g') + shopt -u nullglob + + # Store the subcrates in associative array for retrieval when patching `Cargo.toml` + declare -A subcrates + while IFS= read -r line; do + pair=($line) + subcrates[${pair[1]}]=${pair[0]} + done <<< "$SUBCRATES" + + # Write Git patches for each dependency used downstream + for crate in $DEP_NAMES; do + crate_path="${subcrates[$crate]}" + echo "$crate = { path = \"$crate_path\" }" | tee -a Cargo.toml + done + - name: Check downstream types don't break spectacularly + shell: bash + working-directory: ${{ github.workspace }}/${{ inputs.downstream-path }} + run: cargo check --workspace --tests --benches --examples From 0760948a1b31d970325503fd345b249d9232d472 Mon Sep 17 00:00:00 2001 From: Samuel Burnham <45365069+samuelburnham@users.noreply.github.com> Date: Thu, 25 Apr 2024 10:08:41 -0400 Subject: [PATCH 7/7] Prep for merge --- .../workflows/check-downstream-compiles.yml | 121 ------------------ .github/workflows/check-lurk-compiles.yml | 53 ++++++++ 2 files changed, 53 insertions(+), 121 deletions(-) delete mode 100644 .github/workflows/check-downstream-compiles.yml create mode 100644 .github/workflows/check-lurk-compiles.yml diff --git a/.github/workflows/check-downstream-compiles.yml b/.github/workflows/check-downstream-compiles.yml deleted file mode 100644 index 89f5c8e..0000000 --- a/.github/workflows/check-downstream-compiles.yml +++ /dev/null @@ -1,121 +0,0 @@ -# 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: - secrets: - PRIVATE_PULL_TOKEN: - required: false - description: '' - inputs: - runner: - required: false - default: 'ubuntu-latest' - type: string - # Downstream repo to check - repository: - required: false - default: 'lurk-lab/lurk-rs' - type: string - # Used to checkout private repos - token: - required: false - default: false - type: boolean - # List of prerequisite Ubuntu packages, separated by whitespace - packages: - required: false - type: string - # Patch with SSH instead of HTTPS - patch-ssh: - required: false - default: false - type: boolean - -jobs: - check-downstream-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 }}" - - name: Set env - run: | - echo "DOWNSTREAM_REPO=$(echo ${{ inputs.repository }} | awk -F'/' '{ print $2 }')" | tee -a $GITHUB_ENV - echo "UPSTREAM_REPO=$(echo ${{ github.repository }} | awk -F'/' '{ print $2 }')" | tee -a $GITHUB_ENV - - uses: actions/checkout@v4 - with: - path: ${{ github.workspace }}/${{ env.UPSTREAM_REPO }} - submodules: recursive - - uses: actions/checkout@v4 - if: inputs.token != true - with: - repository: ${{ inputs.repository }} - path: ${{ github.workspace }}/${{ env.DOWNSTREAM_REPO }} - submodules: recursive - - uses: actions/checkout@v4 - if: inputs.token - with: - repository: ${{ inputs.repository }} - path: ${{ github.workspace }}/${{ env.DOWNSTREAM_REPO }} - submodules: recursive - token: "${{ secrets.PRIVATE_PULL_TOKEN }}" - - uses: dtolnay/rust-toolchain@stable - - uses: Swatinem/rust-cache@v2 - - name: Patch Cargo.toml - working-directory: ${{ github.workspace }}/${{ env.DOWNSTREAM_REPO }} - run: | - # Get each workspace package and relative path of the upstream crate, storing them in a map of former to latter - if [[ "${{ inputs.patch-ssh }}" == "true" ]]; then - URL=ssh://git@github.com/${{ github.repository }} - else - URL=https://github.com/${{ github.repository }} - fi - - # Assumes at least one dependency in the current workspace is used by the downstream crate - printf "\n[patch.'$URL']\n" | tee -a Cargo.toml - - # Get a list of all upstream dependencies used by the downstream crate workspace - # This is done by checking for each instance of `git = ` in any of the downstream `Cargo.toml` files - DEPENDENCIES=$(grep -rsh "git = \"$URL\"" --include="Cargo.toml" .) - - # Extract the dependency names and check for package renames, removing duplicates - 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) - - shopt -s nullglob - # Collect the `package path` pairs for each subcrate in the directory, regardless of whether it's a workspace member - SUBCRATES=$(grep -r -A1 --no-group-separator "\[package\]" --exclude-dir='.' --exclude-dir='target' ../${{ env.UPSTREAM_REPO }}/*/Cargo.toml | sed -n 'n;p' | awk -F'/' '{split($NF,a,"\""); print a[2], $(NF-1)}') - shopt -u nullglob - - # Store the subcrates in associative array for retrieval when patching `Cargo.toml` - declare -A subcrates - while IFS= read -r line; do - pair=($line) - subcrates[${pair[0]}]=${pair[1]} - done <<< "$SUBCRATES" - - # Write Git patches for each dependency used downstream - # Note: The top-level workspace package if used will be included in `DEP_NAMES`, but not in `subcrates` - # Therefore, below will append an empty string to the top-level path and patch it correctly - for crate in $DEP_NAMES; do - crate_path="${subcrates[$crate]}" - echo "$crate = { path = \"../${{ env.UPSTREAM_REPO }}/$crate_path\" }" | tee -a Cargo.toml - done - - name: Check downstream types don't break spectacularly - working-directory: ${{ github.workspace }}/${{ env.DOWNSTREAM_REPO }} - run: cargo check --workspace --tests --benches --examples - diff --git a/.github/workflows/check-lurk-compiles.yml b/.github/workflows/check-lurk-compiles.yml new file mode 100644 index 0000000..5d48993 --- /dev/null +++ b/.github/workflows/check-lurk-compiles.yml @@ -0,0 +1,53 @@ +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