Skip to content

chore: Update for Ninja Examples #1

chore: Update for Ninja Examples

chore: Update for Ninja Examples #1

Workflow file for this run

name: Test ICP Ninja Examples
on:
pull_request:
branches:
- master
concurrency:
group: ninja-pr-checks-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check-ninja-example-changes:
name: Filter projects
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
has_examples: ${{ steps.set-matrix.outputs.has_examples }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Fetch all branches
run: git fetch origin
- name: Set matrix based on changes
id: set-matrix
run: |
changed_files=$(git diff --name-only origin/master ${{ github.sha }})
echo "Changed files: $changed_files"
examples=()
declare -A example_paths=(
["My Crypto Blog (Frontend)"]="hosting/my_crypto_blog"
["React (Frontend)"]="hosting/react"
["Motoko backend (Motoko)"]="motoko/backend_only"
["Daily Planner (Motoko)"]="motoko/daily_planner"
["EVM Block Explorer (Motoko)"]="motoko/evm_block_explorer"
["FileVault (Motoko)"]="motoko/filevault"
["Flying Ninja (Motoko)"]="motoko/flying_ninja"
["Hello World (Motoko)"]="motoko/hello_world"
["LLM Chatbot (Motoko)"]="motoko/llm_chatbot"
["Tokenmania (Motoko)"]="motoko/tokenmania"
["Who Am I (Motoko)"]="motoko/who_am_i"
["Rust backend (Rust)"]="rust/backend_only"
["Daily Planner (Rust)"]="rust/daily_planner"
["EVM Block Explorer (Rust)"]="rust/evm_block_explorer"
["Flying Ninja (Rust)"]="rust/flying_ninja"
["Hello World (Rust)"]="rust/hello_world"
["LLM Chatbot (Rust)"]="rust/llm_chatbot"
["Tokenmania (Rust)"]="rust/tokenmania"
["Who Am I (Rust)"]="rust/who_am_i"
)
for name in "${!example_paths[@]}"; do
path=${example_paths[$name]}
echo "Checking path: $path"
if echo "$changed_files" | grep -q "^$path/"; then
examples+=("{\"name\": \"$name\", \"path\": \"$path\"}")
echo "Added example: $name with path $path"
fi
done
if [ ${#examples[@]} -eq 0 ]; then
echo "No examples detected. Setting has_examples to false."
echo "has_examples=false" >> $GITHUB_OUTPUT
echo "matrix={\"example\": []}" >> $GITHUB_OUTPUT
else
matrix="{\"example\": [$(IFS=, ; echo "${examples[*]}")]}"
echo "Matrix generated: $matrix"
echo "has_examples=true" >> $GITHUB_OUTPUT
echo "matrix=$matrix" >> $GITHUB_OUTPUT
fi
build-examples:
name: Build
needs: check-ninja-example-changes
if: needs.check-ninja-example-changes.outputs.has_examples == 'true'
runs-on: ubuntu-22.04
container: ghcr.io/dfinity/icp-dev-env-slim:17
strategy:
matrix: ${{ fromJson(needs.check-ninja-example-changes.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dfx # This is a temporary workaround. Dfx is already installed in the container, but it does not start in the next step if we don't install it here again.
uses: dfinity/setup-dfx@main
- name: Start dfx
run: dfx start --background
- name: Build project
working-directory: ${{ matrix.example.path }}
run: dfx deploy