Skip to content

Commit

Permalink
[PM-9310] Add test project and necessary workflows to use it, with ce…
Browse files Browse the repository at this point in the history
…ntralized versioning (#151)

* Add test project and necessary workflows to use it, with centralized versioning

* Just test entire solution

* Clean up something I copied from the monolith
  • Loading branch information
withinfocus authored Jun 27, 2024
1 parent 20f9dac commit ca886ed
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 89 deletions.
59 changes: 18 additions & 41 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,27 @@
---
name: Build

on:
push:
paths-ignore:
- ".github/workflows/**"
workflow_dispatch:
push:
branches:
- "main"
- "rc"
- "hotfix-rc"
pull_request:

jobs:
cloc:
name: CLOC
runs-on: ubuntu-22.04
steps:
- name: Checkout repo
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Install cloc
run: sudo apt update && sudo apt install -y cloc

- name: Print lines of code
run: cloc --include-lang C#,SQL,Razor,"Bourne Shell",PowerShell,HTML,CSS,Sass,JavaScript,TypeScript --vcs git


build-artifacts:
name: Build artifacts
runs-on: ubuntu-22.04

steps:
- name: Checkout repo
- name: Check out repo
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Print environment
run: |
whoami
dotnet --info
echo "GitHub ref: $GITHUB_REF"
echo "GitHub event: $GITHUB_EVENT"
- name: Restore/Clean service
working-directory: src/KeyConnector
run: |
echo "Restore"
dotnet restore
echo "Clean"
dotnet clean -c "Release" -o obj/build-output/publish
- name: Set up .NET
uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0

- name: Publish service
- name: Publish project
working-directory: src/KeyConnector
run: |
echo "Publish"
Expand All @@ -55,31 +32,31 @@ jobs:
pwd
ls -atlh ../../../
- name: Upload service artifact
- name: Upload project artifact
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: KeyConnector.zip
path: src/KeyConnector/KeyConnector.zip
if-no-files-found: error


build-docker:
name: Build Docker images
runs-on: ubuntu-22.04
needs: build-artifacts
env:
_AZ_REGISTRY: bitwardenprod.azurecr.io
_PROJECT_NAME: key-connector

steps:
- name: Checkout repo
- name: Check out repo
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Login to Azure - PROD Subscription
- name: Log in to Azure
uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0
with:
creds: ${{ secrets.AZURE_PROD_KV_CREDENTIALS }}

- name: Login to PROD ACR
- name: Log in to ACR
run: az acr login -n ${_AZ_REGISTRY%.azurecr.io}

- name: Generate Docker image tag
Expand All @@ -91,7 +68,7 @@ jobs:
fi
echo "image_tag=$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Generate image full name
- name: Generate full image name
id: image-name
env:
IMAGE_TAG: ${{ steps.tag.outputs.image_tag }}
Expand All @@ -102,7 +79,7 @@ jobs:
with:
name: KeyConnector.zip

- name: Setup build artifact
- name: Set up build artifact
run: |
mkdir -p src/KeyConnector/obj/build-output/publish
unzip KeyConnector.zip -d src/KeyConnector/obj/build-output/publish
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
name: Cleanup RC Branch
name: Clean up RC branch

on:
push:
Expand All @@ -8,10 +7,11 @@ on:

jobs:
delete-rc:
name: Delete RC Branch
name: Delete RC branch
runs-on: ubuntu-22.04

steps:
- name: Login to Azure - CI Subscription
- name: Log in to Azure
uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0
with:
creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }}
Expand All @@ -23,13 +23,13 @@ jobs:
keyvault: bitwarden-ci
secrets: "github-pat-bitwarden-devops-bot-repo-scope"

- name: Checkout main
- name: Check out repo
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
ref: main
token: ${{ steps.retrieve-bot-secrets.outputs.github-pat-bitwarden-devops-bot-repo-scope }}

- name: Check if a RC branch exists
- name: Check if RC branch exists
id: branch-check
run: |
hotfix_rc_branch_check=$(git ls-remote --heads origin hotfix-rc | wc -l)
Expand Down
37 changes: 15 additions & 22 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
---
name: Release
run-name: Release - ${{ github.event.inputs.release_type }}
run-name: Release ${{ github.event.inputs.release_type }}

on:
workflow_dispatch:
inputs:
release_type:
description: 'Release Options'
default: 'Initial Release'
description: "Release Options"
default: "Initial Release"
type: choice
options:
- Initial Release
Expand All @@ -21,8 +20,9 @@ jobs:
outputs:
release_version: ${{ steps.version.outputs.version }}
branch-name: ${{ steps.branch.outputs.branch-name }}

steps:
- name: Branch check
- name: Check branch
if: ${{ github.event.inputs.release_type != 'Dry Run' }}
run: |
if [[ "$GITHUB_REF" != "refs/heads/rc" ]] && [[ "$GITHUB_REF" != "refs/heads/hotfix-rc" ]]; then
Expand All @@ -32,16 +32,16 @@ jobs:
exit 1
fi
- name: Checkout repo
- name: Check out repo
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Check Release Version
- name: Check release version
id: version
uses: bitwarden/gh-actions/release-version-check@main
with:
release-type: ${{ github.event.inputs.release_type }}
project-type: dotnet
file: src/KeyConnector/KeyConnector.csproj
file: Directory.Build.props

- name: Get branch name
id: branch
Expand Down Expand Up @@ -77,24 +77,17 @@ jobs:
_RELEASE_VERSION: ${{ needs.setup.outputs.release_version }}
_BRANCH_NAME: ${{ needs.setup.outputs.branch-name }}
_RELEASE_OPTION: ${{ github.event.inputs.release_type }}
steps:
- name: Print environment
run: |
whoami
docker --version
echo "GitHub ref: $GITHUB_REF"
echo "GitHub event: $GITHUB_EVENT"
echo "Github Release Option: $_RELEASE_OPTION"

- name: Login to Azure - Prod Subscription
steps:
- name: Log in to Azure
uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0
with:
creds: ${{ secrets.AZURE_PROD_KV_CREDENTIALS }}

- name: Login to Azure ACR
- name: Log in to ACR
run: az acr login -n ${_AZ_REGISTRY%.azurecr.io}

- name: Setup DCT
- name: Set up DCT
id: setup-dct
uses: bitwarden/gh-actions/setup-docker-trust@main
with:
Expand Down Expand Up @@ -139,7 +132,6 @@ jobs:
- name: Log out of Docker
run: docker logout


check-failures:
name: Check for failures
if: always()
Expand All @@ -148,16 +140,17 @@ jobs:
- release-docker
- release-github
- setup

steps:
- name: Check if any job failed
if: |
(github.ref == 'refs/heads/main'
|| github.ref == 'refs/heads/rc'
|| github.ref == 'refs/heads/hotfix')
|| github.ref == 'refs/heads/hotfix-rc')
&& contains(needs.*.result, 'failure')
run: exit 1

- name: Login to Azure - CI subscription
- name: Log in to Azure
uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0
if: failure()
with:
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Test

on:
workflow_dispatch:
push:
branches:
- "main"
- "rc"
- "hotfix-rc"
pull_request:

jobs:
test:
name: Run tests
if: ${{ startsWith(github.head_ref, 'version_bump_') == false }}
runs-on: ubuntu-22.04

steps:
- name: Check out repo
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0

- name: Set up .NET
uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0

- name: Test solution
run: dotnet test --configuration Debug --logger "trx;LogFileName=test-results.trx" /p:CoverletOutputFormatter="cobertura" --collect:"XPlat Code Coverage"

- name: Report test results
uses: dorny/test-reporter@c9b3d0e2bd2a4e96aaf424dbaa31c46b42318226 # v1.6.0
if: always()
with:
name: Test Results
path: "**/test-results.trx"
reporter: dotnet-trx
fail-on-error: true

- name: Upload to codecov.io
uses: codecov/codecov-action@0cfda1dd0a4ad9efc75517f399d859cd1ea4ced1 # v4.0.2
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Loading

0 comments on commit ca886ed

Please sign in to comment.