mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-04 09:01:01 +01:00
419 lines
14 KiB
YAML
419 lines
14 KiB
YAML
---
|
|
name: Build CLI
|
|
|
|
on:
|
|
pull_request:
|
|
branches-ignore:
|
|
- 'l10n_master'
|
|
- 'cf-pages'
|
|
paths:
|
|
- 'apps/cli/**'
|
|
- 'libs/**'
|
|
- '*'
|
|
- '!*.md'
|
|
- '!*.txt'
|
|
- '.github/workflows/build-cli.yml'
|
|
push:
|
|
branches:
|
|
- 'master'
|
|
- 'rc'
|
|
- 'hotfix-rc-cli'
|
|
paths:
|
|
- 'apps/cli/**'
|
|
- 'libs/**'
|
|
- '*'
|
|
- '!*.md'
|
|
- '!*.txt'
|
|
- '.github/workflows/build-cli.yml'
|
|
workflow_dispatch:
|
|
inputs: {}
|
|
|
|
defaults:
|
|
run:
|
|
working-directory: apps/cli
|
|
|
|
jobs:
|
|
cloc:
|
|
name: CLOC
|
|
runs-on: ubuntu-22.04
|
|
steps:
|
|
- name: Checkout repo
|
|
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
|
|
|
|
- name: Set up cloc
|
|
run: |
|
|
sudo apt update
|
|
sudo apt -y install cloc
|
|
|
|
- name: Print lines of code
|
|
run: cloc --include-lang TypeScript,JavaScript --vcs git
|
|
|
|
|
|
setup:
|
|
name: Setup
|
|
runs-on: ubuntu-22.04
|
|
outputs:
|
|
package_version: ${{ steps.retrieve-version.outputs.package_version }}
|
|
steps:
|
|
- name: Checkout repo
|
|
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
|
|
|
|
- name: Get Package Version
|
|
id: retrieve-version
|
|
run: |
|
|
PKG_VERSION=$(jq -r .version package.json)
|
|
echo "package_version=$PKG_VERSION" >> $GITHUB_OUTPUT
|
|
|
|
|
|
cli:
|
|
name: Build CLI ${{ matrix.os }}
|
|
strategy:
|
|
matrix:
|
|
os: [ubuntu-22.04, macos-11]
|
|
runs-on: ${{ matrix.os }}
|
|
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@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
|
|
|
|
- name: Setup Unix Vars
|
|
run: |
|
|
echo "LOWER_RUNNER_OS=$(echo $RUNNER_OS | awk '{print tolower($0)}')" >> $GITHUB_ENV
|
|
echo "SHORT_RUNNER_OS=$(echo $RUNNER_OS | awk '{print substr($0, 1, 3)}' | \
|
|
awk '{print tolower($0)}')" >> $GITHUB_ENV
|
|
|
|
- name: Set up Node
|
|
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
|
with:
|
|
cache: 'npm'
|
|
cache-dependency-path: '**/package-lock.json'
|
|
node-version: '18'
|
|
|
|
- name: Install node-gyp
|
|
run: |
|
|
npm install -g node-gyp
|
|
node-gyp install $(node -v)
|
|
|
|
- name: Install
|
|
run: npm ci
|
|
working-directory: ./
|
|
|
|
- name: Build & Package Unix
|
|
run: npm run dist:${{ env.SHORT_RUNNER_OS }} --quiet
|
|
|
|
- name: Zip Unix
|
|
run: |
|
|
cd ./dist/${{ env.LOWER_RUNNER_OS }}
|
|
zip ../bw-${{ env.LOWER_RUNNER_OS }}-${{ env._PACKAGE_VERSION }}.zip ./bw
|
|
|
|
- name: Version Test
|
|
run: |
|
|
unzip "./dist/bw-${{ env.LOWER_RUNNER_OS }}-${{ env._PACKAGE_VERSION }}.zip" -d "./test"
|
|
testVersion=$(./test/bw -v)
|
|
echo "version: $_PACKAGE_VERSION"
|
|
echo "testVersion: $testVersion"
|
|
if [[ $testVersion != $_PACKAGE_VERSION ]]; then
|
|
echo "Version test failed."
|
|
exit 1
|
|
fi
|
|
|
|
- name: Create checksums Unix
|
|
run: |
|
|
cd ./dist
|
|
shasum -a 256 bw-${{ env.LOWER_RUNNER_OS }}-${{ env._PACKAGE_VERSION }}.zip \
|
|
| awk '{split($0, a); print a[1]}' > bw-${{ env.LOWER_RUNNER_OS }}-sha256-${{ env._PACKAGE_VERSION }}.txt
|
|
|
|
- name: Upload unix zip asset
|
|
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
|
|
with:
|
|
name: bw-${{ env.LOWER_RUNNER_OS }}-${{ env._PACKAGE_VERSION }}.zip
|
|
path: apps/cli/dist/bw-${{ env.LOWER_RUNNER_OS }}-${{ env._PACKAGE_VERSION }}.zip
|
|
if-no-files-found: error
|
|
|
|
- name: Upload unix checksum asset
|
|
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
|
|
with:
|
|
name: bw-${{ env.LOWER_RUNNER_OS }}-sha256-${{ env._PACKAGE_VERSION }}.txt
|
|
path: apps/cli/dist/bw-${{ env.LOWER_RUNNER_OS }}-sha256-${{ env._PACKAGE_VERSION }}.txt
|
|
if-no-files-found: error
|
|
|
|
cli-windows:
|
|
name: Build CLI Windows
|
|
runs-on: windows-2019
|
|
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@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
|
|
|
|
- name: Setup Windows builder
|
|
run: |
|
|
choco install checksum --no-progress
|
|
choco install reshack --no-progress
|
|
choco install nasm --no-progress
|
|
|
|
- name: Set up Node
|
|
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
|
with:
|
|
cache: 'npm'
|
|
cache-dependency-path: '**/package-lock.json'
|
|
node-version: '18'
|
|
|
|
- name: Install node-gyp
|
|
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: 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 CLI"
|
|
VALUE "FileVersion", "$env:_PACKAGE_VERSION"
|
|
VALUE "ProductVersion", "$env:_PACKAGE_VERSION"
|
|
VALUE "OriginalFilename", "bw.exe"
|
|
VALUE "InternalName", "bw"
|
|
VALUE "LegalCopyright", "Copyright Bitwarden Inc."
|
|
}
|
|
}
|
|
BLOCK "VarFileInfo"
|
|
{
|
|
VALUE "Translation", 0x0409 0x04B0
|
|
}
|
|
}
|
|
"@
|
|
$versionInfo | Out-File ./version-info.rc
|
|
# https://github.com/vercel/pkg-fetch/issues/188
|
|
|
|
- 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
|
|
copy %WIN_PKG% %WIN_PKG_BUILT%
|
|
ResourceHacker -open %WIN_PKG_BUILT% -save %WIN_PKG_BUILT% -action delete -mask ICONGROUP,1,
|
|
ResourceHacker -open version-info.rc -save version-info.res -action compile
|
|
ResourceHacker -open %WIN_PKG_BUILT% -save %WIN_PKG_BUILT% -action addoverwrite -resource version-info.res
|
|
|
|
- name: Install
|
|
run: npm ci
|
|
working-directory: ./
|
|
|
|
- name: Build & Package Windows
|
|
run: npm run dist:win --quiet
|
|
|
|
- name: Package Chocolatey
|
|
shell: pwsh
|
|
run: |
|
|
Copy-Item -Path stores/chocolatey -Destination dist/chocolatey -Recurse
|
|
Copy-Item dist/windows/bw.exe -Destination dist/chocolatey/tools
|
|
Copy-Item ${{ github.workspace }}/LICENSE.txt -Destination dist/chocolatey/tools
|
|
choco pack dist/chocolatey/bitwarden-cli.nuspec --version ${{ env._PACKAGE_VERSION }} --out dist/chocolatey
|
|
|
|
- name: Zip Windows
|
|
shell: cmd
|
|
run: 7z a ./dist/bw-windows-%_PACKAGE_VERSION%.zip ./dist/windows/bw.exe
|
|
|
|
- name: Version Test
|
|
run: |
|
|
dir ./dist/
|
|
Expand-Archive -Path "./dist/bw-windows-${env:_PACKAGE_VERSION}.zip" -DestinationPath "./test/windows"
|
|
$testVersion = Invoke-Expression '& ./test/windows/bw.exe -v'
|
|
echo "version: $env:_PACKAGE_VERSION"
|
|
echo "testVersion: $testVersion"
|
|
if($testVersion -ne $env:_PACKAGE_VERSION) {
|
|
Throw "Version test failed."
|
|
}
|
|
|
|
- name: Create checksums Windows
|
|
run: |
|
|
checksum -f="./dist/bw-windows-${env:_PACKAGE_VERSION}.zip" `
|
|
-t sha256 | Out-File -Encoding ASCII ./dist/bw-windows-sha256-${env:_PACKAGE_VERSION}.txt
|
|
|
|
- name: Upload windows zip asset
|
|
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
|
|
with:
|
|
name: bw-windows-${{ env._PACKAGE_VERSION }}.zip
|
|
path: apps/cli/dist/bw-windows-${{ env._PACKAGE_VERSION }}.zip
|
|
if-no-files-found: error
|
|
|
|
- name: Upload windows checksum asset
|
|
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
|
|
with:
|
|
name: bw-windows-sha256-${{ env._PACKAGE_VERSION }}.txt
|
|
path: apps/cli/dist/bw-windows-sha256-${{ env._PACKAGE_VERSION }}.txt
|
|
if-no-files-found: error
|
|
|
|
- name: Upload Chocolatey asset
|
|
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
|
|
with:
|
|
name: bitwarden-cli.${{ env._PACKAGE_VERSION }}.nupkg
|
|
path: apps/cli/dist/chocolatey/bitwarden-cli.${{ env._PACKAGE_VERSION }}.nupkg
|
|
if-no-files-found: error
|
|
|
|
- name: Upload NPM Build Directory asset
|
|
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
|
|
with:
|
|
name: bitwarden-cli-${{ env._PACKAGE_VERSION }}-npm-build.zip
|
|
path: apps/cli/build
|
|
if-no-files-found: error
|
|
|
|
snap:
|
|
name: Build Snap
|
|
runs-on: ubuntu-22.04
|
|
needs: [setup, cli]
|
|
env:
|
|
_PACKAGE_VERSION: ${{ needs.setup.outputs.package_version }}
|
|
steps:
|
|
- name: Checkout repo
|
|
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
|
|
|
|
- name: Print environment
|
|
run: |
|
|
whoami
|
|
echo "GitHub ref: $GITHUB_REF"
|
|
echo "GitHub event: $GITHUB_EVENT"
|
|
echo "BW Package Version: $_PACKAGE_VERSION"
|
|
|
|
- name: Get bw linux cli
|
|
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
|
|
with:
|
|
name: bw-linux-${{ env._PACKAGE_VERSION }}.zip
|
|
path: apps/cli/dist/snap
|
|
|
|
- name: Setup Snap Package
|
|
run: |
|
|
cp -r stores/snap/* -t dist/snap
|
|
sed -i s/__version__/${{ env._PACKAGE_VERSION }}/g dist/snap/snapcraft.yaml
|
|
cd dist/snap
|
|
ls -alth
|
|
|
|
- name: Build snap
|
|
uses: snapcore/action-build@2ee46bc29d163c9c836f2820cc46b39664bf0de2 # v1.1.3
|
|
with:
|
|
path: apps/cli/dist/snap
|
|
|
|
- name: Create checksum
|
|
run: |
|
|
cd dist/snap
|
|
ls -alth
|
|
sha256sum bw_${{ env._PACKAGE_VERSION }}_amd64.snap \
|
|
| awk '{split($0, a); print a[1]}' > bw-snap-sha256-${{ env._PACKAGE_VERSION }}.txt
|
|
|
|
- name: Install Snap
|
|
run: sudo snap install dist/snap/bw*.snap --dangerous
|
|
|
|
- name: Test Snap
|
|
shell: pwsh
|
|
run: |
|
|
$testVersion = Invoke-Expression '& bw -v'
|
|
if($testVersion -ne $env:_PACKAGE_VERSION) {
|
|
Throw "Version test failed."
|
|
}
|
|
env:
|
|
BITWARDENCLI_APPDATA_DIR: "/home/runner/snap/bw/x1/.config/Bitwarden CLI"
|
|
|
|
- name: Cleanup Test & Update Snap for Publish
|
|
shell: pwsh
|
|
run: sudo snap remove bw
|
|
|
|
- name: Upload snap asset
|
|
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
|
|
with:
|
|
name: bw_${{ env._PACKAGE_VERSION }}_amd64.snap
|
|
path: apps/cli/dist/snap/bw_${{ env._PACKAGE_VERSION }}_amd64.snap
|
|
if-no-files-found: error
|
|
|
|
- name: Upload snap checksum asset
|
|
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
|
|
with:
|
|
name: bw-snap-sha256-${{ env._PACKAGE_VERSION }}.txt
|
|
path: apps/cli/dist/snap/bw-snap-sha256-${{ env._PACKAGE_VERSION }}.txt
|
|
if-no-files-found: error
|
|
|
|
|
|
check-failures:
|
|
name: Check for failures
|
|
if: always()
|
|
runs-on: ubuntu-22.04
|
|
needs:
|
|
- cloc
|
|
- setup
|
|
- cli
|
|
- cli-windows
|
|
- snap
|
|
steps:
|
|
- name: Check if any job failed
|
|
working-directory: ${{ github.workspace }}
|
|
if: ${{ (github.ref == 'refs/heads/master') || (github.ref == 'refs/heads/rc') }}
|
|
env:
|
|
CLOC_STATUS: ${{ needs.cloc.result }}
|
|
SETUP_STATUS: ${{ needs.setup.result }}
|
|
CLI_STATUS: ${{ needs.cli.result }}
|
|
SNAP_STATUS: ${{ needs.snap.result }}
|
|
run: |
|
|
if [ "$CLOC_STATUS" = "failure" ]; then
|
|
exit 1
|
|
elif [ "$SETUP_STATUS" = "failure" ]; then
|
|
exit 1
|
|
elif [ "$CLI_STATUS" = "failure" ]; then
|
|
exit 1
|
|
elif [ "$SNAP_STATUS" = "failure" ]; then
|
|
exit 1
|
|
fi
|
|
|
|
- name: Login to Azure - Prod Subscription
|
|
uses: Azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 # v1.4.7
|
|
if: failure()
|
|
with:
|
|
creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }}
|
|
|
|
- name: Retrieve secrets
|
|
id: retrieve-secrets
|
|
if: failure()
|
|
uses: bitwarden/gh-actions/get-keyvault-secrets@67ab95d7a466bcefdedf3f93cbc10bcff436edfe
|
|
with:
|
|
keyvault: "bitwarden-ci"
|
|
secrets: "devops-alerts-slack-webhook-url"
|
|
|
|
- name: Notify Slack on failure
|
|
uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f # v2.0.0
|
|
if: failure()
|
|
env:
|
|
SLACK_WEBHOOK_URL: ${{ steps.retrieve-secrets.outputs.devops-alerts-slack-webhook-url }}
|
|
with:
|
|
status: ${{ job.status }}
|