Skip to content

Commit 77b94e7

Browse files
authored
feat: add Library PR & Release Workflow with SonarCloud integration (#173)
centralised workflow for publishing npm libraries
1 parent 6f7964d commit 77b94e7

1 file changed

Lines changed: 124 additions & 0 deletions

File tree

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Library PR & Release Workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
# Node configuration
7+
node-version:
8+
description: 'Node.js version'
9+
type: string
10+
default: '20'
11+
12+
# Runner configuration
13+
runner:
14+
description: 'Runner to use'
15+
type: string
16+
default: '["self-hosted", "ci-universal"]'
17+
18+
# Commands
19+
lint-command:
20+
description: 'Lint command'
21+
type: string
22+
default: 'yarn lint'
23+
24+
test-command:
25+
description: 'Test command'
26+
type: string
27+
default: 'yarn test --coverage'
28+
29+
build-command:
30+
description: 'Build command (optional, leave empty to skip)'
31+
type: string
32+
default: ''
33+
34+
# Semantic Release
35+
run-semantic-release:
36+
description: 'Run semantic-release on specified branches'
37+
type: boolean
38+
default: true
39+
40+
semantic-release-branches:
41+
description: 'Branches to run semantic-release on (JSON array)'
42+
type: string
43+
default: '["main", "beta", "alpha", "next"]'
44+
45+
# SonarCloud
46+
run-sonarcloud:
47+
description: 'Run SonarCloud scan'
48+
type: boolean
49+
default: true
50+
51+
sonar-project-key:
52+
description: 'SonarCloud project key (defaults to repository name)'
53+
type: string
54+
default: ''
55+
56+
# Timeouts
57+
timeout-minutes:
58+
description: 'Job timeout in minutes'
59+
type: number
60+
default: 15
61+
62+
secrets:
63+
GH_TOKEN:
64+
required: true
65+
SONAR_CLOUD_TOKEN:
66+
required: false
67+
68+
permissions:
69+
contents: write
70+
pull-requests: write
71+
72+
# Concurrency control: Cancel old runs for PRs, never cancel for main branch
73+
concurrency:
74+
group: ${{ github.workflow }}-${{ github.ref }}
75+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
76+
77+
jobs:
78+
checks-and-release:
79+
name: 🔍 Checks & Release
80+
runs-on: ${{ fromJSON(inputs.runner) }}
81+
timeout-minutes: ${{ inputs.timeout-minutes }}
82+
83+
steps:
84+
- name: Check out Git repository
85+
uses: actions/checkout@v4
86+
with:
87+
fetch-depth: 0 # Required for SonarCloud and semantic-release
88+
89+
- name: Setup Node with Cache
90+
uses: Typeform/.github/shared-actions/setup-node-with-cache@main
91+
with:
92+
node-version: ${{ inputs.node-version }}
93+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
94+
95+
- name: Run linters
96+
run: ${{ inputs.lint-command }}
97+
98+
- name: Run tests
99+
run: ${{ inputs.test-command }}
100+
101+
- name: Build (if specified)
102+
if: inputs.build-command != ''
103+
run: ${{ inputs.build-command }}
104+
105+
- name: Semantic Release
106+
if: |
107+
inputs.run-semantic-release &&
108+
contains(fromJSON(inputs.semantic-release-branches), github.ref_name)
109+
run: yarn semantic-release
110+
env:
111+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
112+
NPM_TOKEN: ${{ secrets.GH_TOKEN }}
113+
114+
- name: SonarCloud Scan
115+
if: inputs.run-sonarcloud
116+
uses: SonarSource/sonarqube-scan-action@v6
117+
with:
118+
args: >
119+
-Dsonar.projectKey=${{ inputs.sonar-project-key != '' && inputs.sonar-project-key || format('{0}_{1}', github.repository_owner, github.event.repository.name) }}
120+
-Dsonar.projectVersion=${{ github.run_id }}
121+
env:
122+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
123+
SONAR_TOKEN: ${{ secrets.SONAR_CLOUD_TOKEN }}
124+
LC_ALL: "C.UTF-8"

0 commit comments

Comments
 (0)