Attempt to fix broken envs during build (#11584)

This commit is contained in:
Paweł Grabarz 2024-11-21 19:39:57 +01:00 committed by GitHub
parent 7b0184993c
commit 0e31169782
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 76 additions and 50 deletions

View File

@ -196,9 +196,9 @@ jobs:
ENSO_CLOUD_GOOGLE_ANALYTICS_TAG: ${{ vars.ENSO_CLOUD_GOOGLE_ANALYTICS_TAG }}
ENSO_CLOUD_SENTRY_DSN: ${{ vars.ENSO_CLOUD_SENTRY_DSN }}
ENSO_CLOUD_STRIPE_KEY: ${{ vars.ENSO_CLOUD_STRIPE_KEY }}
ENSO_IDE_AG_GRID_LICENSE_KEY: ${{ vars.ENSO_AG_GRID_LICENSE_KEY }}
ENSO_IDE_MAPBOX_API_TOKEN: ${{ vars.ENSO_MAPBOX_API_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VITE_ENSO_AG_GRID_LICENSE_KEY: ${{ vars.ENSO_AG_GRID_LICENSE_KEY }}
VITE_ENSO_MAPBOX_API_TOKEN: ${{ vars.ENSO_MAPBOX_API_TOKEN }}
- if: failure() && runner.os == 'Windows'
name: List files if failed (Windows)
run: Get-ChildItem -Force -Recurse
@ -250,9 +250,9 @@ jobs:
ENSO_CLOUD_GOOGLE_ANALYTICS_TAG: ${{ vars.ENSO_CLOUD_GOOGLE_ANALYTICS_TAG }}
ENSO_CLOUD_SENTRY_DSN: ${{ vars.ENSO_CLOUD_SENTRY_DSN }}
ENSO_CLOUD_STRIPE_KEY: ${{ vars.ENSO_CLOUD_STRIPE_KEY }}
ENSO_IDE_AG_GRID_LICENSE_KEY: ${{ vars.ENSO_AG_GRID_LICENSE_KEY }}
ENSO_IDE_MAPBOX_API_TOKEN: ${{ vars.ENSO_MAPBOX_API_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VITE_ENSO_AG_GRID_LICENSE_KEY: ${{ vars.ENSO_AG_GRID_LICENSE_KEY }}
VITE_ENSO_MAPBOX_API_TOKEN: ${{ vars.ENSO_MAPBOX_API_TOKEN }}
- if: failure() && runner.os == 'Windows'
name: List files if failed (Windows)
run: Get-ChildItem -Force -Recurse
@ -305,9 +305,9 @@ jobs:
ENSO_CLOUD_GOOGLE_ANALYTICS_TAG: ${{ vars.ENSO_CLOUD_GOOGLE_ANALYTICS_TAG }}
ENSO_CLOUD_SENTRY_DSN: ${{ vars.ENSO_CLOUD_SENTRY_DSN }}
ENSO_CLOUD_STRIPE_KEY: ${{ vars.ENSO_CLOUD_STRIPE_KEY }}
ENSO_IDE_AG_GRID_LICENSE_KEY: ${{ vars.ENSO_AG_GRID_LICENSE_KEY }}
ENSO_IDE_MAPBOX_API_TOKEN: ${{ vars.ENSO_MAPBOX_API_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VITE_ENSO_AG_GRID_LICENSE_KEY: ${{ vars.ENSO_AG_GRID_LICENSE_KEY }}
VITE_ENSO_MAPBOX_API_TOKEN: ${{ vars.ENSO_MAPBOX_API_TOKEN }}
- if: failure() && runner.os == 'Windows'
name: List files if failed (Windows)
run: Get-ChildItem -Force -Recurse
@ -362,9 +362,9 @@ jobs:
ENSO_CLOUD_GOOGLE_ANALYTICS_TAG: ${{ vars.ENSO_CLOUD_GOOGLE_ANALYTICS_TAG }}
ENSO_CLOUD_SENTRY_DSN: ${{ vars.ENSO_CLOUD_SENTRY_DSN }}
ENSO_CLOUD_STRIPE_KEY: ${{ vars.ENSO_CLOUD_STRIPE_KEY }}
ENSO_IDE_AG_GRID_LICENSE_KEY: ${{ vars.ENSO_AG_GRID_LICENSE_KEY }}
ENSO_IDE_MAPBOX_API_TOKEN: ${{ vars.ENSO_MAPBOX_API_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VITE_ENSO_AG_GRID_LICENSE_KEY: ${{ vars.ENSO_AG_GRID_LICENSE_KEY }}
VITE_ENSO_MAPBOX_API_TOKEN: ${{ vars.ENSO_MAPBOX_API_TOKEN }}
- run: xvfb-run corepack pnpm -r --filter enso exec playwright test
env:
DEBUG: "pw:browser log:"
@ -435,9 +435,9 @@ jobs:
ENSO_CLOUD_GOOGLE_ANALYTICS_TAG: ${{ vars.ENSO_CLOUD_GOOGLE_ANALYTICS_TAG }}
ENSO_CLOUD_SENTRY_DSN: ${{ vars.ENSO_CLOUD_SENTRY_DSN }}
ENSO_CLOUD_STRIPE_KEY: ${{ vars.ENSO_CLOUD_STRIPE_KEY }}
ENSO_IDE_AG_GRID_LICENSE_KEY: ${{ vars.ENSO_AG_GRID_LICENSE_KEY }}
ENSO_IDE_MAPBOX_API_TOKEN: ${{ vars.ENSO_MAPBOX_API_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VITE_ENSO_AG_GRID_LICENSE_KEY: ${{ vars.ENSO_AG_GRID_LICENSE_KEY }}
VITE_ENSO_MAPBOX_API_TOKEN: ${{ vars.ENSO_MAPBOX_API_TOKEN }}
- run: corepack pnpm -r --filter enso exec playwright test
env:
DEBUG: "pw:browser log:"
@ -501,9 +501,9 @@ jobs:
ENSO_CLOUD_GOOGLE_ANALYTICS_TAG: ${{ vars.ENSO_CLOUD_GOOGLE_ANALYTICS_TAG }}
ENSO_CLOUD_SENTRY_DSN: ${{ vars.ENSO_CLOUD_SENTRY_DSN }}
ENSO_CLOUD_STRIPE_KEY: ${{ vars.ENSO_CLOUD_STRIPE_KEY }}
ENSO_IDE_AG_GRID_LICENSE_KEY: ${{ vars.ENSO_AG_GRID_LICENSE_KEY }}
ENSO_IDE_MAPBOX_API_TOKEN: ${{ vars.ENSO_MAPBOX_API_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VITE_ENSO_AG_GRID_LICENSE_KEY: ${{ vars.ENSO_AG_GRID_LICENSE_KEY }}
VITE_ENSO_MAPBOX_API_TOKEN: ${{ vars.ENSO_MAPBOX_API_TOKEN }}
WIN_CSC_KEY_PASSWORD: ${{ secrets.MICROSOFT_CODE_SIGNING_CERT_PASSWORD }}
WIN_CSC_LINK: ${{ secrets.MICROSOFT_CODE_SIGNING_CERT }}
- run: corepack pnpm -r --filter enso exec playwright test

View File

@ -392,9 +392,9 @@ jobs:
ENSO_CLOUD_GOOGLE_ANALYTICS_TAG: ${{ vars.ENSO_CLOUD_GOOGLE_ANALYTICS_TAG }}
ENSO_CLOUD_SENTRY_DSN: ${{ vars.ENSO_CLOUD_SENTRY_DSN }}
ENSO_CLOUD_STRIPE_KEY: ${{ vars.ENSO_CLOUD_STRIPE_KEY }}
ENSO_IDE_AG_GRID_LICENSE_KEY: ${{ vars.ENSO_AG_GRID_LICENSE_KEY }}
ENSO_IDE_MAPBOX_API_TOKEN: ${{ vars.ENSO_MAPBOX_API_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VITE_ENSO_AG_GRID_LICENSE_KEY: ${{ vars.ENSO_AG_GRID_LICENSE_KEY }}
VITE_ENSO_MAPBOX_API_TOKEN: ${{ vars.ENSO_MAPBOX_API_TOKEN }}
- if: failure() && runner.os == 'Windows'
name: List files if failed (Windows)
run: Get-ChildItem -Force -Recurse
@ -461,9 +461,9 @@ jobs:
ENSO_CLOUD_GOOGLE_ANALYTICS_TAG: ${{ vars.ENSO_CLOUD_GOOGLE_ANALYTICS_TAG }}
ENSO_CLOUD_SENTRY_DSN: ${{ vars.ENSO_CLOUD_SENTRY_DSN }}
ENSO_CLOUD_STRIPE_KEY: ${{ vars.ENSO_CLOUD_STRIPE_KEY }}
ENSO_IDE_AG_GRID_LICENSE_KEY: ${{ vars.ENSO_AG_GRID_LICENSE_KEY }}
ENSO_IDE_MAPBOX_API_TOKEN: ${{ vars.ENSO_MAPBOX_API_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VITE_ENSO_AG_GRID_LICENSE_KEY: ${{ vars.ENSO_AG_GRID_LICENSE_KEY }}
VITE_ENSO_MAPBOX_API_TOKEN: ${{ vars.ENSO_MAPBOX_API_TOKEN }}
- if: failure() && runner.os == 'Windows'
name: List files if failed (Windows)
run: Get-ChildItem -Force -Recurse
@ -528,9 +528,9 @@ jobs:
ENSO_CLOUD_GOOGLE_ANALYTICS_TAG: ${{ vars.ENSO_CLOUD_GOOGLE_ANALYTICS_TAG }}
ENSO_CLOUD_SENTRY_DSN: ${{ vars.ENSO_CLOUD_SENTRY_DSN }}
ENSO_CLOUD_STRIPE_KEY: ${{ vars.ENSO_CLOUD_STRIPE_KEY }}
ENSO_IDE_AG_GRID_LICENSE_KEY: ${{ vars.ENSO_AG_GRID_LICENSE_KEY }}
ENSO_IDE_MAPBOX_API_TOKEN: ${{ vars.ENSO_MAPBOX_API_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VITE_ENSO_AG_GRID_LICENSE_KEY: ${{ vars.ENSO_AG_GRID_LICENSE_KEY }}
VITE_ENSO_MAPBOX_API_TOKEN: ${{ vars.ENSO_MAPBOX_API_TOKEN }}
- if: failure() && runner.os == 'Windows'
name: List files if failed (Windows)
run: Get-ChildItem -Force -Recurse
@ -589,9 +589,9 @@ jobs:
ENSO_CLOUD_GOOGLE_ANALYTICS_TAG: ${{ vars.ENSO_CLOUD_GOOGLE_ANALYTICS_TAG }}
ENSO_CLOUD_SENTRY_DSN: ${{ vars.ENSO_CLOUD_SENTRY_DSN }}
ENSO_CLOUD_STRIPE_KEY: ${{ vars.ENSO_CLOUD_STRIPE_KEY }}
ENSO_IDE_AG_GRID_LICENSE_KEY: ${{ vars.ENSO_AG_GRID_LICENSE_KEY }}
ENSO_IDE_MAPBOX_API_TOKEN: ${{ vars.ENSO_MAPBOX_API_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VITE_ENSO_AG_GRID_LICENSE_KEY: ${{ vars.ENSO_AG_GRID_LICENSE_KEY }}
VITE_ENSO_MAPBOX_API_TOKEN: ${{ vars.ENSO_MAPBOX_API_TOKEN }}
WIN_CSC_KEY_PASSWORD: ${{ secrets.MICROSOFT_CODE_SIGNING_CERT_PASSWORD }}
WIN_CSC_LINK: ${{ secrets.MICROSOFT_CODE_SIGNING_CERT }}
- if: failure() && runner.os == 'Windows'

View File

@ -18,13 +18,21 @@ export async function readEnvironmentFromFile() {
const filePath = path.join(url.fileURLToPath(new URL('../..', import.meta.url)), fileName)
const buildInfo = await (async () => {
try {
return await import('../../../build.json', { with: { type: 'json' } })
const build = await import('../../../build.json', { with: { type: 'json' } })
// Handle importing json file regardless of CommonJS/ESM integation settings.
return 'default' in build ? build.default : build
} catch {
return { commit: '', version: '', engineVersion: '', name: '' }
}
})()
console.info('Build info: ' + JSON.stringify(buildInfo))
discardUndefinedEnv('ENSO_IDE_VERSION')
discardUndefinedEnv('ENSO_CLOUD_DASHBOARD_VERSION')
discardUndefinedEnv('ENSO_CLOUD_DASHBOARD_COMMIT_HASH')
try {
const file = await fs.readFile(filePath, { encoding: 'utf-8' })
console.info(`Reading environment from file: ${filePath}`)
/** @type {readonly (readonly [string, string])[]} */
let entries = file.split('\n').flatMap(line => {
if (/^\s*$|^.s*#/.test(line)) {
@ -36,10 +44,14 @@ export async function readEnvironmentFromFile() {
})
if (isProduction) {
entries = entries.filter(kv => {
const [k] = kv
return process.env[k] == null
const [k, v] = kv
return v !== 'undefined' && process.env[k] == null
})
}
const foundVars = entries.map(([k, _]) => k).join(', ')
console.info(`Found variables: ${foundVars}`)
const variables = Object.fromEntries(entries)
if (!isProduction || entries.length > 0) {
Object.assign(process.env, variables)
@ -52,6 +64,16 @@ export async function readEnvironmentFromFile() {
}
}
/**
* Discard environment variable value when is an "undefined" string.
* @param {string} name Name of an env variable.
*/
function discardUndefinedEnv(name) {
if (process.env[name] === 'undefined') {
delete process.env[name]
}
}
// ===============
// === globals ===
// ===============

2
app/gui/env.d.ts vendored
View File

@ -230,8 +230,6 @@ declare global {
// @ts-expect-error The index signature is intentional to disallow unknown env vars.
readonly ENSO_CLOUD_GOOGLE_ANALYTICS_TAG?: string
// @ts-expect-error The index signature is intentional to disallow unknown env vars.
readonly ENSO_CLOUD_DASHBOARD_VERSION?: string
// @ts-expect-error The index signature is intentional to disallow unknown env vars.
readonly ENSO_CLOUD_DASHBOARD_COMMIT_HASH?: string
// @ts-expect-error The index signature is intentional to disallow unknown env vars.
readonly ENSO_CLOUD_ENSO_HOST?: string

View File

@ -20,7 +20,8 @@ import { download } from '#/utilities/download'
import { getDownloadUrl, getLatestRelease } from '#/utilities/github'
import { startTransition, useState } from 'react'
const CURRENT_VERSION = process.env.ENSO_CLOUD_DASHBOARD_VERSION ?? 'unknown-dev'
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const CURRENT_VERSION: string = import.meta.env.ENSO_IDE_VERSION ?? 'unknown-dev'
const CURRENT_VERSION_IS_DEV = CURRENT_VERSION.endsWith('-dev')
const CURRENT_VERSION_IS_NIGHTLY = CURRENT_VERSION.includes('-nightly')
const CURRENT_VERSION_NUMBER = getVersionNumber(CURRENT_VERSION)

View File

@ -29,9 +29,9 @@ export default function AboutModal() {
['chromeVersion', window.versionInfo.chrome],
] as const)
: [
...(process.env.ENSO_CLOUD_DASHBOARD_VERSION == null ?
...(import.meta.env.ENSO_IDE_VERSION == null ?
[]
: ([['version', process.env.ENSO_CLOUD_DASHBOARD_VERSION]] as const)),
: ([['version', import.meta.env.ENSO_IDE_VERSION]] as const)),
...(process.env.ENSO_CLOUD_DASHBOARD_COMMIT_HASH == null ?
[]
: ([['build', process.env.ENSO_CLOUD_DASHBOARD_COMMIT_HASH]] as const)),

View File

@ -220,7 +220,7 @@ function supressCopy(event: KeyboardEvent) {
const { LicenseManager } = await import('ag-grid-enterprise')
if (typeof import.meta.env.VITE_ENSO_AG_GRID_LICENSE_KEY !== 'string') {
if (typeof import.meta.env.ENSO_IDE_AG_GRID_LICENSE_KEY !== 'string') {
console.warn('The AG_GRID_LICENSE_KEY is not defined.')
if (import.meta.env.DEV) {
// Hide annoying license validation errors in dev mode when the license is not defined. The
@ -240,7 +240,7 @@ if (typeof import.meta.env.VITE_ENSO_AG_GRID_LICENSE_KEY !== 'string') {
}
}
} else {
const agGridLicenseKey = import.meta.env.VITE_ENSO_AG_GRID_LICENSE_KEY
const agGridLicenseKey = import.meta.env.ENSO_IDE_AG_GRID_LICENSE_KEY
LicenseManager.setLicenseKey(agGridLicenseKey)
}

View File

@ -100,10 +100,10 @@ const props = defineProps<{ data: Data }>()
* Mapbox API access token.
* All the limits of API are listed here: https://docs.mapbox.com/api/#rate-limits
*/
const TOKEN = import.meta.env.VITE_ENSO_MAPBOX_API_TOKEN
const TOKEN = import.meta.env.ENSO_IDE_MAPBOX_API_TOKEN
if (TOKEN == null) {
console.warn(
'Mapbox API token is missing, to use Geo Map visualization please provide VITE_ENSO_MAPBOX_API_TOKEN.',
'Mapbox API token is missing, to use Geo Map visualization please provide ENSO_IDE_MAPBOX_API_TOKEN.',
)
}
const SCATTERPLOT_LAYER = 'Scatterplot_Layer'

View File

@ -28,7 +28,8 @@ const entrypoint =
// NOTE(Frizi): This rename is for the sake of forward compatibility with not yet merged config refactor on bazel branch,
// and because Vite's HTML env replacements only work with import.meta.env variables, not defines.
process.env.ENSO_IDE_VERSION = process.env.ENSO_CLOUD_DASHBOARD_VERSION
process.env.ENSO_IDE_VERSION ??= process.env.ENSO_CLOUD_DASHBOARD_VERSION
console.info(`Building IDE version: ${process.env.ENSO_IDE_VERSION}`)
const isCI = process.env.CI === 'true'

View File

@ -6,4 +6,4 @@ required-versions:
# NB. The Rust version is pinned in rust-toolchain.toml.
# NB. The Node version is pinned in .node-version.
cargo-watch: ^8.1.1
wasm-pack: ^0.12.1
wasm-pack: ">=0.12.1"

View File

@ -12,8 +12,8 @@ use crate::ci_gen::RunStepsBuilder;
use crate::ci_gen::RunnerType;
use crate::ci_gen::RELEASE_CLEANING_POLICY;
use crate::engine::env;
use crate::ide::web::env::VITE_ENSO_AG_GRID_LICENSE_KEY;
use crate::ide::web::env::VITE_ENSO_MAPBOX_API_TOKEN;
use crate::ide::web::env::ENSO_IDE_AG_GRID_LICENSE_KEY;
use crate::ide::web::env::ENSO_IDE_MAPBOX_API_TOKEN;
use ide_ci::actions::workflow::definition::cancel_workflow_action;
use ide_ci::actions::workflow::definition::shell;
@ -145,8 +145,8 @@ pub fn expose_cloud_vars(step: Step) -> Step {
/// Expose variables for the GUI build.
pub fn expose_gui_vars(step: Step) -> Step {
let step = step
.with_variable_exposed_as(ENSO_AG_GRID_LICENSE_KEY, VITE_ENSO_AG_GRID_LICENSE_KEY)
.with_variable_exposed_as(ENSO_MAPBOX_API_TOKEN, VITE_ENSO_MAPBOX_API_TOKEN);
.with_variable_exposed_as(ENSO_AG_GRID_LICENSE_KEY, ENSO_IDE_AG_GRID_LICENSE_KEY)
.with_variable_exposed_as(ENSO_MAPBOX_API_TOKEN, ENSO_IDE_MAPBOX_API_TOKEN);
// GUI includes the cloud-delivered dashboard.
expose_cloud_vars(step)

View File

@ -89,9 +89,9 @@ pub mod env {
// GUI-specific environment variables
define_env_var! {
/// License key for the AG Grid library.
VITE_ENSO_AG_GRID_LICENSE_KEY, String;
ENSO_IDE_AG_GRID_LICENSE_KEY, String;
/// The Mapbox API token for the GeoMap visualization.
VITE_ENSO_MAPBOX_API_TOKEN, String;
ENSO_IDE_MAPBOX_API_TOKEN, String;
}
}

View File

@ -292,7 +292,9 @@ impl Processor {
let context = self.context();
let target = self.target::<Target>();
let job = self.resolve_build_job(job);
let info = self.write_build_info_file();
async move {
info.await?;
let job = job.await?;
target?.build(context, job).await
}
@ -517,6 +519,16 @@ impl Processor {
.boxed()
}
pub fn write_build_info_file(&self) -> BoxFuture<'static, Result> {
let build_info_get = self.js_build_info();
let build_info_path = self.context.inner.repo_root.join(&*enso_build::ide::web::BUILD_INFO);
async move {
let build_info = build_info_get.await?;
build_info_path.write_as_json(&build_info)
}
.boxed()
}
pub fn handle_ide(&self, ide: arg::ide::Target) -> BoxFuture<'static, Result> {
match ide.command {
arg::ide::Command::Build { params } => self.build_ide(params).void_ok().boxed(),
@ -559,19 +571,11 @@ impl Processor {
sign_artifacts,
} = params;
let build_info_get = self.js_build_info();
let build_info_path = self.context.inner.repo_root.join(&*enso_build::ide::web::BUILD_INFO);
let build_info = async move {
let build_info = build_info_get.await?;
build_info_path.write_as_json(&build_info)
};
let info = self.write_build_info_file();
let gui = self.get(gui);
let input = ide::BuildInput {
gui: async move {
build_info.await?;
info.await?;
gui.await
}
.boxed(),