Skip to content

Commit

Permalink
Update dotnet build pipeline (#671)
Browse files Browse the repository at this point in the history
## Type of change

<!-- (mark with an `X`) -->

```
- [ ] Bug fix
- [ ] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [x] Build/deploy pipeline (DevOps)
- [ ] Other
```

## Objective

<!--Describe what the purpose of this PR is. For example: what bug
you're fixing or what new feature you're adding-->

## Code changes

<!--Explain the changes you've made to each file or major component.
This should help the reviewer understand your changes-->
<!--Also refer to any related changes or PRs in other repositories-->

- **.github/workflows/build-dotnet.yml:** Trigger build on `rc` and
`hotfix-rc` branches, get dotnet project version from `.csproj` while
building.
- **.github/workflows/publish-dotnet.yml** Use build artifact during
publish

## Before you submit

- Please add **unit tests** where it makes sense to do so
  • Loading branch information
michalchecinski authored Mar 29, 2024
1 parent 0ae0226 commit 9cd9a15
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 60 deletions.
31 changes: 26 additions & 5 deletions .github/workflows/build-dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
push:
branches:
- main
- rc
- hotfix-rc
pull_request:
workflow_dispatch:

jobs:
generate_schemas:
Expand All @@ -12,12 +16,31 @@ jobs:
build_rust:
uses: ./.github/workflows/build-rust-cross-platform.yml

version:
name: Get version
runs-on: ubuntu-22.04
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Install xmllint
run: sudo apt-get install -y libxml2-utils

- name: Get version
id: version
run: |
VERSION=$(xmllint --xpath 'string(/Project/PropertyGroup/Version)' languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj)
echo "version=$VERSION" >> $GITHUB_OUTPUT
build_dotnet:
name: Build .NET
runs-on: ubuntu-22.04
needs:
- generate_schemas
- build_rust
- version

steps:
- name: Checkout Repository
Expand Down Expand Up @@ -58,21 +81,19 @@ jobs:
name: libbitwarden_c_files-x86_64-pc-windows-msvc
path: languages/csharp/Bitwarden.Sdk/windows-x64

- name: Build .NET 6 Project
- name: Build .NET Project
working-directory: languages/csharp/Bitwarden.Sdk
run: |
dotnet restore
dotnet build --configuration Release
- name: Pack NuGet Package
env:
VERSION: 0.0.1
run: dotnet pack --configuration Release -p:PackageID=Bitwarden.Sdk -p:Version=${VERSION} --output ./nuget-output /nologo /v:n
run: dotnet pack --configuration Release --output ./nuget-output /nologo /v:n
working-directory: languages/csharp/Bitwarden.Sdk

- name: Upload NuGet package
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: Bitwarden.Sdk.0.0.1.nupkg
name: Bitwarden.Sdk.${{ needs.version.outputs.version }}.nupkg
path: |
./languages/csharp/Bitwarden.Sdk/nuget-output/*.nupkg
60 changes: 5 additions & 55 deletions .github/workflows/publish-dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,64 +50,14 @@ jobs:
runs-on: ubuntu-22.04
needs: validate
steps:
- name: Checkout Repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Download C# schemas artifact
uses: bitwarden/gh-actions/download-artifacts@main
with:
workflow: generate_schemas.yml
workflow_conclusion: success
branch: ${{ inputs.release_type == 'Dry Run' && 'main' || github.ref_name }}
artifacts: schemas.cs
path: languages/csharp/Bitwarden.Sdk

- name: Set up .NET Core
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4.0.0
with:
global-json-file: languages/csharp/global.json

- name: Download x86_64-apple-darwin files
uses: bitwarden/gh-actions/download-artifacts@main
with:
workflow: build-rust-cross-platform.yml
workflow_conclusion: success
branch: ${{ inputs.release_type == 'Dry Run' && 'main' || github.ref_name }}
artifacts: libbitwarden_c_files-x86_64-apple-darwin
path: languages/csharp/Bitwarden.Sdk/macos-x64

- name: Download aarch64-apple-darwin files
- name: Download NuGet package
uses: bitwarden/gh-actions/download-artifacts@main
with:
workflow: build-rust-cross-platform.yml
workflow: build-dotnet.yml
workflow_conclusion: success
branch: ${{ inputs.release_type == 'Dry Run' && 'main' || github.ref_name }}
artifacts: libbitwarden_c_files-aarch64-apple-darwin
path: languages/csharp/Bitwarden.Sdk/macos-arm64

- name: Download x86_64-unknown-linux-gnu files
uses: bitwarden/gh-actions/download-artifacts@main
with:
workflow: build-rust-cross-platform.yml
workflow_conclusion: success
branch: ${{ inputs.release_type == 'Dry Run' && 'main' || github.ref_name }}
artifacts: libbitwarden_c_files-x86_64-unknown-linux-gnu
path: languages/csharp/Bitwarden.Sdk/linux-x64

- name: Download x86_64-pc-windows-msvc files
uses: bitwarden/gh-actions/download-artifacts@main
with:
workflow: build-rust-cross-platform.yml
workflow_conclusion: success
branch: ${{ inputs.release_type == 'Dry Run' && 'main' || github.ref_name }}
artifacts: libbitwarden_c_files-x86_64-pc-windows-msvc
path: languages/csharp/Bitwarden.Sdk/windows-x64

- name: Pack NuGet Package
env:
VERSION: ${{ needs.validate.outputs.version }}
run: dotnet pack --configuration Release -p:PackageID=Bitwarden.Sdk -p:Version=${VERSION} --output ./nuget-output /nologo /v:n
working-directory: languages/csharp/Bitwarden.Sdk
artifacts: Bitwarden.Sdk.${{ needs.validate.outputs.version }}.nupkg
path: ./nuget-output

- name: Login to Azure - Prod Subscription
uses: Azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 # v1.4.7
Expand All @@ -125,4 +75,4 @@ jobs:
if: ${{ inputs.release_type != 'Dry Run' }}
env:
NUGET_API_KEY: ${{ steps.retrieve-secrets.outputs.nuget-api-key }}
run: dotnet nuget push ./languages/csharp/Bitwarden.Sdk/nuget-output/*.nupkg -k ${{ env.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
run: dotnet nuget push ./nuget-output/*.nupkg -k ${{ env.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json

0 comments on commit 9cd9a15

Please sign in to comment.