Skip to content

Create frontend plugin test-plugin-22 #2

Create frontend plugin test-plugin-22

Create frontend plugin test-plugin-22 #2

name: Playwright tests
on:
pull_request:
branches: [main]
jobs:
changes:
name: Scan for changes
runs-on: ubuntu-latest
outputs:
plugins: ${{ steps.scan.outputs.plugins }}
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
with:
fetch-depth: 0
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
with:
node-version: 18
- name: Determine changes
id: scan
env:
HEAD: ${{ github.sha }}
BASE: ${{ github.event.pull_request.base.sha }}
run: |
root=$(pwd)
cd plugins
changed=()
for f in */; do
if git diff --name-only $BASE $HEAD | grep $f -q; then
if [[ ! -L "$f" && -f "$f/package.json" ]]; then
cd $f
if npm run | grep ui-test -q; then
changed+=($f)
fi
cd $root/plugins
fi
fi
done
JSON="[$(echo ${changed[@]} | sed 's/ /,/g')]"
echo "plugins=$(echo $JSON)" >> $GITHUB_OUTPUT
playwright:
name: 'Run Playwright Tests'
needs: changes
if: needs.changes.outputs.plugins != '[]'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
with:
node-version: 18
- name: Install dependencies
run: yarn
- name: Install playwright
run: yarn playwright install --with-deps chromium
- name: Run tests
env:
PLUGINS: ${{ needs.changes.outputs.plugins }}
run: |
root=$(pwd)
cd packages/backend
readarray folders < <(echo $PLUGINS | sed 's/[][]//g' | sed 's/,/ /g')
# enable permission support and RBAC plugins
printf "\npermission:\n enabled: true\n" >> ${root}/app-config.yaml
# Start backend
echo "Starting backend"
logfile=$(mktemp)
yarn start >$logfile 2>&1 &
for attempt in $(seq 1 45); do
sleep 1
if grep -q "Error:" $logfile; then
cat $logfile
exit 1
fi
if grep -q "Listening on" $logfile; then
echo "Backend started"
break
fi
if [[ attempt -eq 45 ]]; then
echo "Failed to launch backend"
cat $logfile
exit 1
fi
done
cd $root/plugins
# Launch suitable plugins with changes
for f in $folders; do
cd $f
echo "Starting $f plugin"
tmpfile=$(mktemp)
# Start the plugin
yarn start >$tmpfile 2>&1 &
for attempt in $(seq 1 45); do
sleep 1
if grep -q "Error:" $tmpfile; then
cat $tmpfile
exit 1
fi
if grep -q "webpack compiled" $tmpfile; then
echo "$f started"
break
fi
if [[ attempt -eq 45 ]]; then
echo "Failed to launch $f"
cat $tmpfile
exit 1
fi
done
# Run UI tests
yarn run ui-test
# Kill the plugin
pid=$(lsof -i :3000 -Fp | grep p | sed s/p//)
kill -9 $pid && echo "$f shut down"
cd $root/plugins
done
# Kill backend
pid=$(lsof -i :7007 -Fp | grep p | sed s/p//)
kill -9 $pid && echo "Backend shut down"
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
if: always()
with:
name: playwright-report
path: plugins/*/playwright-report/
retention-days: 1