diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml new file mode 100644 index 0000000..1d1f8bb --- /dev/null +++ b/.github/workflows/cypress.yml @@ -0,0 +1,62 @@ +name: Cypress Tests with Allure Report + +on: + push: + branches: + - main + - develop + pull_request: + branches: + - main + - develop + +jobs: + tests: + runs-on: ubuntu-latest + + steps: + # Step 1: Check out the repository + - uses: actions/checkout@v4 + + # Step 2: Set up Node.js + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + # Step 3: Install dependencies + - name: Install dependencies + run: | + npm ci + npx cypress install # Ensure Cypress is installed + + # Step 4: Set up Allure commandline + - name: Set up Allure commandline + run: npm install -g allure-commandline + + # Step 5: Install additional dependencies for Allure and Cypress + - name: Install additional dependencies + run: | + npm install mocha-allure-reporter allure-cypress --save-dev + npm install @bahmutov/cypress-esbuild-preprocessor @badeball/cypress-cucumber-preprocessor cypress-file-upload --save-dev + + # Step 6: Run Cypress tests and generate Allure results (ensure it doesn't fail the workflow) + - name: Run Cypress tests + run: | + npx cypress run --reporter mocha-allure-reporter --reporter-options allureResults=allure-results || true + echo "Cypress tests completed (even with failures)" + + # Step 7: Always generate Allure report, even if tests failed + - name: Generate Allure report + run: | + allure generate allure-results --clean + if: always() # Ensures it runs even if the previous step fails + + # Step 8: Deploy Allure Report to GitHub Pages + - name: Deploy Allure Report to GitHub Pages + uses: peaceiris/actions-gh-pages@v3 + with: + personal_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./allure-report # Folder where the Allure report is generated + publish_branch: gh-pages # Deploy to gh-pages branch + if: always() # Ensures this step runs even if tests fail diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 3d9065a..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,117 +0,0 @@ -name: Cypress Tests with Allure Report - -on: - workflow_dispatch: # Trigger workflow manually using the 'Run workflow' button - pull_request: - branches: - - main # Trigger on PR targeting the 'development' branch - - develop # Trigger on PR targeting the 'master' branch - -jobs: - run-tests: - name: Run Cypress Tests - runs-on: ubuntu-latest - steps: - - name: Checkout Repository - uses: actions/checkout@v3 - - - name: Set up Java - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: '17' - - - name: Create Server Directory - run: mkdir -p server - - - name: Download JAR File from Cloud - run: | - wget --output-document=server/demo-0.0.1-SNAPSHOT.jar "https://firebasestorage.googleapis.com/v0/b/flashmart-c51b3.appspot.com/o/demo-0.0.1-SNAPSHOT.jar?alt=media&token=df7721d4-e5fd-416a-9a26-a550bf1d0a53" - - - name: Set JAVA_HOME Environment Variable - run: | - echo "JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))" >> $GITHUB_ENV - echo "JAVA_HOME is set to: $JAVA_HOME" - - - name: Download and Extract Allure - run: | - wget https://github.com/allure-framework/allure2/releases/download/2.32.0/allure-2.32.0.tgz -O allure-2.32.0.tgz - tar -zxvf allure-2.32.0.tgz - sudo mv allure-2.32.0 /opt/allure - echo "/opt/allure/bin" >> $GITHUB_PATH - - - name: Start the JAR File - run: | - nohup java -jar server/demo-0.0.1-SNAPSHOT.jar > server.log 2>&1 & - echo "Waiting for the server to start..." - until curl --silent --head http://localhost:7081/api/books; do - echo "Server not ready yet. Retrying in 2 seconds..." - sleep 2 - done - echo "Server is up and running." - - - name: Upload Server Log for Debugging - if: always() - uses: actions/upload-artifact@v3 - with: - name: server-log - path: server.log - - - - name: Install Node.js and Dependencies - uses: actions/setup-node@v3 - with: - node-version: '20' - - - name: Install Dependencies - working-directory: . - run: npm install - - - name: Run Cypress Tests - working-directory: . - run: npx cypress run --reporter mocha-allure-reporter --reporter-options allureResults=allure-results - continue-on-error: true - - - name: Generate Allure Report - working-directory: . - run: allure generate allure-results --clean - - - name: Upload Allure Report as Artifact - uses: actions/upload-artifact@v3 - with: - name: cypress-test-report - path: allure-report # Download the whole report directory - expire-in: 14d # Set expiration time for the artifact - - - name: Stop the Server - run: | - pkill -f 'java -jar server/demo-0.0.1-SNAPSHOT.jar' - - deploy-reports: - name: Deploy Allure Reports to GitHub Pages - runs-on: ubuntu-latest - needs: [run-tests] - permissions: - contents: write - steps: - - name: Checkout Repository - uses: actions/checkout@v3 - - - name: Download Report Artifact - uses: actions/download-artifact@v3 - with: - name: cypress-test-report - path: test-report - - - name: Combine Reports - run: | - mkdir -p combined-report - cp -R test-report/* combined-report/ - echo '

Test Report

' > combined-report/index.html - - - name: Deploy to GitHub Pages - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./combined-report - force_orphan: true