Skip to content

Commit dfe6e94

Browse files
authored
Merge pull request #8 from BhaskarKulshrestha/feature_PR_CI
added the PR check pipline feature
2 parents 0525df0 + 661c18b commit dfe6e94

File tree

1 file changed

+170
-0
lines changed

1 file changed

+170
-0
lines changed

.github/workflows/pr-ci.yml

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
name: PR CI (Templates)
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, ready_for_review]
6+
branches: [ main ]
7+
8+
permissions:
9+
contents: read
10+
pull-requests: read
11+
12+
concurrency:
13+
group: pr-ci-${{ github.event.pull_request.number || github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
changes:
18+
name: Detect Template Changes
19+
runs-on: ubuntu-latest
20+
outputs:
21+
node: ${{ steps.filter.outputs.node }}
22+
python: ${{ steps.filter.outputs.python }}
23+
go: ${{ steps.filter.outputs.go }}
24+
java: ${{ steps.filter.outputs.java }}
25+
frontend: ${{ steps.filter.outputs.frontend }}
26+
any: ${{ steps.filter.outputs.any }}
27+
steps:
28+
- uses: actions/checkout@v4
29+
- name: Filter
30+
id: filter
31+
uses: dorny/paths-filter@v3
32+
with:
33+
filters: |
34+
node:
35+
- 'templates/node/**'
36+
python:
37+
- 'templates/python/**'
38+
go:
39+
- 'templates/go/**'
40+
java:
41+
- 'templates/spring-boot/**'
42+
frontend:
43+
- 'templates/frontend/**'
44+
any:
45+
- 'templates/**'
46+
47+
node:
48+
name: Node Template
49+
needs: changes
50+
if: needs.changes.outputs.node == 'true' || needs.changes.outputs.any == 'true'
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v4
54+
- uses: actions/setup-node@v4
55+
with:
56+
node-version: '20'
57+
cache: npm
58+
cache-dependency-path: templates/node/package.json
59+
- name: Install deps
60+
working-directory: templates/node
61+
run: npm install --no-audit --no-fund
62+
- name: Lint (placeholder)
63+
run: echo 'No lint config yet';
64+
- name: Smoke run
65+
working-directory: templates/node
66+
run: node src/index.js & sleep 2 && curl -f http://localhost:3001/ || echo 'Sample run complete'
67+
68+
frontend:
69+
name: Next.js Template
70+
needs: changes
71+
if: needs.changes.outputs.frontend == 'true' || needs.changes.outputs.any == 'true'
72+
runs-on: ubuntu-latest
73+
steps:
74+
- uses: actions/checkout@v4
75+
- uses: actions/setup-node@v4
76+
with:
77+
node-version: '20'
78+
cache: npm
79+
cache-dependency-path: templates/frontend/package.json
80+
- name: Install deps
81+
working-directory: templates/frontend
82+
run: npm install --no-audit --no-fund
83+
- name: Build
84+
working-directory: templates/frontend
85+
run: npm run build
86+
87+
python:
88+
name: Python FastAPI Template
89+
needs: changes
90+
if: needs.changes.outputs.python == 'true' || needs.changes.outputs.any == 'true'
91+
runs-on: ubuntu-latest
92+
steps:
93+
- uses: actions/checkout@v4
94+
- uses: actions/setup-python@v5
95+
with:
96+
python-version: '3.12'
97+
cache: 'pip'
98+
cache-dependency-path: templates/python/requirements.txt
99+
- name: Install deps
100+
working-directory: templates/python
101+
run: pip install -r requirements.txt
102+
- name: Import check
103+
working-directory: templates/python
104+
run: python -c "import fastapi, uvicorn"
105+
- name: FastAPI startup (smoke)
106+
working-directory: templates/python
107+
run: |
108+
uvicorn app.main:app --port 3004 &
109+
PID=$!
110+
sleep 2
111+
curl -f http://127.0.0.1:3004/health || (echo 'health check failed'; kill $PID; exit 1)
112+
kill $PID || true
113+
114+
go:
115+
name: Go Template
116+
needs: changes
117+
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.any == 'true'
118+
runs-on: ubuntu-latest
119+
steps:
120+
- uses: actions/checkout@v4
121+
- name: Build
122+
working-directory: templates/go
123+
run: go build -v ./...
124+
- name: Vet
125+
working-directory: templates/go
126+
run: go vet ./...
127+
- name: Run & health
128+
working-directory: templates/go
129+
run: |
130+
go run . &
131+
PID=$!
132+
sleep 2
133+
curl -f http://127.0.0.1:3002/health || (echo 'no health'; kill $PID; exit 1)
134+
kill $PID || true
135+
136+
java:
137+
name: Spring Boot Template
138+
needs: changes
139+
if: needs.changes.outputs.java == 'true' || needs.changes.outputs.any == 'true'
140+
runs-on: ubuntu-latest
141+
steps:
142+
- uses: actions/checkout@v4
143+
- name: Set up Temurin JDK
144+
uses: actions/setup-java@v4
145+
with:
146+
distribution: 'temurin'
147+
java-version: '21'
148+
cache: 'maven'
149+
- name: Build (skip tests)
150+
working-directory: templates/spring-boot
151+
run: mvn -B -ntp package -DskipTests
152+
153+
summary:
154+
name: Summary
155+
needs: [node, frontend, python, go, java]
156+
if: always()
157+
runs-on: ubuntu-latest
158+
steps:
159+
- name: Report matrix
160+
run: |
161+
echo "Node: ${{ needs.node.result }}"
162+
echo "Frontend: ${{ needs.frontend.result }}"
163+
echo "Python: ${{ needs.python.result }}"
164+
echo "Go: ${{ needs.go.result }}"
165+
echo "Java: ${{ needs.java.result }}"
166+
if [[ '${{ needs.node.result }}' == 'failure' || '${{ needs.frontend.result }}' == 'failure' || '${{ needs.python.result }}' == 'failure' || '${{ needs.go.result }}' == 'failure' || '${{ needs.java.result }}' == 'failure' ]]; then
167+
echo 'One or more template jobs failed.'
168+
exit 1
169+
fi
170+
echo 'All selected template jobs passed.'

0 commit comments

Comments
 (0)