From 960e48f5d40755f53f70accdcc31d8c727359c5e Mon Sep 17 00:00:00 2001 From: Samuel Burnham <45365069+samuelburnham@users.noreply.github.com> Date: Wed, 24 Apr 2024 19:01:06 -0400 Subject: [PATCH] ci: Check downstream compiles --- .../workflows/check-downstream-compiles.yml | 149 ++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 .github/workflows/check-downstream-compiles.yml diff --git a/.github/workflows/check-downstream-compiles.yml b/.github/workflows/check-downstream-compiles.yml new file mode 100644 index 00000000..f67114f1 --- /dev/null +++ b/.github/workflows/check-downstream-compiles.yml @@ -0,0 +1,149 @@ +name: Check downstream compiles + +on: + push: + branches: + - zkvm + pull_request: + branches: + - zkvm + +jobs: + check-aptos-lc-compiles: + runs-on: ubuntu-latest + steps: + - name: Set up git private repo access + run: | + git config --global url."https://${{ secrets.REPO_TOKEN }}@github.com/".insteadOf ssh://git@github.com + git config --global url."https://${{ secrets.REPO_TOKEN }}@github.com".insteadOf https://github.com + - uses: actions/checkout@v4 + with: + repository: lurk-lab/ci-workflows + - uses: ./.github/actions/ci-env + - uses: ./.github/actions/install-deps + with: + packages: "pkg-config libudev-dev" + - uses: Swatinem/rust-cache@v2 + - uses: dtolnay/rust-toolchain@stable + - uses: taiki-e/install-action@nextest + - name: Set env + run: | + echo "DOWNSTREAM_REPO=$(echo "wormhole-foundation/example-zk-light-clients-internal" | awk -F'/' '{ print $2 }')" | tee -a $GITHUB_ENV + echo "UPSTREAM_REPO=$(echo "lurk-lab/bls12_381" | 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: "wormhole-foundation/${{ env.DOWNSTREAM_REPO }}" + path: ${{ github.workspace }}/${{ env.DOWNSTREAM_REPO }} + token: ${{ secrets.REPO_TOKEN }} + submodules: recursive + - name: Patch Cargo.toml + working-directory: ${{ github.workspace }}/${{ env.DOWNSTREAM_REPO }}/aptos + run: | + # Get each workspace package and relative path of the upstream crate, storing them in a map of former to latter + URL=ssh://git@github.com/${{ github.repository }} + + # 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 most subcrates in the upstream directory, regardless of whether it's a workspace member + SUBCRATES=$(find ../../${{ env.UPSTREAM_REPO }} \( -type d \( -name target -o -name examples -o -name tests -o -name cli \) -prune \) -o -name Cargo.toml -exec grep -A1 --no-group-separator -e "\[package\]" {} +) + SUBCRATES=$(echo "$SUBCRATES" | sed -n 'n;p' | awk -F '-name = "|"' '{split($1, parts, "/"); path=""; for(i=1; i<=length(parts)-1; i++) {path = path parts[i] "/"}; print $2, path}') + 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 + 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 + working-directory: ${{ github.workspace }}/${{ env.DOWNSTREAM_REPO }}/aptos + run: cargo check --workspace --tests --benches --examples + + check-wp1-compiles: + runs-on: ubuntu-latest + steps: + - name: Set up git private repo access + run: | + git config --global url."https://${{ secrets.REPO_TOKEN }}@github.com/".insteadOf ssh://git@github.com + git config --global url."https://${{ secrets.REPO_TOKEN }}@github.com".insteadOf https://github.com + - uses: actions/checkout@v4 + with: + repository: lurk-lab/ci-workflows + - uses: ./.github/actions/ci-env + - uses: ./.github/actions/install-deps + with: + packages: "pkg-config libudev-dev" + - name: Set env + run: | + echo "DOWNSTREAM_REPO=$(echo "wormhole-foundation/wp1" | awk -F'/' '{ print $2 }')" | tee -a $GITHUB_ENV + echo "UPSTREAM_REPO=$(echo "lurk-lab/bls12_381" | 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: "wormhole-foundation/${{ env.DOWNSTREAM_REPO }}" + path: ${{ github.workspace }}/${{ env.DOWNSTREAM_REPO }} + token: ${{ secrets.REPO_TOKEN }} + submodules: recursive + - name: Setup CI + uses: ./wp1/.github/actions/setup + with: + pull_token: ${{ secrets.REPO_TOKEN }} + - 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 + URL=ssh://git@github.com/${{ github.repository }} + + # 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 most subcrates in the upstream directory, regardless of whether it's a workspace member + SUBCRATES=$(find ../../${{ env.UPSTREAM_REPO }} \( -type d \( -name target -o -name examples -o -name tests -o -name cli \) -prune \) -o -name Cargo.toml -exec grep -A1 --no-group-separator -e "\[package\]" {} +) + SUBCRATES=$(echo "$SUBCRATES" | sed -n 'n;p' | awk -F '-name = "|"' '{split($1, parts, "/"); path=""; for(i=1; i<=length(parts)-1; i++) {path = path parts[i] "/"}; print $2, path}') + 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 + 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 + working-directory: ${{ github.workspace }}/${{ env.DOWNSTREAM_REPO }} + run: cargo check --workspace --tests --benches --examples