From a4d8cdb14d7c4dfd8fc649acf5047142bdf9578a Mon Sep 17 00:00:00 2001 From: nabim777 Date: Tue, 8 Oct 2024 12:08:19 +0545 Subject: [PATCH] refactor ci Signed-off-by: nabim777 --- .github/workflows/build-and-test.yml | 73 ++++++++++++++++++++++ .github/workflows/ci-workflows.yml | 91 ---------------------------- client/package.json | 2 +- client/tests/setup-symlinks.sh | 23 +++++++ 4 files changed, 97 insertions(+), 92 deletions(-) create mode 100644 .github/workflows/build-and-test.yml delete mode 100644 .github/workflows/ci-workflows.yml create mode 100755 client/tests/setup-symlinks.sh diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 00000000..4d4d627e --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,73 @@ +name: CI + +on: + pull_request: + branches: + - master + push: + branches: + - master + +jobs: + setup: + runs-on: ubuntu-latest + env: + POSTGRES_DB: planka_db + POSTGRES_USER: user + POSTGRES_PASSWORD: password + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: 18 + cache: 'npm' + + - name: Setup PostgreSQL + uses: ikalnytskyi/action-setup-postgres@v5 + with: + database: ${{ env.POSTGRES_DB }} + username: ${{ env.POSTGRES_USER }} + password: ${{ env.POSTGRES_PASSWORD }} + + - name: Cache Node.js modules + uses: actions/cache@v3 + with: + path: client/node_modules + key: ${{ runner.os }}-node-${{ hashFiles('client/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - name: Install dependencies + run: | + npm install + cd client + npm run build + + - name: server setup + env: + DEFAULT_ADMIN_EMAIL: demo@demo.demo + DEFAULT_ADMIN_PASSWORD: demo + DEFAULT_ADMIN_NAME: Demo Demo + DEFAULT_ADMIN_USERNAME: demo + run: | + client/tests/setup-symlinks.sh + cd server + cp .env.sample .env + sed -i "s|^DATABASE_URL=.*|DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost/${POSTGRES_DB}|" .env + npm run db:init + npm start --prod & + + - name: Wait for development server + run: | + sudo apt-get install wait-for-it -y + wait-for-it -h localhost -p 1337 -t 10 + + - name: Run UI tests + run: | + cd client + npm install + npx playwright install chromium + npm run test:acceptance tests diff --git a/.github/workflows/ci-workflows.yml b/.github/workflows/ci-workflows.yml deleted file mode 100644 index 2e5e8d35..00000000 --- a/.github/workflows/ci-workflows.yml +++ /dev/null @@ -1,91 +0,0 @@ -name: CI - -on: - pull_request: - branches: - - master - push: - branches: - - master - -jobs: - setup: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Setup node - uses: actions/setup-node@v4 - with: - node-version: 18 - - - name: Setup PostgreSQL - uses: ikalnytskyi/action-setup-postgres@v5 - with: - port: 5432 - database: planka - username: planka - password: planka - - - name: Cache Node.js modules - id: cache-npm - uses: actions/cache@v3 - with: - path: | - /home/runner/work/planka/planka/node_modules - /home/runner/work/planka/planka/client/node_modules - key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node_modules- - - - name: Install dependencies - run: | - npm install - cd client - npm run build - - - name: Save Node.js modules cache - uses: actions/cache@v3 - with: - path: | - /home/runner/work/planka/planka/node_modules - /home/runner/work/planka/planka/client/node_modules - key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package-lock.json') }} - - - name: Symbolic fun - run: | - ln -s /home/runner/work/planka/planka/client/build/asset-manifest.json /home/runner/work/planka/planka/server/public/asset-manifest.json - ln -s /home/runner/work/planka/planka/client/build/favicon.ico /home/runner/work/planka/planka/server/public/favicon.ico - ln -s /home/runner/work/planka/planka/client/build/logo192.png /home/runner/work/planka/planka/server/public/logo192.png - ln -s /home/runner/work/planka/planka/client/build/logo512.png /home/runner/work/planka/planka/server/public/logo512.png - ln -s /home/runner/work/planka/planka/client/build/manifest.json /home/runner/work/planka/planka/server/public/manifest.json - ln -s /home/runner/work/planka/planka/client/build/robots.txt /home/runner/work/planka/planka/server/public/robots.txt - ln -s /home/runner/work/planka/planka/client/build/static /home/runner/work/planka/planka/server/public/static - ln -s /home/runner/work/planka/planka/client/build/index.html /home/runner/work/planka/planka/server/views/index.ejs - - - name: server setup - run: | - SECRETKEY=$(openssl rand -hex 64) - cd server - cp .env.sample .env - sed -i 's|^DATABASE_URL=.*|DATABASE_URL=postgresql://planka:planka@localhost/planka|' .env - sed -i "s|^SECRET_KEY=.*|SECRET_KEY=${SECRETKEY}/|" .env - sed -i 's/^# DEFAULT_ADMIN_EMAIL/DEFAULT_ADMIN_EMAIL/' .env - sed -i 's/^# DEFAULT_ADMIN_PASSWORD/DEFAULT_ADMIN_PASSWORD/' .env - sed -i 's/^# DEFAULT_ADMIN_NAME/DEFAULT_ADMIN_NAME/' .env - sed -i 's/^# DEFAULT_ADMIN_USERNAME/DEFAULT_ADMIN_USERNAME/' .env - npm run db:init - npm start --prod & - - - name: Wait for development server - run: | - sudo apt-get install wait-for-it -y - wait-for-it -h localhost -p 1337 -t 10 - - - name: Run e2e tests - run: | - cd client - npm install - npx playwright install chromium - npm run test:e2e tests diff --git a/client/package.json b/client/package.json index e9cc9d84..e9af83c9 100755 --- a/client/package.json +++ b/client/package.json @@ -7,7 +7,7 @@ "lint": "eslint --ext js,jsx src config-overrides.js", "start": "react-app-rewired start", "test": "react-app-rewired test", - "test:e2e": "cucumber-js --require cucumber.conf.js --require tests/acceptance/stepDefinitions/**/*.js --format @cucumber/pretty-formatter" + "test:acceptance": "cucumber-js --require cucumber.conf.js --require tests/acceptance/stepDefinitions/**/*.js --format @cucumber/pretty-formatter" }, "browserslist": { "production": [ diff --git a/client/tests/setup-symlinks.sh b/client/tests/setup-symlinks.sh new file mode 100755 index 00000000..8b8334e6 --- /dev/null +++ b/client/tests/setup-symlinks.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# This script sets up symbolic links between the client build files and the server directories, + +# Navigate to the root directory of the git repository +cd "$(git rev-parse --show-toplevel)" || { echo "Failed to navigate to the git repository root"; exit 1; } + +# Store paths for the client build, server public directory, and server views directory +CLIENT_PATH=$(pwd)/client/build +SERVER_PUBLIC_PATH=$(pwd)/server/public +SERVER_VIEWS_PATH=$(pwd)/server/views + +# Create symbolic links for the necessary client assets in the server's public and views directories +ln -s ${CLIENT_PATH}/asset-manifest.json ${SERVER_PUBLIC_PATH}/asset-manifest.json && echo "Linked asset-manifest.json successfully" +ln -s ${CLIENT_PATH}/favicon.ico ${SERVER_PUBLIC_PATH}/favicon.ico && echo "Linked favicon.ico successfully" +ln -s ${CLIENT_PATH}/logo192.png ${SERVER_PUBLIC_PATH}/logo192.png && echo "Linked logo192.png successfully" +ln -s ${CLIENT_PATH}/logo512.png ${SERVER_PUBLIC_PATH}/logo512.png && echo "Linked logo512.png successfully" +ln -s ${CLIENT_PATH}/manifest.json ${SERVER_PUBLIC_PATH}/manifest.json && echo "Linked manifest.json successfully" +ln -s ${CLIENT_PATH}/robots.txt ${SERVER_PUBLIC_PATH}/robots.txt && echo "Linked robots.txt successfully" +ln -s ${CLIENT_PATH}/static ${SERVER_PUBLIC_PATH}/static && echo "Linked static folder successfully" +ln -s ${CLIENT_PATH}/index.html ${SERVER_VIEWS_PATH}/index.ejs && echo "Linked index.html to index.ejs successfully" + +echo "Setup symbolic links completed successfully."