diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 33a8850..62b8713 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -9,7 +9,6 @@ on: jobs: build-scan: name: SonarCloud Scan - if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')" runs-on: ubuntu-latest steps: @@ -32,6 +31,7 @@ jobs: uses: sonarsource/sonarqube-scan-action@v5.2.0 env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + if: env.SONAR_TOKEN != '' build-test: name: Build & Test - Node ${{ matrix.node-version }} on ${{ matrix.os }} @@ -41,7 +41,6 @@ jobs: node-version: [16.x, 18.x, 20.x, 22.x] os: [ ubuntu-latest, windows-latest ] runs-on: ${{ matrix.os }} - if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')" steps: - name: Git checkout diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml new file mode 100644 index 0000000..0e176ae --- /dev/null +++ b/.github/workflows/sonar.yml @@ -0,0 +1,55 @@ +name: Manual SonarCloud Analysis + +on: + workflow_dispatch: + inputs: + pr_id: + description: 'Pull Request ID to analyze' + required: true + type: string + +jobs: + sonar-analysis: + name: SonarCloud Analysis for PR + runs-on: ubuntu-latest + + steps: + - name: Get PR details + id: pr + uses: actions/github-script@v7 + with: + script: | + const pr = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: ${{ inputs.pr_id }} + }); + core.setOutput('head_ref', pr.data.head.ref); + core.setOutput('base_ref', pr.data.base.ref); + core.setOutput('head_sha', pr.data.head.sha); + + - uses: actions/checkout@v4 + with: + ref: ${{ steps.pr.outputs.head_sha }} + fetch-depth: 0 + + - name: Use Node.js 22.x + uses: actions/setup-node@v4 + with: + node-version: 22.x + - run: npm install + - run: npm run lint + - run: npm test + env: + SWITCHER_API_KEY: ${{ secrets.SWITCHER_API_KEY }} + + - name: SonarCloud Scan + uses: sonarsource/sonarqube-scan-action@v5.2.0 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + if: env.SONAR_TOKEN != '' + with: + args: > + -Dsonar.pullrequest.key=${{ inputs.pr_id }} \ + -Dsonar.pullrequest.branch=${{ steps.pr.outputs.head_ref }} \ + -Dsonar.pullrequest.base=${{ steps.pr.outputs.base_ref }} \ No newline at end of file diff --git a/package.json b/package.json index 3baaf19..6a015df 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "switcher-client", - "version": "4.4.1", + "version": "4.4.2", "description": "Client JS SDK for working with Switcher-API", "main": "./switcher-client.js", "type": "module", @@ -37,7 +37,7 @@ "c8": "^10.1.3", "chai": "^5.2.1", "env-cmd": "^10.1.0", - "eslint": "^9.30.1", + "eslint": "^9.31.0", "mocha": "^11.7.1", "mocha-sonarqube-reporter": "^1.0.2", "sinon": "^21.0.0" diff --git a/sonar-project.properties b/sonar-project.properties index 99a0c8e..1e88e30 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,7 +1,7 @@ sonar.projectKey=switcherapi_switcher-client-master sonar.projectName=switcher-client-js sonar.organization=switcherapi -sonar.projectVersion=4.4.1 +sonar.projectVersion=4.4.2 sonar.links.homepage=https://github.com/switcherapi/switcher-client-js sonar.javascript.lcov.reportPaths=coverage/lcov.info diff --git a/tests/switcher-integrated.test.js b/tests/switcher-integrated.test.js index aa3c90b..210399a 100644 --- a/tests/switcher-integrated.test.js +++ b/tests/switcher-integrated.test.js @@ -7,6 +7,10 @@ describe('Switcher integrated test', () => { it('should hit remote API and return Switcher response', async function () { this.timeout(3000); + if (!process.env.SWITCHER_API_KEY) { + this.skip(); + } + // given context build Client.buildContext({ url: 'https://api.switcherapi.com',