Skip to content

Commit ae1fe1d

Browse files
committed
ci: improved workflow process for PR from forked repos
1 parent bc41d1e commit ae1fe1d

File tree

5 files changed

+63
-5
lines changed

5 files changed

+63
-5
lines changed

.github/workflows/master.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ on:
99
jobs:
1010
build-scan:
1111
name: SonarCloud Scan
12-
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
1312
runs-on: ubuntu-latest
1413

1514
steps:
@@ -32,6 +31,7 @@ jobs:
3231
uses: sonarsource/[email protected]
3332
env:
3433
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
34+
if: env.SONAR_TOKEN != ''
3535

3636
build-test:
3737
name: Build & Test - Node ${{ matrix.node-version }} on ${{ matrix.os }}
@@ -41,7 +41,6 @@ jobs:
4141
node-version: [16.x, 18.x, 20.x, 22.x]
4242
os: [ ubuntu-latest, windows-latest ]
4343
runs-on: ${{ matrix.os }}
44-
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
4544

4645
steps:
4746
- name: Git checkout

.github/workflows/sonar.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Manual SonarCloud Analysis
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
pr_id:
7+
description: 'Pull Request ID to analyze'
8+
required: true
9+
type: string
10+
11+
jobs:
12+
sonar-analysis:
13+
name: SonarCloud Analysis for PR
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Get PR details
18+
id: pr
19+
uses: actions/github-script@v7
20+
with:
21+
script: |
22+
const pr = await github.rest.pulls.get({
23+
owner: context.repo.owner,
24+
repo: context.repo.repo,
25+
pull_number: ${{ inputs.pr_id }}
26+
});
27+
core.setOutput('head_ref', pr.data.head.ref);
28+
core.setOutput('base_ref', pr.data.base.ref);
29+
core.setOutput('head_sha', pr.data.head.sha);
30+
31+
- uses: actions/checkout@v4
32+
with:
33+
ref: ${{ steps.pr.outputs.head_sha }}
34+
fetch-depth: 0
35+
36+
- name: Use Node.js 22.x
37+
uses: actions/setup-node@v4
38+
with:
39+
node-version: 22.x
40+
- run: npm install
41+
- run: npm run lint
42+
- run: npm test
43+
env:
44+
SWITCHER_API_KEY: ${{ secrets.SWITCHER_API_KEY }}
45+
46+
- name: SonarCloud Scan
47+
uses: sonarsource/[email protected]
48+
env:
49+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
50+
if: env.SONAR_TOKEN != ''
51+
with:
52+
args: >
53+
-Dsonar.pullrequest.key=${{ inputs.pr_id }} \
54+
-Dsonar.pullrequest.branch=${{ steps.pr.outputs.head_ref }} \
55+
-Dsonar.pullrequest.base=${{ steps.pr.outputs.base_ref }}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "switcher-client",
3-
"version": "4.4.1",
3+
"version": "4.4.2",
44
"description": "Client JS SDK for working with Switcher-API",
55
"main": "./switcher-client.js",
66
"type": "module",
@@ -37,7 +37,7 @@
3737
"c8": "^10.1.3",
3838
"chai": "^5.2.1",
3939
"env-cmd": "^10.1.0",
40-
"eslint": "^9.30.1",
40+
"eslint": "^9.31.0",
4141
"mocha": "^11.7.1",
4242
"mocha-sonarqube-reporter": "^1.0.2",
4343
"sinon": "^21.0.0"

sonar-project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
sonar.projectKey=switcherapi_switcher-client-master
22
sonar.projectName=switcher-client-js
33
sonar.organization=switcherapi
4-
sonar.projectVersion=4.4.1
4+
sonar.projectVersion=4.4.2
55
sonar.links.homepage=https://github.com/switcherapi/switcher-client-js
66

77
sonar.javascript.lcov.reportPaths=coverage/lcov.info

tests/switcher-integrated.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ describe('Switcher integrated test', () => {
77
it('should hit remote API and return Switcher response', async function () {
88
this.timeout(3000);
99

10+
if (!process.env.SWITCHER_API_KEY) {
11+
this.skip();
12+
}
13+
1014
// given context build
1115
Client.buildContext({
1216
url: 'https://api.switcherapi.com',

0 commit comments

Comments
 (0)