Skip to content

Commit

Permalink
feat: add github action pr builds for building project, and running t…
Browse files Browse the repository at this point in the history
…ests on linux and windows (#204)

* feat: add github action pr builds for building project, and running tests on linux and windows

* feat: update and ensure linux ci cd test build only run on dotnet 7 framework only

* feat: add sensible timeouts for github action builds and add automatic upgrades for github actions

* feat: use a safe implementation of falling back to char separator for PhoneNumberOfflineGeocoder.cs
  • Loading branch information
wmundev authored Jan 29, 2024
1 parent 9aa1b19 commit 46ef382
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 2
- package-ecosystem: "nuget"
directory: "/csharp/PhoneNumbers"
schedule:
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/build_and_run_unit_tests_linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: build_and_run_unit_tests_linux

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:

jobs:
build_and_run_unit_tests_linux:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.x
- name: Add zip files required for running tests
run: |
(cd resources/geocoding; zip -r ../../resources/geocoding.zip *)
(cd resources/test/geocoding; zip -r ../../../resources/test/testgeocoding.zip *)
- name: Restore dependencies
run: dotnet restore
working-directory: ./csharp
- name: Build solution
run: dotnet build --no-restore
working-directory: ./csharp
- name: Test solution targeting dotnet7.0 only
run: dotnet test --no-build --verbosity normal -p:TargetFrameworks=net7.0
working-directory: ./csharp
32 changes: 32 additions & 0 deletions .github/workflows/build_and_run_unit_tests_windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: build_and_run_unit_tests_windows

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:

jobs:
build_and_run_unit_tests_windows:
runs-on: windows-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.x
- name: Add zip files required for running tests
run: |
Compress-Archive -Path "resources\geocoding\*" -DestinationPath "resources\geocoding.zip"
Compress-Archive -Path "resources\test\geocoding\*" -DestinationPath "resources\test\testgeocoding.zip"
- name: Restore dependencies
run: dotnet restore
working-directory: ./csharp
- name: Build solution
run: dotnet build --no-restore
working-directory: ./csharp
- name: Test solution
run: dotnet test --no-build --verbosity normal
working-directory: ./csharp
5 changes: 5 additions & 0 deletions csharp/PhoneNumbers/PhoneNumberOfflineGeocoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ private static SortedDictionary<int, HashSet<string>> LoadFileNamesFromZip(Strea
}

var name = entry.FullName.Split('.')[0].Split('\\');
// fallback to directory separator char if we are unable to use the original implementation of splitting the path
if (name.Length < 2)
{
name = entry.FullName.Split('.')[0].Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
}
int country;
try
{
Expand Down

0 comments on commit 46ef382

Please sign in to comment.