mirror of
https://github.com/bitwarden/server.git
synced 2024-11-28 13:15:12 +01:00
532 lines
18 KiB
YAML
532 lines
18 KiB
YAML
---
|
|
name: Build
|
|
|
|
on:
|
|
push:
|
|
branches-ignore:
|
|
- "l10n_master"
|
|
- "gh-pages"
|
|
paths-ignore:
|
|
- ".github/workflows/**"
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
cloc:
|
|
name: CLOC
|
|
runs-on: ubuntu-22.04
|
|
steps:
|
|
- name: Checkout repo
|
|
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
|
|
|
|
- name: Install cloc
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get -y install cloc
|
|
|
|
- name: Print lines of code
|
|
run: cloc --include-lang C#,SQL,Razor,"Bourne Shell",PowerShell,HTML,CSS,Sass,JavaScript,TypeScript --vcs git
|
|
|
|
lint:
|
|
name: Lint
|
|
runs-on: ubuntu-22.04
|
|
steps:
|
|
- name: Checkout repo
|
|
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846
|
|
|
|
- name: Verify Format
|
|
run: dotnet format --verify-no-changes
|
|
|
|
testing:
|
|
name: Testing
|
|
runs-on: windows-2022
|
|
env:
|
|
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
|
|
steps:
|
|
- name: Set up dotnet
|
|
uses: actions/setup-dotnet@9211491ffb35dd6a6657ca4f45d43dfe6e97c829
|
|
with:
|
|
dotnet-version: "6.0.x"
|
|
- name: Set up MSBuild
|
|
uses: microsoft/setup-msbuild@ab534842b4bdf384b8aaf93765dc6f721d9f5fab
|
|
|
|
- name: Print environment
|
|
run: |
|
|
dotnet --info
|
|
msbuild -version
|
|
nuget help | grep Version
|
|
echo "GitHub ref: $GITHUB_REF"
|
|
echo "GitHub event: $GITHUB_EVENT"
|
|
|
|
- name: Checkout repo
|
|
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846
|
|
|
|
- name: Restore
|
|
run: dotnet restore --locked-mode
|
|
shell: pwsh
|
|
|
|
- name: Build OSS solution
|
|
run: msbuild bitwarden-server.sln /p:Configuration=Debug /p:DefineConstants="OSS" /verbosity:minimal
|
|
shell: pwsh
|
|
|
|
- name: Build solution
|
|
run: msbuild bitwarden-server.sln /p:Configuration=Debug /verbosity:minimal
|
|
shell: pwsh
|
|
|
|
- name: Test OSS solution
|
|
run: dotnet test ./test --configuration Debug --no-build --logger "trx;LogFileName=oss-test-results.trx" || true
|
|
shell: pwsh
|
|
|
|
- name: Test Bitwarden solution
|
|
run: dotnet test ./bitwarden_license/test --configuration Debug --no-build --logger "trx;LogFileName=bw-test-results.trx" || true
|
|
shell: pwsh
|
|
|
|
- name: Report test results
|
|
uses: dorny/test-reporter@c9b3d0e2bd2a4e96aaf424dbaa31c46b42318226
|
|
if: always()
|
|
with:
|
|
name: Test Results
|
|
path: "**/*-test-results.trx"
|
|
reporter: dotnet-trx
|
|
fail-on-error: true
|
|
|
|
build-artifacts:
|
|
name: Build artifacts
|
|
runs-on: ubuntu-22.04
|
|
needs:
|
|
- testing
|
|
- lint
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- project_name: Admin
|
|
base_path: ./src
|
|
node: true
|
|
- project_name: Api
|
|
base_path: ./src
|
|
- project_name: Billing
|
|
base_path: ./src
|
|
- project_name: Events
|
|
base_path: ./src
|
|
- project_name: EventsProcessor
|
|
base_path: ./src
|
|
- project_name: Icons
|
|
base_path: ./src
|
|
- project_name: Identity
|
|
base_path: ./src
|
|
- project_name: Notifications
|
|
base_path: ./src
|
|
- project_name: Server
|
|
base_path: ./util
|
|
- project_name: Setup
|
|
base_path: ./util
|
|
- project_name: Sso
|
|
base_path: ./bitwarden_license/src
|
|
node: true
|
|
- project_name: Scim
|
|
base_path: ./bitwarden_license/src
|
|
dotnet: true
|
|
steps:
|
|
- name: Checkout repo
|
|
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846
|
|
|
|
- name: Set up Node
|
|
uses: actions/setup-node@9ced9a43a244f3ac94f13bfd896db8c8f30da67a
|
|
with:
|
|
cache: "npm"
|
|
cache-dependency-path: "**/package-lock.json"
|
|
node-version: "16"
|
|
|
|
- name: Print environment
|
|
run: |
|
|
whoami
|
|
dotnet --info
|
|
node --version
|
|
npm --version
|
|
echo "GitHub ref: $GITHUB_REF"
|
|
echo "GitHub event: $GITHUB_EVENT"
|
|
|
|
- name: Restore/Clean project
|
|
working-directory: ${{ matrix.base_path }}/${{ matrix.project_name }}
|
|
run: |
|
|
echo "Restore"
|
|
dotnet restore
|
|
echo "Clean"
|
|
dotnet clean -c "Release" -o obj/build-output/publish
|
|
|
|
- name: Build node
|
|
if: ${{ matrix.node }}
|
|
working-directory: ${{ matrix.base_path }}/${{ matrix.project_name }}
|
|
run: |
|
|
npm ci
|
|
npm run build
|
|
|
|
- name: Publish project
|
|
working-directory: ${{ matrix.base_path }}/${{ matrix.project_name }}
|
|
run: |
|
|
echo "Publish"
|
|
dotnet publish -c "Release" -o obj/build-output/publish
|
|
|
|
cd obj/build-output/publish
|
|
zip -r ${{ matrix.project_name }}.zip .
|
|
mv ${{ matrix.project_name }}.zip ../../../
|
|
|
|
pwd
|
|
ls -atlh ../../../
|
|
|
|
- name: Upload project artifact
|
|
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535
|
|
with:
|
|
name: ${{ matrix.project_name }}.zip
|
|
path: ${{ matrix.base_path }}/${{ matrix.project_name }}/${{ matrix.project_name }}.zip
|
|
if-no-files-found: error
|
|
|
|
build-docker:
|
|
name: Build Docker images
|
|
runs-on: ubuntu-22.04
|
|
needs: build-artifacts
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- project_name: Admin
|
|
base_path: ./src
|
|
docker_repos: [bitwarden, bitwardenqa.azurecr.io]
|
|
dotnet: true
|
|
- project_name: Api
|
|
base_path: ./src
|
|
docker_repos: [bitwarden, bitwardenqa.azurecr.io]
|
|
dotnet: true
|
|
- project_name: Attachments
|
|
base_path: ./util
|
|
docker_repos: [bitwarden, bitwardenqa.azurecr.io]
|
|
- project_name: Events
|
|
base_path: ./src
|
|
docker_repos: [bitwarden, bitwardenqa.azurecr.io]
|
|
dotnet: true
|
|
- project_name: EventsProcessor
|
|
base_path: ./src
|
|
docker_repos: [bitwardenqa.azurecr.io]
|
|
dotnet: true
|
|
- project_name: Icons
|
|
base_path: ./src
|
|
docker_repos: [bitwarden, bitwardenqa.azurecr.io]
|
|
dotnet: true
|
|
- project_name: Identity
|
|
base_path: ./src
|
|
docker_repos: [bitwarden, bitwardenqa.azurecr.io]
|
|
dotnet: true
|
|
- project_name: MsSql
|
|
base_path: ./util
|
|
docker_repos: [bitwarden, bitwardenqa.azurecr.io]
|
|
- project_name: Nginx
|
|
base_path: ./util
|
|
docker_repos: [bitwarden, bitwardenqa.azurecr.io]
|
|
- project_name: Notifications
|
|
base_path: ./src
|
|
docker_repos: [bitwarden, bitwardenqa.azurecr.io]
|
|
dotnet: true
|
|
- project_name: Server
|
|
base_path: ./util
|
|
docker_repos: [bitwarden, bitwardenqa.azurecr.io]
|
|
dotnet: true
|
|
- project_name: Setup
|
|
base_path: ./util
|
|
docker_repos: [bitwarden, bitwardenqa.azurecr.io]
|
|
dotnet: true
|
|
- project_name: Sso
|
|
base_path: ./bitwarden_license/src
|
|
docker_repos: [bitwarden, bitwardenqa.azurecr.io]
|
|
dotnet: true
|
|
- project_name: Scim
|
|
base_path: ./bitwarden_license/src
|
|
docker_repos: [bitwarden, bitwardenqa.azurecr.io]
|
|
dotnet: true
|
|
- project_name: Billing
|
|
base_path: ./src
|
|
docker_repos: [bitwardenqa.azurecr.io]
|
|
dotnet: true
|
|
steps:
|
|
- name: Checkout repo
|
|
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846
|
|
|
|
########## Build Docker Image ##########
|
|
- name: Setup project name
|
|
id: setup
|
|
run: |
|
|
PROJECT_NAME=$(echo "${{ matrix.project_name }}" | awk '{print tolower($0)}')
|
|
echo "Matrix name: ${{ matrix.project_name }}"
|
|
echo "PROJECT_NAME: $PROJECT_NAME"
|
|
echo "project_name=$PROJECT_NAME" >> $GITHUB_OUTPUT
|
|
|
|
- name: Get build artifact
|
|
if: ${{ matrix.dotnet }}
|
|
uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741
|
|
with:
|
|
name: ${{ matrix.project_name }}.zip
|
|
|
|
- name: Setup build artifact
|
|
if: ${{ matrix.dotnet }}
|
|
run: |
|
|
mkdir -p ${{ matrix.base_path}}/${{ matrix.project_name }}/obj/build-output/publish
|
|
unzip ${{ matrix.project_name }}.zip \
|
|
-d ${{ matrix.base_path }}/${{ matrix.project_name }}/obj/build-output/publish
|
|
|
|
- name: Build Docker image
|
|
env:
|
|
PROJECT_NAME: ${{ steps.setup.outputs.project_name }}
|
|
run: docker build -t $PROJECT_NAME ${{ matrix.base_path }}/${{ matrix.project_name }}
|
|
|
|
########## ACR ##########
|
|
- name: Login to Azure - QA Subscription
|
|
uses: Azure/login@1f63701bf3e6892515f1b7ce2d2bf1708b46beaf
|
|
with:
|
|
creds: ${{ secrets.AZURE_QA_KV_CREDENTIALS }}
|
|
|
|
- name: Login to Azure ACR
|
|
run: az acr login -n bitwardenqa
|
|
|
|
- name: Tag and Push image to Azure ACR QA registry
|
|
env:
|
|
PROJECT_NAME: ${{ steps.setup.outputs.project_name }}
|
|
REGISTRY: bitwardenqa.azurecr.io
|
|
run: |
|
|
IMAGE_TAG=$(echo "${GITHUB_REF:11}" | sed "s#/#-#g") # slash safe branch name
|
|
if [[ "$IMAGE_TAG" == "master" ]]; then
|
|
IMAGE_TAG=dev
|
|
fi
|
|
|
|
docker tag $PROJECT_NAME \
|
|
$REGISTRY/$PROJECT_NAME:$IMAGE_TAG
|
|
docker push $REGISTRY/$PROJECT_NAME:$IMAGE_TAG
|
|
|
|
- name: Log out of Docker
|
|
run: docker logout
|
|
|
|
########## DockerHub ##########
|
|
- name: Login to Azure - Prod Subscription
|
|
if: |
|
|
contains(matrix.docker_repos, 'bitwarden')
|
|
&& (github.ref == 'refs/heads/master' ||
|
|
github.ref == 'refs/heads/rc' ||
|
|
github.ref == 'refs/heads/hotfix-rc')
|
|
uses: Azure/login@1f63701bf3e6892515f1b7ce2d2bf1708b46beaf
|
|
with:
|
|
creds: ${{ secrets.AZURE_PROD_KV_CREDENTIALS }}
|
|
|
|
- name: Retrieve secrets
|
|
if: |
|
|
contains(matrix.docker_repos, 'bitwarden')
|
|
&& (github.ref == 'refs/heads/master' ||
|
|
github.ref == 'refs/heads/rc' ||
|
|
github.ref == 'refs/heads/hotfix-rc')
|
|
id: retrieve-secrets
|
|
uses: bitwarden/gh-actions/get-keyvault-secrets@c3b3285993151c5af47cefcb3b9134c28ab479af
|
|
with:
|
|
keyvault: "bitwarden-prod-kv"
|
|
secrets: "docker-password,
|
|
docker-username,
|
|
dct-delegate-2-repo-passphrase,
|
|
dct-delegate-2-key"
|
|
|
|
- name: Log into Docker
|
|
if: |
|
|
contains(matrix.docker_repos, 'bitwarden')
|
|
&& (github.ref == 'refs/heads/master' ||
|
|
github.ref == 'refs/heads/rc' ||
|
|
github.ref == 'refs/heads/hotfix-rc')
|
|
env:
|
|
DOCKER_USERNAME: ${{ steps.retrieve-secrets.outputs.docker-username }}
|
|
DOCKER_PASSWORD: ${{ steps.retrieve-secrets.outputs.docker-password }}
|
|
run: echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
|
|
|
|
- name: Setup Docker Trust
|
|
if: |
|
|
contains(matrix.docker_repos, 'bitwarden')
|
|
&& (github.ref == 'refs/heads/master' ||
|
|
github.ref == 'refs/heads/rc' ||
|
|
github.ref == 'refs/heads/hotfix-rc')
|
|
env:
|
|
DCT_DELEGATION_KEY_ID: "c9bde8ec820701516491e5e03d3a6354e7bd66d05fa3df2b0062f68b116dc59c"
|
|
DCT_DELEGATE_KEY: ${{ steps.retrieve-secrets.outputs.dct-delegate-2-key }}
|
|
DCT_REPO_PASSPHRASE: ${{ steps.retrieve-secrets.outputs.dct-delegate-2-repo-passphrase }}
|
|
run: |
|
|
mkdir -p ~/.docker/trust/private
|
|
echo "$DCT_DELEGATE_KEY" > ~/.docker/trust/private/$DCT_DELEGATION_KEY_ID.key
|
|
echo "DOCKER_CONTENT_TRUST=1" >> $GITHUB_ENV
|
|
echo "DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE=$DCT_REPO_PASSPHRASE" >> $GITHUB_ENV
|
|
|
|
- name: Tag and Push RC to Docker Hub
|
|
if: |
|
|
contains(matrix.docker_repos, 'bitwarden')
|
|
&& (github.ref == 'refs/heads/master' ||
|
|
github.ref == 'refs/heads/rc' ||
|
|
github.ref == 'refs/heads/hotfix-rc')
|
|
env:
|
|
PROJECT_NAME: ${{ steps.setup.outputs.project_name }}
|
|
REGISTRY: bitwarden
|
|
run: |
|
|
IMAGE_TAG=$(echo "${GITHUB_REF:11}" | sed "s#/#-#g") # slash safe branch name
|
|
if [[ "$IMAGE_TAG" == "master" ]]; then
|
|
IMAGE_TAG=dev
|
|
fi
|
|
|
|
docker tag $PROJECT_NAME \
|
|
$REGISTRY/$PROJECT_NAME:$IMAGE_TAG
|
|
docker push $REGISTRY/$PROJECT_NAME:$IMAGE_TAG
|
|
|
|
- name: Log out of Docker and disable Docker Notary
|
|
if: |
|
|
contains(matrix.docker_repos, 'bitwarden')
|
|
&& (github.ref == 'refs/heads/master' ||
|
|
github.ref == 'refs/heads/rc' ||
|
|
github.ref == 'refs/heads/hotfix-rc')
|
|
run: |
|
|
docker logout
|
|
echo "DOCKER_CONTENT_TRUST=0" >> $GITHUB_ENV
|
|
|
|
upload:
|
|
name: Upload
|
|
runs-on: ubuntu-22.04
|
|
needs: build-docker
|
|
steps:
|
|
- name: Set up dotnet
|
|
uses: actions/setup-dotnet@9211491ffb35dd6a6657ca4f45d43dfe6e97c829
|
|
with:
|
|
dotnet-version: "6.0.x"
|
|
|
|
- name: Checkout repo
|
|
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846
|
|
|
|
- name: Restore
|
|
run: dotnet tool restore
|
|
|
|
- name: Make Docker stub
|
|
if: github.ref == 'refs/heads/master' ||
|
|
github.ref == 'refs/heads/rc' ||
|
|
github.ref == 'refs/heads/hotfix-rc'
|
|
run: |
|
|
if [[ "${{ github.ref }}" == "rc" ]]; then
|
|
SETUP_IMAGE="bitwarden/setup:rc"
|
|
elif [[ "${{ github.ref }}" == "hotfix-rc" ]]; then
|
|
SETUP_IMAGE="bitwarden/setup:hotfix-rc"
|
|
else
|
|
SETUP_IMAGE="bitwarden/setup:dev"
|
|
fi
|
|
|
|
STUB_OUTPUT=$(pwd)/docker-stub
|
|
docker run -i --rm --name setup -v $STUB_OUTPUT:/bitwarden $SETUP_IMAGE \
|
|
dotnet Setup.dll -stub 1 -install 1 -domain bitwarden.example.com -os lin
|
|
sudo chown -R $(whoami):$(whoami) $STUB_OUTPUT
|
|
rm -rf $STUB_OUTPUT/letsencrypt
|
|
rm $STUB_OUTPUT/env/uid.env $STUB_OUTPUT/config.yml
|
|
touch $STUB_OUTPUT/env/uid.env
|
|
cd docker-stub; zip -r ../docker-stub.zip *; cd ..
|
|
|
|
- name: Make Docker stub checksum
|
|
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/rc' || github.ref == 'refs/heads/hotfix-rc'
|
|
run: sha256sum docker-stub.zip > docker-stub-sha256.txt
|
|
|
|
- name: Upload Docker stub artifact
|
|
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/rc' || github.ref == 'refs/heads/hotfix-rc'
|
|
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535
|
|
with:
|
|
name: docker-stub.zip
|
|
path: docker-stub.zip
|
|
if-no-files-found: error
|
|
|
|
- name: Upload Docker stub checksum artifact
|
|
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/rc' || github.ref == 'refs/heads/hotfix-rc'
|
|
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535
|
|
with:
|
|
name: docker-stub-sha256.txt
|
|
path: docker-stub-sha256.txt
|
|
if-no-files-found: error
|
|
|
|
- name: Build Swagger
|
|
run: |
|
|
cd ./src/Api
|
|
echo "Restore"
|
|
dotnet restore
|
|
echo "Clean"
|
|
dotnet clean -c "Release" -o obj/build-output/publish
|
|
echo "Publish"
|
|
dotnet publish -c "Release" -o obj/build-output/publish
|
|
|
|
dotnet swagger tofile --output ../../swagger.json --host https://api.bitwarden.com \
|
|
./obj/build-output/publish/Api.dll public
|
|
cd ../..
|
|
env:
|
|
ASPNETCORE_ENVIRONMENT: Production
|
|
swaggerGen: "True"
|
|
DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX: 2
|
|
GLOBALSETTINGS__SQLSERVER__CONNECTIONSTRING: "placeholder"
|
|
|
|
- name: Upload Swagger artifact
|
|
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535
|
|
with:
|
|
name: swagger.json
|
|
path: swagger.json
|
|
if-no-files-found: error
|
|
|
|
check-failures:
|
|
name: Check for failures
|
|
if: always()
|
|
runs-on: ubuntu-22.04
|
|
needs:
|
|
- cloc
|
|
- lint
|
|
- testing
|
|
- build-artifacts
|
|
- build-docker
|
|
- upload
|
|
steps:
|
|
- name: Check if any job failed
|
|
if: |
|
|
github.ref == 'refs/heads/master'
|
|
|| github.ref == 'refs/heads/rc'
|
|
|| github.ref == 'refs/heads/hotfix-rc'
|
|
env:
|
|
CLOC_STATUS: ${{ needs.cloc.result }}
|
|
LINT_STATUS: ${{ needs.lint.result }}
|
|
TESTING_STATUS: ${{ needs.testing.result }}
|
|
BUILD_ARTIFACTS_STATUS: ${{ needs.build-artifacts.result }}
|
|
BUILD_DOCKER_STATUS: ${{ needs.build-docker.result }}
|
|
UPLOAD_STATUS: ${{ needs.upload.result }}
|
|
run: |
|
|
if [ "$CLOC_STATUS" = "failure" ]; then
|
|
exit 1
|
|
elif [ "$LINT_STATUS" = "failure" ]; then
|
|
exit 1
|
|
elif [ "$TESTING_STATUS" = "failure" ]; then
|
|
exit 1
|
|
elif [ "$BUILD_ARTIFACTS_STATUS" = "failure" ]; then
|
|
exit 1
|
|
elif [ "$BUILD_DOCKER_STATUS" = "failure" ]; then
|
|
exit 1
|
|
elif [ "$UPLOAD_STATUS" = "failure" ]; then
|
|
exit 1
|
|
fi
|
|
|
|
- name: Login to Azure - Prod Subscription
|
|
uses: Azure/login@1f63701bf3e6892515f1b7ce2d2bf1708b46beaf
|
|
if: failure()
|
|
with:
|
|
creds: ${{ secrets.AZURE_PROD_KV_CREDENTIALS }}
|
|
|
|
- name: Retrieve secrets
|
|
id: retrieve-secrets
|
|
uses: bitwarden/gh-actions/get-keyvault-secrets@c3b3285993151c5af47cefcb3b9134c28ab479af
|
|
if: failure()
|
|
with:
|
|
keyvault: "bitwarden-prod-kv"
|
|
secrets: "devops-alerts-slack-webhook-url"
|
|
|
|
- name: Notify Slack on failure
|
|
uses: act10ns/slack@da3191ebe2e67f49b46880b4633f5591a96d1d33
|
|
if: failure()
|
|
env:
|
|
SLACK_WEBHOOK_URL: ${{ steps.retrieve-secrets.outputs.devops-alerts-slack-webhook-url }}
|
|
with:
|
|
status: ${{ job.status }}
|