Skip to content

Commit 7f05d15

Browse files
committed
ci: refactor to use reusable workflows
1 parent f6cb078 commit 7f05d15

File tree

5 files changed

+50
-40
lines changed

5 files changed

+50
-40
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: dotnet-demo-api CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
jobs:
8+
test:
9+
uses: vojtechmares/dotnet-demo-api/.github/workflows/reusable-test.yml@main
10+
11+
docker-build:
12+
needs: [test]
13+
uses: vojtechmares/dotnet-demo-api/.github/workflows/reusable-docker-build.yml@main
14+
15+
deploy:
16+
needs: [docker-build]
17+
if: ${{ contains(github.ref, 'release') }}
18+
uses: vojtechmares/dotnet-demo-api/.github/workflows/reusable-deploy.yml@main

.github/workflows/deploy.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Reusable deploy
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
environment:
7+
required: true
8+
type: string
9+
10+
jobs:
11+
deploy:
12+
runs-on: ubuntu-latest
13+
environment: ${{ inputs.environment }}
14+
15+
steps:
16+
- name: Deploy
17+
run: |
18+
echo "Deploying to ${{ inputs.environment }}..."
19+
sleep 30
20+
echo "Deploy to ${{ inputs.environment }} complete."

.github/workflows/build.yml renamed to .github/workflows/reusable-docker-build.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
name: Docker build
1+
name: Reusable Docker build
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
pull_request:
8-
branches:
9-
- main
4+
workflow_call:
105

116
jobs:
127
build:
13-
runs-on: ubuntu-24.04
8+
runs-on: ubuntu-latest
149

1510
permissions:
1611
contents: read
@@ -51,4 +46,4 @@ jobs:
5146
platforms: linux/amd64
5247
push: true
5348
tags: ${{ steps.meta.outputs.tags }}
54-
labels: ${{ steps.meta.outputs.labels }}
49+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/test.yml renamed to .github/workflows/reusable-test.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
name: .NET Test
1+
name: Reusable .NET tests
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
pull_request:
8-
branches:
9-
- main
4+
workflow_call:
5+
inputs:
6+
dotnet-version:
7+
required: true
8+
type: string
109

1110
jobs:
1211
test:
13-
runs-on: ubuntu-24.04 # or ubuntu-latest
12+
runs-on: ubuntu-latest
1413

1514
steps:
1615
- name: Checkout code
@@ -19,7 +18,7 @@ jobs:
1918
- name: Setup .NET
2019
uses: actions/setup-dotnet@v4
2120
with:
22-
dotnet-version: '9.0.x'
21+
dotnet-version: ${{ inputs.dotnet-version }}
2322

2423
- name: Cache NuGet packages
2524
uses: actions/cache@v4

0 commit comments

Comments
 (0)