Skip to content

Commit 2e1c809

Browse files
authored
Merge pull request #3 from toddaheath/chore/align-ci-cd-pipelines
Align CI/CD pipelines with optimization-heuristics patterns
2 parents 4a083b3 + 5d8dbda commit 2e1c809

File tree

5 files changed

+287
-58
lines changed

5 files changed

+287
-58
lines changed

.github/workflows/ci.yml

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,105 @@ on:
55
branches: [main]
66
pull_request:
77
branches: [main]
8+
workflow_call:
9+
10+
concurrency:
11+
group: ci-${{ github.ref }}
12+
cancel-in-progress: true
813

914
jobs:
1015
backend:
1116
name: Backend Build & Test
1217
runs-on: ubuntu-latest
18+
19+
services:
20+
postgres:
21+
image: postgres:16
22+
env:
23+
POSTGRES_DB: shed_builder_test
24+
POSTGRES_USER: postgres
25+
POSTGRES_PASSWORD: postgres
26+
ports:
27+
- 5432:5432
28+
options: >-
29+
--health-cmd "pg_isready -U postgres"
30+
--health-interval 10s
31+
--health-timeout 5s
32+
--health-retries 5
33+
1334
steps:
1435
- uses: actions/checkout@v4
1536

1637
- name: Setup .NET
1738
uses: actions/setup-dotnet@v4
1839
with:
19-
dotnet-version: "8.0.x"
40+
dotnet-version: 8.0.x
41+
42+
- name: Cache NuGet packages
43+
uses: actions/cache@v4
44+
with:
45+
path: ~/.nuget/packages
46+
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj') }}
47+
restore-keys: nuget-${{ runner.os }}-
2048

2149
- name: Restore dependencies
2250
run: dotnet restore ShedBuilder.sln
2351

2452
- name: Build
2553
run: dotnet build ShedBuilder.sln --no-restore --configuration Release
2654

27-
- name: Test with coverage
28-
run: dotnet test ShedBuilder.sln --no-build --configuration Release --collect:"XPlat Code Coverage" --results-directory ./coverage
55+
- name: Run unit tests
56+
run: >
57+
dotnet test ShedBuilder.sln
58+
--no-build
59+
--configuration Release
60+
--filter "FullyQualifiedName!~Integration"
61+
--logger "trx;LogFileName=unit-tests.trx"
62+
--collect:"XPlat Code Coverage"
63+
--results-directory ./test-results
64+
65+
- name: Run integration tests
66+
env:
67+
ConnectionStrings__DefaultConnection: "Host=localhost;Database=shed_builder_test;Username=postgres;Password=postgres"
68+
run: >
69+
dotnet test ShedBuilder.sln
70+
--no-build
71+
--configuration Release
72+
--filter "FullyQualifiedName~Integration"
73+
--logger "trx;LogFileName=integration-tests.trx"
74+
--results-directory ./test-results
75+
76+
- name: Upload test results
77+
uses: actions/upload-artifact@v4
78+
if: always()
79+
with:
80+
name: test-results
81+
path: ./test-results/
2982

3083
- name: Upload coverage artifact
3184
uses: actions/upload-artifact@v4
85+
if: always()
3286
with:
3387
name: backend-coverage
34-
path: coverage/**/coverage.cobertura.xml
88+
path: test-results/**/coverage.cobertura.xml
3589
retention-days: 14
3690

3791
frontend:
38-
name: Frontend Build
92+
name: Frontend Build & Lint
3993
runs-on: ubuntu-latest
94+
4095
defaults:
4196
run:
4297
working-directory: src/shed-builder-ui
98+
4399
steps:
44100
- uses: actions/checkout@v4
45101

46102
- name: Setup Node.js
47103
uses: actions/setup-node@v4
48104
with:
49-
node-version: "20"
50-
cache: "npm"
105+
node-version: 22
106+
cache: npm
51107
cache-dependency-path: src/shed-builder-ui/package-lock.json
52108

53109
- name: Install dependencies
@@ -65,16 +121,24 @@ jobs:
65121
- name: Build
66122
run: npm run build
67123

124+
- name: Upload build artifact
125+
uses: actions/upload-artifact@v4
126+
with:
127+
name: client-dist
128+
path: src/shed-builder-ui/dist/
129+
68130
docker:
69131
name: Docker Build
70132
runs-on: ubuntu-latest
133+
71134
strategy:
72135
matrix:
73136
include:
74137
- dockerfile: Dockerfile.api
75138
image: shed-builder-api
76139
- dockerfile: Dockerfile.ui
77140
image: shed-builder-ui
141+
78142
steps:
79143
- uses: actions/checkout@v4
80144

.github/workflows/deploy-dev.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Deploy to Dev
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- main
7+
8+
concurrency:
9+
group: deploy-dev-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
permissions:
13+
contents: read
14+
packages: write
15+
16+
env:
17+
REGISTRY: ghcr.io
18+
19+
jobs:
20+
ci:
21+
name: CI
22+
uses: ./.github/workflows/ci.yml
23+
24+
build-and-push:
25+
name: Build & Push Images
26+
needs: ci
27+
runs-on: ubuntu-latest
28+
environment: dev
29+
outputs:
30+
image-tag: ${{ steps.meta.outputs.tag }}
31+
32+
steps:
33+
- uses: actions/checkout@v4
34+
35+
- name: Set image tag
36+
id: meta
37+
run: echo "tag=dev-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
38+
39+
- name: Log in to GitHub Container Registry
40+
uses: docker/login-action@v3
41+
with:
42+
registry: ${{ env.REGISTRY }}
43+
username: ${{ github.actor }}
44+
password: ${{ secrets.GITHUB_TOKEN }}
45+
46+
- name: Build and push API image
47+
uses: docker/build-push-action@v6
48+
with:
49+
context: .
50+
file: Dockerfile.api
51+
push: true
52+
tags: ${{ env.REGISTRY }}/${{ github.repository_owner }}/shed-builder-api:${{ steps.meta.outputs.tag }}
53+
54+
- name: Build and push UI image
55+
uses: docker/build-push-action@v6
56+
with:
57+
context: .
58+
file: Dockerfile.ui
59+
push: true
60+
tags: ${{ env.REGISTRY }}/${{ github.repository_owner }}/shed-builder-ui:${{ steps.meta.outputs.tag }}
61+
62+
deploy:
63+
name: Deploy to Dev
64+
needs: build-and-push
65+
runs-on: ubuntu-latest
66+
environment: dev
67+
68+
steps:
69+
- uses: actions/checkout@v4
70+
71+
- name: Setup Helm
72+
uses: azure/setup-helm@v4
73+
74+
- name: Configure kubectl
75+
uses: azure/setup-kubectl@v4
76+
77+
- name: Set kubeconfig
78+
run: echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > $HOME/.kube/config
79+
80+
- name: Deploy with Helm
81+
run: |
82+
helm upgrade --install shed-builder deploy/helm/shed-builder \
83+
--namespace dev --create-namespace \
84+
--set api.image.repository=${{ env.REGISTRY }}/${{ github.repository_owner }}/shed-builder-api \
85+
--set api.image.tag=${{ needs.build-and-push.outputs.image-tag }} \
86+
--set ui.image.repository=${{ env.REGISTRY }}/${{ github.repository_owner }}/shed-builder-ui \
87+
--set ui.image.tag=${{ needs.build-and-push.outputs.image-tag }} \
88+
--set postgres.password=${{ secrets.DB_PASSWORD }} \
89+
--wait --timeout 5m

.github/workflows/deploy-prod.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Deploy to Prod
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
concurrency:
9+
group: deploy-prod
10+
cancel-in-progress: false
11+
12+
permissions:
13+
contents: read
14+
packages: write
15+
16+
env:
17+
REGISTRY: ghcr.io
18+
19+
jobs:
20+
ci:
21+
name: CI
22+
uses: ./.github/workflows/ci.yml
23+
24+
build-and-push:
25+
name: Build & Push Images
26+
needs: ci
27+
runs-on: ubuntu-latest
28+
environment: prod
29+
outputs:
30+
image-tag: ${{ steps.meta.outputs.tag }}
31+
32+
steps:
33+
- uses: actions/checkout@v4
34+
35+
- name: Set image tag
36+
id: meta
37+
run: echo "tag=prod-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
38+
39+
- name: Log in to GitHub Container Registry
40+
uses: docker/login-action@v3
41+
with:
42+
registry: ${{ env.REGISTRY }}
43+
username: ${{ github.actor }}
44+
password: ${{ secrets.GITHUB_TOKEN }}
45+
46+
- name: Build and push API image
47+
uses: docker/build-push-action@v6
48+
with:
49+
context: .
50+
file: Dockerfile.api
51+
push: true
52+
tags: |
53+
${{ env.REGISTRY }}/${{ github.repository_owner }}/shed-builder-api:${{ steps.meta.outputs.tag }}
54+
${{ env.REGISTRY }}/${{ github.repository_owner }}/shed-builder-api:latest
55+
56+
- name: Build and push UI image
57+
uses: docker/build-push-action@v6
58+
with:
59+
context: .
60+
file: Dockerfile.ui
61+
push: true
62+
tags: |
63+
${{ env.REGISTRY }}/${{ github.repository_owner }}/shed-builder-ui:${{ steps.meta.outputs.tag }}
64+
${{ env.REGISTRY }}/${{ github.repository_owner }}/shed-builder-ui:latest
65+
66+
deploy:
67+
name: Deploy to Production
68+
needs: build-and-push
69+
runs-on: ubuntu-latest
70+
environment: production
71+
72+
steps:
73+
- uses: actions/checkout@v4
74+
75+
- name: Setup Helm
76+
uses: azure/setup-helm@v4
77+
78+
- name: Configure kubectl
79+
uses: azure/setup-kubectl@v4
80+
81+
- name: Set kubeconfig
82+
run: echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > $HOME/.kube/config
83+
84+
- name: Deploy with Helm
85+
run: |
86+
helm upgrade --install shed-builder deploy/helm/shed-builder \
87+
--namespace production --create-namespace \
88+
--set api.image.repository=${{ env.REGISTRY }}/${{ github.repository_owner }}/shed-builder-api \
89+
--set api.image.tag=${{ needs.build-and-push.outputs.image-tag }} \
90+
--set ui.image.repository=${{ env.REGISTRY }}/${{ github.repository_owner }}/shed-builder-ui \
91+
--set ui.image.tag=${{ needs.build-and-push.outputs.image-tag }} \
92+
--set postgres.password=${{ secrets.DB_PASSWORD }} \
93+
--set ingress.enabled=true \
94+
--set ingress.host=${{ vars.PRODUCTION_HOST }} \
95+
--wait --timeout 5m

0 commit comments

Comments
 (0)