build-cloud-nx.yml•5.3 kB
name: CI
on:
pull_request:
permissions:
actions: read
contents: read
env:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
jobs:
main:
runs-on: ubuntu-latest
if: github.repository == 'activepieces/activepieces'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 20
cache: 'npm'
- run: npx nx-cloud start-ci-run --distribute-on="3 linux-large-js"
if: github.event.pull_request.head.repo.full_name == github.repository
- run: npm ci
- run: npx nx reset
- uses: nrwl/nx-set-shas@v4
- name: List all nx targets
run: npx nx show projects --all
- name: Get changed files
id: changed-files
run: echo "files=$(git diff --name-only HEAD origin/main | tr '\n' ' ')" >> $GITHUB_OUTPUT
- name: Check if framework or common pieces are changed
id: check-framework-common
run: |
CHANGED_FILES="${{ steps.changed-files.outputs.files }}"
if echo "$CHANGED_FILES" | grep -q "community/framework\|community/common"; then
echo "framework_or_common_changed=true" >> $GITHUB_OUTPUT
else
echo "framework_or_common_changed=false" >> $GITHUB_OUTPUT
fi
- name: Extract pieces projects from changed files
id: extract-pieces
run: |
PIECES=$(echo "${{ steps.changed-files.outputs.files }}" | grep -o "packages/pieces/[^/]*/[^/]*/" | awk -F'/' '{print "pieces-" $4}' | sort -u | tr '\n' ',' | sed 's/,$//')
echo "pieces_projects=$PIECES" >> $GITHUB_OUTPUT
- name: Lint affected projects excluding pieces
run: |
if [ "${{ github.event.pull_request.head.repo.full_name }}" = "${{ github.repository }}" ]; then
npx nx affected --target=lint --exclude="pieces-*" --agents --parallel
else
npx nx affected --target=lint --exclude="pieces-*"
fi
- name: Lint changed pieces projects
if: steps.extract-pieces.outputs.pieces_projects != '' && steps.check-framework-common.outputs.framework_or_common_changed == 'false'
run: |
if [ "${{ github.event.pull_request.head.repo.full_name }}" = "${{ github.repository }}" ]; then
npx nx run-many --target=lint --projects="${{ steps.extract-pieces.outputs.pieces_projects }}" --agents --parallel
else
npx nx run-many --target=lint --projects="${{ steps.extract-pieces.outputs.pieces_projects }}"
fi
- name: Lint all pieces projects
if: steps.check-framework-common.outputs.framework_or_common_changed == 'true'
run: |
if [ "${{ github.event.pull_request.head.repo.full_name }}" = "${{ github.repository }}" ]; then
npx nx run-many --target=lint --projects="pieces-*" --agents --parallel
else
npx nx run-many --target=lint --projects="pieces-*"
fi
- name: Build affected projects excluding pieces
run: |
if [ "${{ github.event.pull_request.head.repo.full_name }}" = "${{ github.repository }}" ]; then
npx nx affected --target=build -c production --exclude="pieces-*" --agents --parallel
else
npx nx affected --target=build -c production --exclude="pieces-*"
fi
- name: Build changed pieces projects
if: steps.extract-pieces.outputs.pieces_projects != '' && steps.check-framework-common.outputs.framework_or_common_changed == 'false'
run: |
if [ "${{ github.event.pull_request.head.repo.full_name }}" = "${{ github.repository }}" ]; then
npx nx run-many --target=build -c production --projects="${{ steps.extract-pieces.outputs.pieces_projects }}" --agents --parallel
else
npx nx run-many --target=build -c production --projects="${{ steps.extract-pieces.outputs.pieces_projects }}"
fi
- name: Build all pieces projects
if: steps.check-framework-common.outputs.framework_or_common_changed == 'true'
run: |
if [ "${{ github.event.pull_request.head.repo.full_name }}" = "${{ github.repository }}" ]; then
npx nx run-many --target=build -c production --projects="pieces-*" --agents --parallel
else
npx nx run-many --target=build -c production --projects="pieces-*"
fi
- name: Run all tests in parallel
run: |
set -euo pipefail
pids=()
if [ "${{ github.event.pull_request.head.repo.full_name }}" = "${{ github.repository }}" ]; then
npx nx run-many --target=test --projects=engine,shared --agents --parallel &
else
npx nx run-many --target=test --projects=engine,shared &
fi
pids+=($!)
npx nx run server-api:test-ce &
pids+=($!)
npx nx run server-api:test-ee &
pids+=($!)
npx nx run server-api:test-cloud &
pids+=($!)
status=0
for pid in "${pids[@]}"; do
if ! wait "$pid"; then
status=1
fi
done
exit $status