Skip to content

Commit

Permalink
Switch to composite action
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelburnham committed Apr 25, 2024
1 parent 67cb7ba commit bf6a65f
Showing 1 changed file with 40 additions and 108 deletions.
148 changes: 40 additions & 108 deletions .github/workflows/check-downstream-compiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ jobs:
- uses: actions/checkout@v4
with:
repository: lurk-lab/ci-workflows
- uses: ./.github/actions/ci-env
- uses: ./.github/actions/install-deps
ref: check-downstream-compiles
path: ${{ github.workspace }}/ci-workflows
- uses: ./ci-workflows/.github/actions/ci-env
- uses: ./ci-workflows/.github/actions/install-deps
with:
packages: "pkg-config libudev-dev"
- uses: Swatinem/rust-cache@v2
Expand All @@ -32,120 +34,50 @@ jobs:
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 }}
ref: zkvm
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=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" | 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 = <upstream_url>` 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 }}
ref: zkvm
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
- uses: ./ci-workflows/.github/actions/check-downstream-compiles
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=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" | 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 = <upstream_url>` 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"
upstream-path: "${{ env.UPSTREAM_REPO }}"
downstream-path: "${{ env.DOWNSTREAM_REPO }}/aptos"

# 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
# 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 }}
# ref: zkvm
# 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 }}

0 comments on commit bf6a65f

Please sign in to comment.