Skip to content

Commit

Permalink
ci: Add main protection and cleaning of workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesGresset committed Nov 23, 2024
1 parent f454864 commit 2bd11a3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 21 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/buildAndTest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build and test

on:
workflow_dispatch:
workflow_call:

jobs:
build:
name: "Build and test"

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 18.x, 20.x]

steps:
- name: Check out Git repository
uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm ci
- run: npm run build --if-present
- run: npm test
22 changes: 1 addition & 21 deletions .github/workflows/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on:
workflow_call:
push:
branches: ["main", "dev"]
pull_request:
branches: ["main", "dev"]

jobs:
lint:
Expand All @@ -15,22 +13,4 @@ jobs:
build:
name: "Build and test"
needs: lint

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 18.x, 20.x]

steps:
- name: Check out Git repository
uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm ci
- run: npm run build --if-present
- run: npm test
uses: ./.github/workflows/buildAndTest.yaml
29 changes: 29 additions & 0 deletions .github/workflows/pullRequest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Pull Request

on:
workflow_dispatch:
workflow_call:
pull_request:
types:
- opened
- edited
- synchronize
- reopened

jobs:
check-target-branch:
runs-on: ubuntu-latest

steps:
- name: Check if PR targets a protected branch
run: |
PROTECTED_BRANCH="main"
if [ "${{ github.event.pull_request.base.ref }}" == "$PROTECTED_BRANCH" ]; then
echo "Pull requests to $PROTECTED_BRANCH are not allowed."
exit 1
fi
echo "Pull request target is allowed."
development:
name: "Development workflow"
needs: check-target-branch
uses: ./.github/workflows/dev.yaml

0 comments on commit 2bd11a3

Please sign in to comment.