Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEVOPS-1748] Build pipeline for C++ sdk #687

Merged
merged 68 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
bc72905
Add cpp schemas
michalchecinski Mar 29, 2024
d6db031
Add build cpp
michalchecinski Mar 29, 2024
77bb2e6
Upload artifact
michalchecinski Mar 29, 2024
9d4bb79
Add workflow dispatch trigger to build cpp
michalchecinski Mar 29, 2024
4531f5e
Fix
michalchecinski Apr 2, 2024
b88519e
Maybe fix
michalchecinski Apr 2, 2024
f8eba0b
Check install location
michalchecinski Apr 2, 2024
43f7453
Change path for includes
michalchecinski Apr 2, 2024
754ab88
Add matrix
michalchecinski Apr 2, 2024
04b8305
try to fix
michalchecinski Apr 2, 2024
a5b319c
Add difgferent deps installation for different oses
michalchecinski Apr 3, 2024
8fbf42f
Fix
michalchecinski Apr 3, 2024
fc9cfd0
Arror if no files found to upload
michalchecinski Apr 3, 2024
34539bd
Use conda for libs for windows
michalchecinski Apr 4, 2024
6f4dc51
Fix
michalchecinski Apr 4, 2024
6bf1b06
Fix windows paths
michalchecinski Apr 4, 2024
03271d5
Comment out arch64 macos build
michalchecinski Apr 4, 2024
fad1c72
Update artifact path in build-cpp.yml
michalchecinski Apr 4, 2024
5a66dc0
Fix maybe?
michalchecinski Apr 4, 2024
33d77a3
Add defaults bash
michalchecinski Apr 4, 2024
6a0fa30
Update C++ package name in build workflow
michalchecinski Apr 4, 2024
8cd57c0
ls include
michalchecinski Apr 4, 2024
1091107
Mabe fix
michalchecinski Apr 4, 2024
a923e2b
Fix
michalchecinski Apr 4, 2024
9f847e6
Update build-cpp.yml: Set target based on runner OS
michalchecinski Apr 5, 2024
9df66e1
Add artifact copying step to C++ build workflow
michalchecinski Apr 5, 2024
86bb6b0
Remove unnecessary 'ls include' command and add environment variables…
michalchecinski Apr 5, 2024
4ef3485
Update BOOST_INCLUDE_DIR and NLOHMANN_JSON_INCLUDE_DIR paths
michalchecinski Apr 5, 2024
8c8ca83
Change way of installing packages for windows
michalchecinski Apr 9, 2024
eb28ef5
Add list trees
michalchecinski Apr 11, 2024
cbe5d62
Add vcpkg.json for Bitwarden Secrets Manager SDK for C++
michalchecinski Apr 11, 2024
53ff5ec
Change command
michalchecinski Apr 11, 2024
042bd41
Use paths
michalchecinski Apr 11, 2024
f014cdb
Fix env variables
michalchecinski Apr 11, 2024
506e16f
remove commented stuff
michalchecinski Apr 11, 2024
7f5f2f7
Add another list
michalchecinski Apr 11, 2024
ed67e68
Change paths
michalchecinski Apr 11, 2024
445bf67
Fix target path in CMake configuration
michalchecinski Apr 11, 2024
d01966e
FIx
michalchecinski Apr 11, 2024
7d1c6d3
test attempted fix
Thomas-Avery Apr 11, 2024
ca302f6
run another test
Thomas-Avery Apr 11, 2024
48b80ea
testing again
Thomas-Avery Apr 11, 2024
cc6990c
Try using cache
michalchecinski Apr 12, 2024
690670a
Try to fix
michalchecinski Apr 12, 2024
a7d7a95
Maybe fix
michalchecinski Apr 15, 2024
1f11e50
Change path
michalchecinski Apr 15, 2024
49041f5
Maybe fix
michalchecinski Apr 15, 2024
636fe48
Add caching param
michalchecinski Apr 15, 2024
a82b202
List includes
michalchecinski Apr 16, 2024
bf0fcd9
Get acl
michalchecinski Apr 16, 2024
1529492
Add github actions cache
michalchecinski Apr 16, 2024
24e6ddb
Add cache save
michalchecinski Apr 16, 2024
6074481
Set permissions for include folder on Windows
michalchecinski Apr 16, 2024
54dab6c
Check if build fails or seeting paths
michalchecinski Apr 18, 2024
1cde15b
Comment out copy in cmake list
michalchecinski Apr 19, 2024
1de39a0
Fix library copy command in CMakeLists.txt
michalchecinski Apr 19, 2024
9e1800d
Add BUILD_TESTING=OFF flag to CMake configuration
michalchecinski Apr 19, 2024
977f79d
Fix dtarget
michalchecinski Apr 19, 2024
c6761cd
Update build-cpp.yml to exclude Windows-2022 target
michalchecinski Apr 24, 2024
b23a933
Add release-cpp.yml workflow for C++ SDK release
michalchecinski Apr 24, 2024
7d6315a
Add C++ SDKto version bump workflow
michalchecinski Apr 24, 2024
63e9194
Add portfile (not working yet)
michalchecinski Apr 24, 2024
6343ced
Remove sh512 hashes calc
michalchecinski May 8, 2024
c144e74
Change files to publish
michalchecinski May 8, 2024
7b4c668
Merge branch 'main' into DEVOPS-1748-Publish-Pipeline-for-C++-SDK
michalchecinski May 8, 2024
7f67c31
Remove portfile
michalchecinski May 8, 2024
8e505cc
Fix endline
michalchecinski May 8, 2024
c430694
Fix
michalchecinski May 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions .github/workflows/build-cpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
name: Build C++ SDK

on:
push:
branches:
- main
- rc
- hotfix-rc

pull_request:
workflow_dispatch:

jobs:
generate-schemas:
uses: ./.github/workflows/generate_schemas.yml

build_rust:
uses: ./.github/workflows/build-rust-cross-platform.yml

build:
name: Build for ${{ matrix.settings.os }} ${{ matrix.settings.target }}
needs:
- generate-schemas
- build_rust
runs-on: ${{ matrix.settings.os }}
strategy:
fail-fast: false
matrix:
settings:
- os: macos-12
target: x86_64-apple-darwin

# - os: windows-2022
# target: x86_64-pc-windows-msvc

- os: ubuntu-22.04
target: x86_64-unknown-linux-gnu

steps:
- name: Checkout Repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: install dependencies linux
if: runner.os == 'Linux'
run: |
sudo apt-get install -y nlohmann-json3-dev
sudo apt-get install -y libboost-all-dev

- name: install dependencies macos
if: runner.os == 'macOS'
run: |
brew install nlohmann-json
brew install boost

- name: Cache vcpkg
if: runner.os == 'Windows'
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: C:/vcpkg/
key: vcpkg-${{ runner.os }}-${{ matrix.settings.target }}
restore-keys: |
vcpkg-${{ runner.os }}-
vcpkg-

- name: Export GitHub Actions cache environment variables
if: runner.os == 'Windows'
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');

- name: Install libraries for Windows
if: runner.os == 'Windows' && steps.cache.outputs.cache-hit != 'true'
env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
run: |
vcpkg install boost --binarysource="clear;x-gha,readwrite"
vcpkg install nlohmann-json --binarysource="clear;x-gha,readwrite"
shell: pwsh

- name: Save cache
if: runner.os == 'Windows'
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: C:/vcpkg/
key: vcpkg-${{ runner.os }}-${{ matrix.settings.target }}

- name: Download schemas
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4
with:
name: sdk-schemas-cpp
path: languages/cpp/include

- name: Download ${{ matrix.settings.target }} files
uses: actions/download-artifact@eaceaf801fd36c7dee90939fad912460b18a1ffe # v4.1.2
with:
name: libbitwarden_c_files-${{ matrix.settings.target }}
path: languages/cpp/include

- name: Set permissions to include folder
if: runner.os == 'Windows'
shell: pwsh
run: |
Get-Acl languages/cpp/include/* | Format-List

$path = "./languages/cpp/include"
$name = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$acl = Get-Acl languages/cpp/include
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($name,"FullControl","Allow")
$acl.SetAccessRule($accessRule)
$acl | Set-Acl languages/cpp/include
Get-ChildItem -Path "$path" -Recurse -Force | Set-Acl -aclObject $acl -Verbose

Get-Acl languages/cpp/include/* | Format-List

- name: Build unix
working-directory: languages/cpp
if: runner.os == 'macOS' || runner.os == 'Linux'
run: |
if [[ '${{ runner.os }}' == 'macOS' ]]; then
export DNLOHMANN_PATH=/usr/local/opt/nlohmann-json
export DBOOST_PATH=/usr/local/opt/boost
export DTARGET=include/libbitwarden_c.dylib
fi

if [[ '${{ runner.os }}' == 'Linux' ]]; then
export DNLOHMANN_PATH=/usr/share/doc/nlohmann-json3-dev
export DBOOST_PATH=/usr/share/doc/libboost-all-dev
export DTARGET=include/libbitwarden_c.so
fi

mkdir build
cd build
cmake .. -DNLOHMANN=$DNLOHMANN_PATH -DBOOST=$DBOOST_PATH -DTARGET=$DTARGET
cmake --build .

- name: Build windows
if: runner.os == 'Windows'
working-directory: languages/cpp
env:
BOOST_INCLUDE_DIR: C:\vcpkg\installed\x64-windows\include\boost
NLOHMANN_JSON_INCLUDE_DIR: C:\vcpkg\installed\x64-windows\include\nlohmann-json
run: |
mkdir build
cd build
$DNLOHMANN_PATH="C:\vcpkg\installed\x64-windows\include\nlohmann-json"
$DBOOST_PATH="C:\vcpkg\installed\x64-windows\include\boost"
$DTARGET="include/libbitwarden_c.dll"
cmake .. -DNLOHMANN=$DNLOHMANN_PATH -DBOOST=$DBOOST_PATH -DTARGET="include/libbitwarden_c.dll" -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/languages/cpp/ -DBUILD_TESTING=OFF
cmake --build .
shell: pwsh

- name: Copy artifacts
working-directory: languages/cpp/build
run: |
mkdir artifacts
cp libbitwarden_c.* artifacts
cp libBitwardenClient.* artifacts

- name: Upload C++ package for ${{ matrix.settings.target }}
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: libbitwarden_cpp-${{ matrix.settings.target }}
path: languages/cpp/build/artifacts
if-no-files-found: error
7 changes: 7 additions & 0 deletions .github/workflows/generate_schemas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,10 @@ jobs:
name: sdk-schemas-java
path: ${{ github.workspace }}/languages/java/src/main/java/com/bitwarden/sdk/schema/*
if-no-files-found: error

- name: Upload cpp schemas artifact
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: sdk-schemas-cpp
path: ${{ github.workspace }}/languages/cpp/include/schemas.hpp
if-no-files-found: error
169 changes: 169 additions & 0 deletions .github/workflows/release-cpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
name: Release C++ SDK
run-name: Release C++ SDK ${{ inputs.release_type }}

on:
workflow_dispatch:
inputs:
release_type:
description: "Release Options"
required: true
default: "Release"
type: choice
options:
- Release
- Dry Run

env:
_KEY_VAULT: "bitwarden-ci"

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

- name: Branch check
if: ${{ inputs.release_type != 'Dry Run' }}
run: |
if [[ "$GITHUB_REF" != "refs/heads/rc" ]] && [[ "$GITHUB_REF" != "refs/heads/hotfix-rc" ]]; then
echo "==================================="
echo "[!] Can only release from the 'rc' or 'hotfix-rc' branches"
echo "==================================="
exit 1
fi

- name: Get version
id: version
run: |
VERSION=$(cat languages/cpp/vcpkg.json | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+")
echo "version=$VERSION" >> $GITHUB_OUTPUT

github-release:
name: GitHub Release
runs-on: ubuntu-22.04
needs:
- repo-sync
- validate
env:
_PKG_VERSION: ${{ needs.validate.outputs.version }}
steps:
- name: Login to Azure - Prod Subscription
uses: Azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 # v1.4.7
with:
creds: ${{ secrets.AZURE_CI_SERVICE_PRINCIPAL }}

- name: Retrieve secrets
id: retrieve-secrets
uses: bitwarden/gh-actions/get-keyvault-secrets@main
with:
keyvault: ${{ env._KEY_VAULT }}
secrets: "github-pat-bitwarden-devops-bot-repo-scope"

- name: Download x86_64-apple-darwin C artifact
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
skip_unpack: true

- name: Download aarch64-apple-darwin C artifact
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-aarch64-apple-darwin
skip_unpack: true

- name: Download x86_64-unknown-linux-gnu C artifact
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
skip_unpack: true

- name: Download x86_64-pc-windows-msvc C artifact
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
skip_unpack: true

- name: Rename C build artifacts
run: |
artifacts=("x86_64-apple-darwin" "aarch64-apple-darwin" "x86_64-unknown-linux-gnu" "x86_64-pc-windows-msvc") # aarch64-unknown-linux-gnu)
for value in "${artifacts[@]}"
do
unzip libbitwarden_c_files-$value.zip -d libbitwarden_c_files-$value
cd libbitwarden_c_files-$value
zip -Rj ../libbitwarden_c_files-$value-$_PKG_VERSION.zip 'libbitwarden_c.*'
cd ..
done

- name: Download schemas
uses: bitwarden/gh-actions/download-artifacts@main
with:
name: sdk-schemas-cpp
workflow: generate_schemas.yml
workflow_conclusion: success
branch: ${{ inputs.release_type == 'Dry Run' && 'main' || github.ref_name }}
artifacts: sdk-schemas-cpp
skip_unpack: true

- name: Rename schemas artifacts
run: mv sdk-schemas-cpp.zip sdk-schemas-cpp-$_PKG_VERSION.zip

- name: Download x86_64-apple-darwin C++ artifact
uses: bitwarden/gh-actions/download-artifacts@main
with:
workflow: build-cpp.yml
workflow_conclusion: success
branch: ${{ inputs.release_type == 'Dry Run' && 'main' || github.ref_name }}
artifacts: libbitwarden_cpp-x86_64-apple-darwin
skip_unpack: true

- name: Download x86_64-unknown-linux-gnu C++ artifact
uses: bitwarden/gh-actions/download-artifacts@main
with:
workflow: build-cpp.yml
workflow_conclusion: success
branch: ${{ inputs.release_type == 'Dry Run' && 'main' || github.ref_name }}
artifacts: libbitwarden_cpp-x86_64-unknown-linux-gnu
skip_unpack: true

- name: Rename C++ build artifacts
run: |
artifacts=("x86_64-apple-darwin" "x86_64-unknown-linux-gnu") # "x86_64-pc-windows-msvc" "aarch64-apple-darwin" "aarch64-unknown-linux-gnu")
for value in "${artifacts[@]}"
do
mv libbitwarden_cpp-$value.zip libbitwarden_cpp_files-$value-$_PKG_VERSION.zip
done

- name: Create release
if: ${{ inputs.release_type != 'Dry Run' }}
uses: ncipollo/release-action@6c75be85e571768fa31b40abf38de58ba0397db5 # v1.13.0
with:
tag: cpp-sdk-v${{ env._PKG_VERSION }}
name: "C++ SDK v${{ env._PKG_VERSION }}"
body: "<insert release notes here>"
token: ${{ steps.retrieve-secrets.outputs.github-pat-bitwarden-devops-bot-repo-scope }}
draft: true
repo: sdk
owner: bitwarden
artifacts: "libbitwarden_c_files-x86_64-apple-darwin-${{ env._PKG_VERSION }}.zip,
libbitwarden_c_files-aarch64-apple-darwin-${{ env._PKG_VERSION }}.zip,
libbitwarden_c_files-x86_64-unknown-linux-gnu-${{ env._PKG_VERSION }}.zip,
libbitwarden_c_files-x86_64-pc-windows-msvc-${{ env._PKG_VERSION }}.zip,
libbitwarden_cpp_files-x86_64-unknown-linux-gnu-${{ env._PKG_VERSION }}.zip,
libbitwarden_cpp_files-x86_64-apple-darwin-${{ env._PKG_VERSION }}.zip,
sdk-schemas-cpp-${{ env._PKG_VERSION }}.zip"
7 changes: 7 additions & 0 deletions .github/workflows/version-bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ on:
- go-sdk
- dotnet-sdk
- php-sdk
- cpp-sdk
version_number:
description: "New version (example: '2024.1.0')"
required: true
Expand Down Expand Up @@ -140,6 +141,12 @@ jobs:
run: |
sed -i 's/"version": "[0-9]\.[0-9]\.[0-9]"/"version": "${{ inputs.version_number }}"/' ./languages/php/composer.json

### cpp sdk
- name: Bump C++ SDK Version
if: ${{ inputs.project == 'cpp-sdk' }}
run: |
sed -i 's/"version": "[0-9]\.[0-9]\.[0-9]"/"version": "${{ inputs.version_number }}"/' ./languages/cpp/vcpkg.json

############################
# VERSION BUMP SECTION END #
############################
Expand Down
10 changes: 10 additions & 0 deletions languages/cpp/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "bitwarden-sdk-secrets",
"version": "0.1.0",
"homepage": "https://github.com/bitwarden/sdk/tree/languages/cpp",
"description": "Bitwarden Secrets Manager SDK for C++",
"dependencies": [
"boost",
"nlohmann-json"
]
}
Loading