-
-
Notifications
You must be signed in to change notification settings - Fork 24
172 lines (147 loc) · 4.88 KB
/
dotnet.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: .NET
on:
push:
branches: "**"
env:
REGISTRY: ghcr.io
jobs:
build:
runs-on: self-hosted
#services:
# postgres:
# image: postgres:latest
# ports:
# - 5432:5432
# env:
# POSTGRES_USER: test_user
# POSTGRES_PASSWORD: test_password_123
# POSTGRES_DB: valour_test
# options: >-
# --health-cmd="pg_isready -U test_user"
# --health-interval=10s
# --health-timeout=5s
# --health-retries=5
#redis:
# image: redis:latest
# ports:
# - 6379:6379
# options: >-
# --health-cmd="redis-cli ping || exit 1"
# --health-interval=10s
# --health-timeout=5s
# --health-retries=5
steps:
- uses: actions/checkout@v3
- name: Cache NuGet packages
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Check Disk Space and Clean Docker Artifacts
run: |
THRESHOLD=10 # Disk space threshold in GB
AVAILABLE_SPACE=$(df --output=avail / | tail -n 1 | awk '{print int($1/1024/1024)}')
echo "Available disk space: ${AVAILABLE_SPACE} GB"
if (( AVAILABLE_SPACE < THRESHOLD )); then
echo "Low disk space detected! Cleaning up Docker artifacts..."
docker system prune -af --volumes
echo "Docker cleanup complete."
else
echo "Sufficient disk space available: ${AVAILABLE_SPACE} GB"
fi
- name: Sanitize branch name
run: |
TAG_NAME=$(echo "${GITHUB_REF_NAME}" | tr '/:' '-_')
echo "TAG_NAME=${TAG_NAME}" >> $GITHUB_ENV
- name: Get Short SHA
id: short-sha
run: echo "short_sha=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
- name: Set Lowercase Variables
id: vars
shell: bash
run: |
echo "IMAGE_NAME=$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
echo "BRANCH_NAME=$(echo ${GITHUB_REF_NAME} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Modify asset versions
uses: mingjun97/file-regex-replace@v1
with:
regex: '\$\(SHORTHASH\)'
replacement: '${{ steps.short-sha.outputs.short_sha }}'
flags: "g"
include: '.*'
exclude: '.^'
encoding: 'utf8'
path: '.'
- name: Delete .js files if corresponding .ts files exist
run: |
#!/bin/bash
SEARCH_DIR="./"
find "$SEARCH_DIR" -name "*.ts" | while read tsfile; do
jsfile="${tsfile%.ts}.js"
if [ -f "$jsfile" ]; then
echo "Deleting $jsfile because $tsfile exists"
rm "$jsfile"
fi
done
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 9.0.100
- name: Restore workload
run: dotnet workload restore
- name: Clean
run: dotnet clean
- name: Restore dependencies
run: dotnet restore
- name: Clean
run: dotnet clean
- name: Build
run: dotnet build --no-restore
- name: Test
env:
TEST_DB: "valour_test"
TEST_DB_HOST: "localhost:5432"
TEST_DB_USER: "test_user"
TEST_DB_PASS: "test_password_123"
TEST_REDIS: "localhost:6379,abortConnect=False"
NODE_NAME: "emma"
APPLY_MIGRATIONS: true
run: dotnet test --no-build --verbosity normal
#continue-on-error: true
- name: Publish Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: Test Results
path: "**/test_results.trx"
- name: Publish Shared Nuget Package
uses: alirezanet/[email protected]
with:
PROJECT_FILE_PATH: Valour/Shared/Valour.Shared.csproj
VERSION_FILE_PATH: Valour/Shared/Valour.Shared.csproj
NUGET_KEY: ${{ secrets.NUGET_API_KEY }}
- name: Publish API Nuget Package
uses: alirezanet/[email protected]
with:
PROJECT_FILE_PATH: Valour/Sdk/Valour.Sdk.csproj
VERSION_FILE_PATH: Valour/Sdk/Valour.Sdk.csproj
NUGET_KEY: ${{ secrets.NUGET_API_KEY }}
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG_NAME }}-${{ steps.short-sha.outputs.short_sha }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG_NAME }}-latest
labels: |
org.opencontainers.image.source=${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}