ci: Run substream checks only on changed substream modules (#200)
* ci: run substream checks only on changed substream modules * ci: move substream package extraction code to a composite action
This commit is contained in:
47
.github/actions/substreams-check/action.yml
vendored
Normal file
47
.github/actions/substreams-check/action.yml
vendored
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
name: 'Substreams Package Names'
|
||||||
|
description: 'Compute package names from changed files'
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
changed-files:
|
||||||
|
description: 'List of changed files from tj-actions/changed-files'
|
||||||
|
required: true
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
package_names:
|
||||||
|
description: 'Space-separated list of package names that were found'
|
||||||
|
value: ${{ steps.extract_package_names.outputs.package_names }}
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: "composite"
|
||||||
|
steps:
|
||||||
|
- name: Get changed directories and package names
|
||||||
|
id: extract_package_names
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
# Convert space-separated list to newline-separated list and process
|
||||||
|
echo '${{ inputs.changed-files }}' | tr ' ' '\n' | grep '^substreams/' | grep -v 'Cargo.lock$' > changed_files.txt
|
||||||
|
|
||||||
|
# Extract unique directory paths
|
||||||
|
CHANGED_DIRS=$(cat changed_files.txt | cut -d'/' -f1-2 | sort -u)
|
||||||
|
|
||||||
|
# Initialize empty array for package names
|
||||||
|
PACKAGE_NAMES=()
|
||||||
|
|
||||||
|
# Loop through directories and find package names
|
||||||
|
while IFS= read -r dir; do
|
||||||
|
if [ -f "$dir/Cargo.toml" ]; then
|
||||||
|
PACKAGE_NAME=$(grep -m1 '^name = ' "$dir/Cargo.toml" | cut -d'"' -f2)
|
||||||
|
if [ -n "$PACKAGE_NAME" ]; then
|
||||||
|
PACKAGE_NAMES+=("$PACKAGE_NAME")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done <<< "$CHANGED_DIRS"
|
||||||
|
|
||||||
|
# Join package names with spaces and store
|
||||||
|
if [ ${#PACKAGE_NAMES[@]} -gt 0 ]; then
|
||||||
|
echo "package_names=${PACKAGE_NAMES[*]}" >> $GITHUB_OUTPUT
|
||||||
|
echo "Found packages: ${PACKAGE_NAMES[*]}"
|
||||||
|
else
|
||||||
|
echo "No valid packages found"
|
||||||
|
echo "package_names=" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
68
.github/workflows/substream.ci.yaml
vendored
68
.github/workflows/substream.ci.yaml
vendored
@@ -1,9 +1,7 @@
|
|||||||
name: Substreams CI
|
name: Substreams CI
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
pull_request:
|
||||||
paths:
|
|
||||||
- "substreams/**"
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
@@ -15,22 +13,50 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Check if any Substreams files changed
|
||||||
|
id: substreams-files-changed
|
||||||
|
uses: tj-actions/changed-files@v35
|
||||||
|
with:
|
||||||
|
files: substreams/**
|
||||||
|
|
||||||
- name: Setup toolchain
|
- name: Setup toolchain
|
||||||
|
if: steps.substreams-files-changed.outputs.any_changed == 'true'
|
||||||
uses: dtolnay/rust-toolchain@v1
|
uses: dtolnay/rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: nightly
|
toolchain: nightly
|
||||||
components: clippy, rustfmt
|
components: clippy, rustfmt
|
||||||
|
|
||||||
- name: Setup Rust Cache
|
- name: Setup Rust Cache
|
||||||
|
if: steps.substreams-files-changed.outputs.any_changed == 'true'
|
||||||
uses: Swatinem/rust-cache@v2
|
uses: Swatinem/rust-cache@v2
|
||||||
with:
|
with:
|
||||||
cache-on-failure: true
|
cache-on-failure: true
|
||||||
|
|
||||||
|
- name: Get changed Substreams package names
|
||||||
|
if: steps.substreams-files-changed.outputs.any_changed == 'true'
|
||||||
|
id: changed_packages
|
||||||
|
uses: ./.github/actions/substreams-check
|
||||||
|
with:
|
||||||
|
changed-files: ${{ steps.substreams-files-changed.outputs.all_changed_files }}
|
||||||
|
|
||||||
- name: Run checks
|
- name: Run checks
|
||||||
|
if: steps.substreams-files-changed.outputs.any_changed == 'true'
|
||||||
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
cd substreams
|
cd substreams
|
||||||
cargo +nightly-2025-03-01 fmt -- --check
|
if [ -n "${{ steps.changed_packages.outputs.package_names }}" ]; then
|
||||||
cargo +nightly-2025-03-01 clippy --all --all-features --all-targets -- -D warnings
|
for package in ${{ steps.changed_packages.outputs.package_names }}; do
|
||||||
|
echo "Running checks for package: $package"
|
||||||
|
cargo +nightly fmt --package "$package" -- --check
|
||||||
|
cargo +nightly clippy --package "$package" -- -D warnings
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo "No packages to check"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Skip check
|
||||||
|
if: steps.substreams-files-changed.outputs.any_changed != 'true'
|
||||||
|
run: echo "No changes to substreams directory, skipping lint check"
|
||||||
|
|
||||||
test:
|
test:
|
||||||
name: Substreams Test
|
name: Substreams Test
|
||||||
@@ -41,19 +67,47 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Check if any Substreams files changed
|
||||||
|
id: substreams-files-changed
|
||||||
|
uses: tj-actions/changed-files@v35
|
||||||
|
with:
|
||||||
|
files: substreams/**
|
||||||
|
|
||||||
- name: Setup toolchain
|
- name: Setup toolchain
|
||||||
|
if: steps.substreams-files-changed.outputs.any_changed == 'true'
|
||||||
uses: dtolnay/rust-toolchain@v1
|
uses: dtolnay/rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: stable
|
toolchain: stable
|
||||||
targets: wasm32-unknown-unknown
|
targets: wasm32-unknown-unknown
|
||||||
|
|
||||||
- name: Setup Rust Cache
|
- name: Setup Rust Cache
|
||||||
|
if: steps.substreams-files-changed.outputs.any_changed == 'true'
|
||||||
uses: Swatinem/rust-cache@v2
|
uses: Swatinem/rust-cache@v2
|
||||||
with:
|
with:
|
||||||
cache-on-failure: true
|
cache-on-failure: true
|
||||||
|
|
||||||
|
- name: Get changed Substreams package names
|
||||||
|
if: steps.substreams-files-changed.outputs.any_changed == 'true'
|
||||||
|
id: changed_packages
|
||||||
|
uses: ./.github/actions/substreams-check
|
||||||
|
with:
|
||||||
|
changed-files: ${{ steps.substreams-files-changed.outputs.all_changed_files }}
|
||||||
|
|
||||||
- name: Run checks
|
- name: Run checks
|
||||||
|
if: steps.substreams-files-changed.outputs.any_changed == 'true'
|
||||||
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
cd substreams
|
cd substreams
|
||||||
cargo build --target wasm32-unknown-unknown --all-targets --all-features
|
if [ -n "${{ steps.changed_packages.outputs.package_names }}" ]; then
|
||||||
cargo test --workspace --all-targets --all-features
|
for package in ${{ steps.changed_packages.outputs.package_names }}; do
|
||||||
|
echo "Running checks for package: $package"
|
||||||
|
cargo build --package "$package" --target wasm32-unknown-unknown
|
||||||
|
cargo test --package "$package"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo "No packages to check"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Skip check
|
||||||
|
if: steps.substreams-files-changed.outputs.any_changed != 'true'
|
||||||
|
run: echo "No changes to substreams directory, skipping test check"
|
||||||
|
|||||||
Reference in New Issue
Block a user