name: Build CLI on: pull_request: {} push: branches: - "main" - "rc" - "hotfix-rc" workflow_dispatch: {} permissions: contents: read jobs: cloc: name: CLOC runs-on: ubuntu-24.04 steps: - name: Checkout repo uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Set up CLOC run: | sudo apt update sudo apt -y install cloc - name: Print lines of code run: cloc --include-lang TypeScript,JavaScript,HTML,Sass,CSS --vcs git setup: name: Setup runs-on: ubuntu-24.04 outputs: package_version: ${{ steps.retrieve-version.outputs.package_version }} steps: - name: Checkout repo uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Get Package Version id: retrieve-version run: | PKG_VERSION=$(jq -r .version package.json) echo "package_version=$PKG_VERSION" >> $GITHUB_OUTPUT linux-cli: name: Build Linux CLI runs-on: ubuntu-24.04 needs: setup env: _PACKAGE_VERSION: ${{ needs.setup.outputs.package_version }} _PKG_FETCH_NODE_VERSION: 18.5.0 _PKG_FETCH_VERSION: 3.4 steps: - name: Checkout repo uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Set up Node uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 with: cache: 'npm' cache-dependency-path: '**/package-lock.json' node-version: '18' - name: Update NPM run: | npm install -g node-gyp node-gyp install $(node -v) - name: Get pkg-fetch run: | cd $HOME fetchedUrl="https://github.com/vercel/pkg-fetch/releases/download/v$_PKG_FETCH_VERSION/node-v$_PKG_FETCH_NODE_VERSION-linux-x64" mkdir -p .pkg-cache/v$_PKG_FETCH_VERSION wget $fetchedUrl -O "./.pkg-cache/v$_PKG_FETCH_VERSION/fetched-v$_PKG_FETCH_NODE_VERSION-linux-x64" - name: Keytar run: | keytarVersion=$(cat package.json | jq -r '.dependencies.keytar') keytarTar="keytar-v$keytarVersion-napi-v3-linux-x64.tar" keytarTarGz="$keytarTar.gz" keytarUrl="https://github.com/atom/node-keytar/releases/download/v$keytarVersion/$keytarTarGz" mkdir -p ./keytar/linux wget $keytarUrl -O ./keytar/linux/$keytarTarGz tar -xvf ./keytar/linux/$keytarTarGz -C ./keytar/linux - name: Install run: npm install - name: Package CLI run: npm run dist:cli:lin - name: Zip run: zip -j dist-cli/bwdc-linux-$_PACKAGE_VERSION.zip dist-cli/linux/bwdc keytar/linux/build/Release/keytar.node - name: Version Test run: | sudo apt-get update sudo apt install libsecret-1-0 dbus-x11 gnome-keyring eval $(dbus-launch --sh-syntax) eval $(echo -n "" | /usr/bin/gnome-keyring-daemon --login) eval $(/usr/bin/gnome-keyring-daemon --components=secrets --start) mkdir -p test/linux unzip ./dist-cli/bwdc-linux-$_PACKAGE_VERSION.zip -d ./test/linux testVersion=$(./test/linux/bwdc -v) echo "version: $_PACKAGE_VERSION" echo "testVersion: $testVersion" if [ "$testVersion" != "$_PACKAGE_VERSION" ]; then echo "Version test failed." exit 1 fi - name: Upload Linux Zip to GitHub uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 with: name: bwdc-linux-${{ env._PACKAGE_VERSION }}.zip path: ./dist-cli/bwdc-linux-${{ env._PACKAGE_VERSION }}.zip if-no-files-found: error macos-cli: name: Build Mac CLI runs-on: macos-13 needs: setup env: _PACKAGE_VERSION: ${{ needs.setup.outputs.package_version }} _PKG_FETCH_NODE_VERSION: 18.5.0 _PKG_FETCH_VERSION: 3.4 steps: - name: Checkout repo uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Set up Node uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 with: cache: 'npm' cache-dependency-path: '**/package-lock.json' node-version: '18' - name: Update NPM run: | npm install -g node-gyp node-gyp install $(node -v) - name: Get pkg-fetch run: | cd $HOME fetchedUrl="https://github.com/vercel/pkg-fetch/releases/download/v$_PKG_FETCH_VERSION/node-v$_PKG_FETCH_NODE_VERSION-macos-x64" mkdir -p .pkg-cache/v$_PKG_FETCH_VERSION wget $fetchedUrl -O "./.pkg-cache/v$_PKG_FETCH_VERSION/fetched-v$_PKG_FETCH_NODE_VERSION-macos-x64" - name: Keytar run: | keytarVersion=$(cat package.json | jq -r '.dependencies.keytar') keytarTar="keytar-v$keytarVersion-napi-v3-darwin-x64.tar" keytarTarGz="$keytarTar.gz" keytarUrl="https://github.com/atom/node-keytar/releases/download/v$keytarVersion/$keytarTarGz" mkdir -p ./keytar/macos wget $keytarUrl -O ./keytar/macos/$keytarTarGz tar -xvf ./keytar/macos/$keytarTarGz -C ./keytar/macos - name: Install run: npm install - name: Package CLI run: npm run dist:cli:mac - name: Zip run: zip -j dist-cli/bwdc-macos-$_PACKAGE_VERSION.zip dist-cli/macos/bwdc keytar/macos/build/Release/keytar.node - name: Version Test run: | mkdir -p test/macos unzip ./dist-cli/bwdc-macos-$_PACKAGE_VERSION.zip -d ./test/macos testVersion=$(./test/macos/bwdc -v) echo "version: $_PACKAGE_VERSION" echo "testVersion: $testVersion" if [ "$testVersion" != "$_PACKAGE_VERSION" ]; then echo "Version test failed." exit 1 fi - name: Upload Mac Zip to GitHub uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 with: name: bwdc-macos-${{ env._PACKAGE_VERSION }}.zip path: ./dist-cli/bwdc-macos-${{ env._PACKAGE_VERSION }}.zip if-no-files-found: error windows-cli: name: Build Windows CLI runs-on: windows-2022 needs: setup env: _PACKAGE_VERSION: ${{ needs.setup.outputs.package_version }} _WIN_PKG_FETCH_VERSION: 18.5.0 _WIN_PKG_VERSION: 3.4 steps: - name: Checkout repo uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Setup Windows builder run: | choco install checksum --no-progress choco install reshack --no-progress - name: Set up Node uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 with: cache: 'npm' cache-dependency-path: '**/package-lock.json' node-version: '18' - name: Update NPM run: | npm install -g node-gyp node-gyp install $(node -v) - name: Get pkg-fetch shell: pwsh run: | cd $HOME $fetchedUrl = "https://github.com/vercel/pkg-fetch/releases/download/v$env:_WIN_PKG_VERSION/node-v$env:_WIN_PKG_FETCH_VERSION-win-x64" New-Item -ItemType directory -Path ./.pkg-cache New-Item -ItemType directory -Path ./.pkg-cache/v$env:_WIN_PKG_VERSION Invoke-RestMethod -Uri $fetchedUrl ` -OutFile "./.pkg-cache/v$env:_WIN_PKG_VERSION/fetched-v$env:_WIN_PKG_FETCH_VERSION-win-x64" - name: Keytar shell: pwsh run: | $keytarVersion = (Get-Content -Raw -Path ./package.json | ConvertFrom-Json).dependencies.keytar $keytarTar = "keytar-v${keytarVersion}-napi-v3-{0}-x64.tar" $keytarTarGz = "${keytarTar}.gz" $keytarUrl = "https://github.com/atom/node-keytar/releases/download/v${keytarVersion}/${keytarTarGz}" New-Item -ItemType directory -Path ./keytar/windows | Out-Null Invoke-RestMethod -Uri $($keytarUrl -f "win32") -OutFile "./keytar/windows/$($keytarTarGz -f "win32")" 7z e "./keytar/windows/$($keytarTarGz -f "win32")" -o"./keytar/windows" 7z e "./keytar/windows/$($keytarTar -f "win32")" -o"./keytar/windows" - name: Setup Version Info shell: pwsh run: | $major, $minor, $patch = $env:_PACKAGE_VERSION.split('.') $versionInfo = @" 1 VERSIONINFO FILEVERSION $major,$minor,$patch,0 PRODUCTVERSION $major,$minor,$patch,0 FILEOS 0x40004 FILETYPE 0x1 { BLOCK "StringFileInfo" { BLOCK "040904b0" { VALUE "CompanyName", "Bitwarden Inc." VALUE "ProductName", "Bitwarden" VALUE "FileDescription", "Bitwarden Directory Connector CLI" VALUE "FileVersion", "$env:_PACKAGE_VERSION" VALUE "ProductVersion", "$env:_PACKAGE_VERSION" VALUE "OriginalFilename", "bwdc.exe" VALUE "InternalName", "bwdc" VALUE "LegalCopyright", "Copyright Bitwarden Inc." } } BLOCK "VarFileInfo" { VALUE "Translation", 0x0409 0x04B0 } } "@ $versionInfo | Out-File ./version-info.rc - name: Resource Hacker shell: cmd run: | set PATH=%PATH%;C:\Program Files (x86)\Resource Hacker set WIN_PKG=C:\Users\runneradmin\.pkg-cache\v%_WIN_PKG_VERSION%\fetched-v%_WIN_PKG_FETCH_VERSION%-win-x64 set WIN_PKG_BUILT=C:\Users\runneradmin\.pkg-cache\v%_WIN_PKG_VERSION%\built-v%_WIN_PKG_FETCH_VERSION%-win-x64 ResourceHacker -open %WIN_PKG% -save %WIN_PKG% -action delete -mask ICONGROUP,1, ResourceHacker -open version-info.rc -save version-info.res -action compile ResourceHacker -open %WIN_PKG% -save %WIN_PKG% -action addoverwrite -resource version-info.res - name: Install run: npm install - name: Package CLI run: npm run dist:cli:win - name: Zip shell: cmd run: 7z a .\dist-cli\bwdc-windows-%_PACKAGE_VERSION%.zip .\dist-cli\windows\bwdc.exe .\keytar\windows\keytar.node - name: Version Test shell: pwsh run: | Expand-Archive -Path "dist-cli\bwdc-windows-${{ env._PACKAGE_VERSION }}.zip" -DestinationPath "test\windows" $testVersion = Invoke-Expression '& .\test\windows\bwdc.exe -v' echo "version: ${env:_PACKAGE_VERSION}" echo "testVersion: $testVersion" if ($testVersion -ne ${env:_PACKAGE_VERSION}) { Throw "Version test failed." } - name: Upload Windows Zip to GitHub uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 with: name: bwdc-windows-${{ env._PACKAGE_VERSION }}.zip path: ./dist-cli/bwdc-windows-${{ env._PACKAGE_VERSION }}.zip if-no-files-found: error check-failures: name: Check for failures runs-on: ubuntu-24.04 needs: - cloc - setup - linux-cli - macos-cli - windows-cli steps: - name: Check if any job failed if: | (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/rc' || github.ref == 'refs/heads/hotfix-rc') && contains(needs.*.result, 'failure') run: exit 1 - name: Login to Azure - CI subscription uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0 if: failure() with: creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} - name: Retrieve secrets id: retrieve-secrets uses: bitwarden/gh-actions/get-keyvault-secrets@main if: failure() with: keyvault: "bitwarden-ci" secrets: "devops-alerts-slack-webhook-url" - name: Notify Slack on failure uses: act10ns/slack@44541246747a30eb3102d87f7a4cc5471b0ffb7d # v2.1.0 if: failure() env: SLACK_WEBHOOK_URL: ${{ steps.retrieve-secrets.outputs.devops-alerts-slack-webhook-url }} with: status: ${{ job.status }}