From 9616d2565a602376da63d06ab11259ca9a1924ca Mon Sep 17 00:00:00 2001 From: Tung Huynh Date: Thu, 8 Aug 2024 14:42:02 +0700 Subject: [PATCH] refactor: github actions --- .github/workflows/audit.yml | 44 ++++++++++++++++++ .github/workflows/build.yml | 48 ++++++++++++++++++++ .github/workflows/ci.yml | 82 ---------------------------------- .github/workflows/testrail.yml | 40 +++++++++++++++++ README.md | 3 +- 5 files changed, 134 insertions(+), 83 deletions(-) create mode 100644 .github/workflows/audit.yml create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/testrail.yml diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml new file mode 100644 index 0000000..e2ea272 --- /dev/null +++ b/.github/workflows/audit.yml @@ -0,0 +1,44 @@ +name: Audit + +on: + workflow_run: + workflows: ["Build"] + types: + - completed + +jobs: + audit: + runs-on: ubuntu-latest + + defaults: + run: + working-directory: processor + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20.9.0' + + - name: Run npm audit + run: npm audit + + - name: Download code coverage results + uses: actions/download-artifact@v4 + with: + name: code-coverage-report + + - name: SonarQube Scan + uses: sonarsource/sonarqube-scan-action@master + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + + - name: SonarQube Quality Gate + uses: sonarsource/sonarqube-quality-gate-action@master + timeout-minutes: 5 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..4b0d5c6 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,48 @@ +name: Build + +on: + push: + branches: + - main + - develop + pull_request: + branches: + - '**' + +jobs: + build-processor: + runs-on: ubuntu-latest + + defaults: + run: + working-directory: processor + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20.9.0' + + - name: Install dependencies + run: npm ci + + - name: Run ESLint check + run: npm run lint + + - name: Run Prettier check + run: npm run prettier:check + + - name: Build project + run: npm run build + + - name: Run tests + run: npm run test + + - name: Archive code coverage results + uses: actions/upload-artifact@v4 + with: + name: code-coverage-report + path: junit-report.xml \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 0217818..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,82 +0,0 @@ -name: CI - -on: - push: - branches: - - main - - develop - pull_request: - branches: - - "**" - -jobs: - build-processor: - runs-on: ubuntu-latest - - defaults: - run: - working-directory: processor - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Node.js 20 - uses: actions/setup-node@v4 - with: - node-version: "20.9.0" - - - name: Install dependencies - run: npm ci - - - name: ESLint check - run: npm run lint - - - name: Prettier check - run: npm run prettier:check - - - name: Build project - run: npm run build - - - name: Run tests - run: npm run test - - - name: Python setup - if: always() - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - - name: TestRail CLI upload results - env: - TR_INSTANCE: ${{ secrets.TR_INSTANCE }} - TR_PROJECT_NAME: ${{ secrets.TR_PROJECT_NAME }} - TR_USER_EMAIL: ${{ secrets.TR_USER_EMAIL }} - TR_PASSWORD: ${{ secrets.TR_PASSWORD }} - if: always() - run: | - pip install trcli - trcli -y \ - -h "https://$TR_INSTANCE.testrail.io" \ - --project "$TR_PROJECT_NAME" \ - -u $TR_USER_EMAIL \ - -p $TR_PASSWORD \ - parse_junit \ - --title "Automated Tests - ${{ github.sha }}" \ - --run-description ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} \ - -f "junit-report.xml" - - - name: Run audit - run: npm audit - - - name: SonarQube Scan - uses: sonarsource/sonarqube-scan-action@master - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} - - - name: SonarQube Quality Gate - uses: sonarsource/sonarqube-quality-gate-action@master - timeout-minutes: 5 - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/testrail.yml b/.github/workflows/testrail.yml new file mode 100644 index 0000000..d1698f4 --- /dev/null +++ b/.github/workflows/testrail.yml @@ -0,0 +1,40 @@ +name: TestRail + +on: + workflow_run: + workflows: ["Build"] + types: + - completed + +jobs: + testrail: + runs-on: ubuntu-latest + + steps: + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Download code coverage results + uses: actions/download-artifact@v4 + with: + name: code-coverage-report + + - name: Upload Test Results to TestRail + env: + TR_INSTANCE: ${{ secrets.TR_INSTANCE }} + TR_PROJECT_NAME: ${{ secrets.TR_PROJECT_NAME }} + TR_USER_EMAIL: ${{ secrets.TR_USER_EMAIL }} + TR_PASSWORD: ${{ secrets.TR_PASSWORD }} + run: | + pip install trcli + trcli -y \ + -h "https://$TR_INSTANCE.testrail.io" \ + --project "$TR_PROJECT_NAME" \ + -u $TR_USER_EMAIL \ + -p $TR_PASSWORD \ + parse_junit \ + --title "Automated Tests - ${{ github.sha }}" \ + --run-description ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} \ + -f "junit-report.xml" diff --git a/README.md b/README.md index f69cbec..ebee0f3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip) -[![GitHub Actions](https://github.com/mollie/commercetools-connector/actions/workflows/ci.yml/badge.svg)](https://github.com/mollie/commercetools-connector/actions/workflows/ci.yml/badge.svg) +[![GitHub Actions](https://github.com/mollie/commercetools-connector/actions/workflows/build.yml/badge.svg)](https://github.com/mollie/commercetools-connector/actions/workflows/build.yml/badge.svg) +[![GitHub Actions](https://github.com/mollie/commercetools-connector/actions/workflows/audit.yml/badge.svg)](https://github.com/mollie/commercetools-connector/actions/workflows/audit.yml/badge.svg) # 🚀 COMMERCETOOLS MOLLIE CONNECTOR 🚀