diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d34cc11918..3249d91c60 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -109,6 +109,14 @@ jobs: env: DISABLE_INSPECT_FUSE: on SIGN_MACOS_SCRIPT: noop.sh + - name: Upload installer size + if: ${{ github.repository == 'signalapp/Signal-Desktop-Private' && github.ref == 'refs/heads/main' }} + run: | + node ts/scripts/dd-installer-size.js macos-arm64 + node ts/scripts/dd-installer-size.js macos-x64 + node ts/scripts/dd-installer-size.js macos-universal + env: + DD_API_KEY: ${{ secrets.DATADOG_API_KEY }} - name: Rebuild native modules for x64 run: npm run electron:install-app-deps - run: npm run test-release @@ -169,6 +177,12 @@ jobs: env: DISABLE_INSPECT_FUSE: on + - name: Upload installer size + if: ${{ github.repository == 'signalapp/Signal-Desktop-Private' && github.ref == 'refs/heads/main' }} + run: node ts/scripts/dd-installer-size.js linux + env: + DD_API_KEY: ${{ secrets.DATADOG_API_KEY }} + - run: xvfb-run --auto-servernum npm run test-node - run: xvfb-run --auto-servernum npm run test-electron timeout-minutes: 5 @@ -247,6 +261,12 @@ jobs: env: DISABLE_INSPECT_FUSE: on + - name: Upload installer size + if: ${{ github.repository == 'signalapp/Signal-Desktop-Private' && github.ref == 'refs/heads/main' }} + run: node ts/scripts/dd-installer-size.js windows + env: + DD_API_KEY: ${{ secrets.DATADOG_API_KEY }} + - run: npm run test-electron env: ARTIFACTS_DIR: artifacts/windows diff --git a/ts/scripts/dd-installer-size.ts b/ts/scripts/dd-installer-size.ts new file mode 100644 index 0000000000..91731b915d --- /dev/null +++ b/ts/scripts/dd-installer-size.ts @@ -0,0 +1,100 @@ +// Copyright 2024 Signal Messenger, LLC +// SPDX-License-Identifier: AGPL-3.0-only + +import { stat } from 'node:fs/promises'; +import { join } from 'node:path'; + +import { name as NAME, version as VERSION } from '../../package.json'; + +const SUPPORT_CONFIG = new Set([ + 'linux', + 'windows', + 'macos-arm64', + 'macos-x64', + 'macos-universal', +]); + +const RELEASE_DIR = join(__dirname, '..', '..', 'release'); + +async function main(): Promise { + const config = process.argv[2]; + if (!SUPPORT_CONFIG.has(config)) { + throw new Error(`Invalid argument: ${config}`); + } + + const { DD_API_KEY } = process.env; + if (DD_API_KEY == null) { + throw new Error('Missing DD_API_KEY env variable'); + } + + let fileName: string; + let platform: string; + let arch: string; + if (config === 'linux') { + fileName = `${NAME}_${VERSION}_amd64.deb`; + platform = 'linux'; + arch = 'x64'; + } else if (config === 'windows') { + fileName = `${NAME}-win-${VERSION}.exe`; + platform = 'windows'; + arch = 'x64'; + } else if (config === 'macos-arm64') { + fileName = `${NAME}-mac-arm64-${VERSION}.dmg`; + platform = 'macos'; + arch = 'arm64'; + } else if (config === 'macos-x64') { + fileName = `${NAME}-mac-x64-${VERSION}.dmg`; + platform = 'macos'; + arch = 'x64'; + } else if (config === 'macos-universal') { + fileName = `${NAME}-mac-universal-${VERSION}.dmg`; + platform = 'macos'; + arch = 'universal'; + } else { + throw new Error(`Unsupported config: ${config}`); + } + + const filePath = join(RELEASE_DIR, fileName); + const { size } = await stat(filePath); + + const res = await fetch('https://api.datadoghq.com/api/v2/series', { + method: 'POST', + headers: { + 'content-type': 'application/json', + 'DD-API-KEY': DD_API_KEY, + }, + body: JSON.stringify({ + series: [ + { + metric: 'desktop.ci.installerSize', + type: 0, + points: [ + { + timestamp: Math.floor(Date.now() / 1000), + value: size, + }, + ], + tags: [ + `hash:${process.env.GITHUB_SHA ?? ''}`, + `platform:${platform}`, + `arch:${arch}`, + ], + }, + ], + }), + }); + + if (!res.ok) { + throw new Error( + `Failed to submit metrics, status: ${res.status}, ` + + `body: ${await res.text()}` + ); + } + + console.log(`Submitted: ${size}`); +} + +main().catch(err => { + console.error('Failed', err); + process.exit(1); +});