Update CLI workflows to be able to release from main branch (#1063) #890
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-13 | |
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@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
- 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@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 | |
with: | |
name: sdk-schemas-cpp | |
path: languages/cpp/include | |
- name: Download ${{ matrix.settings.target }} files | |
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 | |
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@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 | |
with: | |
name: libbitwarden_cpp-${{ matrix.settings.target }} | |
path: languages/cpp/build/artifacts | |
if-no-files-found: error |