Skip to content

Commit 90ad327

Browse files
committed
ci: build and test on pull requests and before publishing
1 parent c34d16b commit 90ad327

3 files changed

Lines changed: 77 additions & 2 deletions

File tree

.github/workflows/release.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,19 @@ jobs:
1414
pull-requests: write # Required to create release PRs
1515
uses: equinor/ops-actions/.github/workflows/release-please-manifest.yml@2198d70491e461c59dd3560b9ea10b1080d863c5 # v9.39.6
1616

17-
build-and-publish:
18-
name: Build and publish
17+
test:
18+
name: Test
1919
needs: release-please
2020
if: ${{ always() && (github.event_name == 'workflow_dispatch' || needs.release-please.outputs.releases_created == 'true') }}
21+
permissions:
22+
contents: read
23+
uses: ./.github/workflows/run-tests.yml
24+
25+
build-and-publish:
26+
name: Build and publish
27+
needs: [release-please, test]
28+
# needs.test must have succeeded — never publish a package whose tests did not pass.
29+
if: ${{ always() && needs.test.result == 'success' && (github.event_name == 'workflow_dispatch' || needs.release-please.outputs.releases_created == 'true') }}
2130
runs-on: ubuntu-latest
2231
permissions:
2332
contents: read # Required to read the repository contents

.github/workflows/run-tests.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Run Tests
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
# Called by the release workflow so nothing is published without a green test run.
7+
workflow_call:
8+
9+
permissions: {}
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
test:
17+
name: Build and test
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
24+
with:
25+
persist-credentials: false
26+
27+
- name: Set up Python
28+
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
29+
with:
30+
python-version: "3.13"
31+
32+
- name: Install Python dependencies
33+
run: pip install -r requirements.txt
34+
35+
- name: Set up .NET
36+
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
37+
with:
38+
dotnet-version: "10.x"
39+
40+
- name: Install Kiota
41+
run: dotnet tool install --global Microsoft.OpenApi.Kiota
42+
43+
# Generated clients are not committed, so they must be produced before anything compiles.
44+
- name: Generate C# clients
45+
run: python generate_all.py
46+
47+
# Builds the whole solution, so the integration test project is compile-checked too.
48+
- name: Build
49+
run: dotnet build OsduCsharpClient.slnx --configuration Release
50+
51+
# Unit tests only — the integration tests need credentials for a live OSDU instance.
52+
- name: Run unit tests
53+
run: >
54+
dotnet test tests/OsduCsharpClient.Tests/OsduCsharpClient.Tests.csproj
55+
--configuration Release
56+
--no-build
57+
--logger "trx;LogFileName=test-results.trx"
58+
59+
- name: Upload test results
60+
if: ${{ !cancelled() }}
61+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
62+
with:
63+
name: test-results
64+
path: "**/TestResults/*.trx"
65+
retention-days: 5

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
bin/
33
obj/
44
*.user
5+
TestResults/
56

67
# NuGet
78
*.nupkg

0 commit comments

Comments
 (0)