Skip to content

Commit 0caeba9

Browse files
committed
ci: Add main protection and cleaning of workflows
1 parent 9135cdf commit 0caeba9

3 files changed

Lines changed: 58 additions & 21 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Build and test
2+
3+
on:
4+
workflow_dispatch:
5+
workflow_call:
6+
7+
jobs:
8+
build:
9+
name: "Build and test"
10+
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [16.x, 18.x, 20.x]
16+
17+
steps:
18+
- name: Check out Git repository
19+
uses: actions/checkout@v4
20+
21+
- name: Use Node.js ${{ matrix.node-version }}
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
cache: "npm"
26+
- run: npm ci
27+
- run: npm run build --if-present
28+
- run: npm test

.github/workflows/dev.yaml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ on:
55
workflow_call:
66
push:
77
branches: ["main", "dev"]
8-
pull_request:
9-
branches: ["main", "dev"]
108

119
jobs:
1210
lint:
@@ -15,22 +13,4 @@ jobs:
1513
build:
1614
name: "Build and test"
1715
needs: lint
18-
19-
runs-on: ubuntu-latest
20-
21-
strategy:
22-
matrix:
23-
node-version: [16.x, 18.x, 20.x]
24-
25-
steps:
26-
- name: Check out Git repository
27-
uses: actions/checkout@v4
28-
29-
- name: Use Node.js ${{ matrix.node-version }}
30-
uses: actions/setup-node@v3
31-
with:
32-
node-version: ${{ matrix.node-version }}
33-
cache: "npm"
34-
- run: npm ci
35-
- run: npm run build --if-present
36-
- run: npm test
16+
uses: ./.github/workflows/buildAndTest.yaml

.github/workflows/pullRequest.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Pull Request
2+
3+
on:
4+
workflow_dispatch:
5+
workflow_call:
6+
pull_request:
7+
types:
8+
- opened
9+
- edited
10+
- synchronize
11+
- reopened
12+
13+
jobs:
14+
check-target-branch:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Check if PR targets a protected branch
19+
run: |
20+
PROTECTED_BRANCH="main"
21+
if [ "${{ github.event.pull_request.base.ref }}" == "$PROTECTED_BRANCH" ]; then
22+
echo "Pull requests to $PROTECTED_BRANCH are not allowed."
23+
exit 1
24+
fi
25+
echo "Pull request target is allowed."
26+
development:
27+
name: "Development workflow"
28+
needs: check-target-branch
29+
uses: ./.github/workflows/dev.yaml

0 commit comments

Comments
 (0)