Skip to content

feat: implement e2e-tests crate and kv-store example #181

feat: implement e2e-tests crate and kv-store example

feat: implement e2e-tests crate and kv-store example #181

Workflow file for this run

name: Build and Commit node-ui
on:
workflow_dispatch:
push:
branches:
- master # Explicitly set to master
paths:
- 'node-ui/**'
pull_request:
types:
- closed
jobs:
build_node_ui:
if: github.event.pull_request.merged == true || github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
env:
HUSKY: 0 # Disable Husky globally for this job
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all branches and tags
# Check if there are changes in the node-ui folder (excluding build)
- name: Check for changes in node-ui (excluding build folder)
id: check_changes
run: |
echo "CHANGES_DETECTED=false" >> $GITHUB_ENV
git fetch --unshallow || true
# For workflow_dispatch, consider all files as changed
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "Workflow manually triggered. Considering all files as changed."
echo "CHANGES_DETECTED=true" >> $GITHUB_ENV
else
# Check for changes in the node-ui folder (excluding the build directory)
changes=$(git diff --name-only HEAD~1 HEAD -- 'node-ui' ':!node-ui/build')
if [ -n "$changes" ]; then
echo "Changes detected in node-ui."
echo "CHANGES_DETECTED=true" >> $GITHUB_ENV
else
echo "No changes in node-ui (excluding build folder)."
fi
fi
# Conditional steps, executed only if changes were detected
- name: Set up Node.js
if: env.CHANGES_DETECTED == 'true'
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Install pnpm
if: env.CHANGES_DETECTED == 'true'
run: npm install -g pnpm
- name: Install frontend dependencies with pnpm
if: env.CHANGES_DETECTED == 'true'
run: pnpm install --prefix ./node-ui
# Set up Git credentials for committing
- name: Set up Git user
if: env.CHANGES_DETECTED == 'true'
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
- name: Build node ui
if: env.CHANGES_DETECTED == 'true'
run: |
cd $GITHUB_WORKSPACE/node-ui
pnpm build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Commit and push changes
if: env.CHANGES_DETECTED == 'true'
run: |
cd $GITHUB_WORKSPACE
git add ./node-ui/build
git commit -m "Automated build of node-ui" || echo "No changes to commit"
# Retry loop
max_attempts=5
attempt=1
while [ $attempt -le $max_attempts ]; do
echo "Attempt $attempt to push changes..."
git fetch origin master
git rebase origin/master
if git push origin HEAD:master; then
echo "Successfully pushed changes."
break
else
echo "Push failed. Retrying in 5 seconds..."
sleep 5
attempt=$((attempt + 1))
fi
done
if [ $attempt -gt $max_attempts ]; then
echo "Failed to push changes after $max_attempts attempts."
exit 1
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Clone target repository
if: env.CHANGES_DETECTED == 'true'
run: |
cd $GITHUB_WORKSPACE
git clone https://github.com/calimero-network/admin-dashboard.git
- name: Copy entire node-ui to target repo
if: env.CHANGES_DETECTED == 'true'
run: |
cp -r $GITHUB_WORKSPACE/node-ui/src/* $GITHUB_WORKSPACE/admin-dashboard/src/
- name: Push changes to admin-dashboard repo
if: env.CHANGES_DETECTED == 'true'
run: |
cd $GITHUB_WORKSPACE/admin-dashboard
git add -A
git commit -m "Automated push of node-ui changes (excluding build)" || echo "No changes to commit"
git push https://${{ secrets.PUSH_TOKEN }}@github.com/calimero-network/admin-dashboard.git master
env:
PUSH_TOKEN: ${{ secrets.PUSH_TOKEN }}