diff --git a/.github/workflows/adev-preview-build.yml b/.github/workflows/adev-preview-build.yml index fd142ac98..c13ce4384 100644 --- a/.github/workflows/adev-preview-build.yml +++ b/.github/workflows/adev-preview-build.yml @@ -13,6 +13,9 @@ on: permissions: read-all +env: + BAZEL_REPO_CACHE_PATH: '~/.cache/bazel_repo_cache' + jobs: adev-build: runs-on: ubuntu-latest @@ -27,6 +30,12 @@ jobs: with: node-version-file: '.node-version' cache: yarn + - uses: actions/cache@v4 + with: + path: ${{ env.BAZEL_REPO_CACHE_PATH }} + key: bazel-repo-cache-${{ runner.os }}-${{ hashFiles('origin/WORKSPACE') }} + restore-keys: | + bazel-repo-cache-${{ runner.os }}- - run: yarn install - run: yarn build - run: chmod 755 build/dist/bin/adev/build/browser diff --git a/tools/build.mjs b/tools/build.mjs index cb1c5ddba..2e6eaf26f 100644 --- a/tools/build.mjs +++ b/tools/build.mjs @@ -4,6 +4,7 @@ import { chalk, argv } from 'zx'; import { applyPatches, buildAdev, + setupBazelrc, copyLocalizedFiles, remove404HTML, copyRobots, @@ -16,9 +17,9 @@ const { init = true } = argv; try { console.log(chalk.green('==== setup ====')); - await setup(init); + await setup({ init }); console.log(chalk.green('==== preBuild ====')); - await preBuild(); + await preBuild({ init }); console.log(chalk.green('==== build ====')); await build(); console.log(chalk.green('==== postBuild ====')); @@ -28,18 +29,21 @@ try { process.exit(1); } -async function setup(init) { +async function setup({ init }) { await resetBuildDir({ init }); + await setupBazelrc(); } -async function preBuild() { - // copy translated files - // console.log(chalk.cyan('Copy localized files...')); - // await copyLocalizedFiles(); +async function preBuild({ init }) { + if (init) { + // copy translated files + // console.log(chalk.cyan('Copy localized files...')); + // await copyLocalizedFiles(); - // apply patches - console.log(chalk.cyan('Apply patches...')); - await applyPatches(); + // apply patches + console.log(chalk.cyan('Apply patches...')); + await applyPatches(); + } } async function build() { diff --git a/tools/lib/common.mjs b/tools/lib/common.mjs index 6cac3bfca..efd75ebe1 100644 --- a/tools/lib/common.mjs +++ b/tools/lib/common.mjs @@ -1,7 +1,8 @@ import { watch } from 'chokidar'; +import { writeFile } from 'node:fs/promises'; import { resolve } from 'node:path'; -import { $, cd, chalk, glob, within } from 'zx'; -import { initDir, cpRf, exists, sed, rmrf, rename } from './fileutils.mjs'; +import { $, cd, chalk, glob, os, within } from 'zx'; +import { cpRf, exists, initDir, rename, sed } from './fileutils.mjs'; const rootDir = resolve(__dirname, '../'); const aiojaDir = resolve(rootDir, 'aio-ja'); @@ -22,6 +23,31 @@ export async function resetBuildDir({ init = false }) { } } +export async function setupBazelrc() { + await within(async () => { + const cachePath = process.env.BAZEL_REPO_CACHE_PATH || resolve(os.homedir(), '.cache/bazel_repo_cache'); + const escapedCachePath = cachePath.replace(/\\/g, '\\\\'); + + cd(`${outDir}`); + const bazelrcContent = ` + # Print all the options that apply to the build. + # This helps us diagnose which options override others + # (e.g. /etc/bazel.bazelrc vs. tools/bazel.rc) + build --announce_rc + + # Avoids re-downloading NodeJS/browsers all the time. + build --repository_cache=${escapedCachePath} + + # More details on failures + build --verbose_failures=true + + # CI supports colors but Bazel does not detect it. + common --color=yes +`; + await writeFile('.bazelrc.user', bazelrcContent); + }); +} + export async function buildAdev() { await within(async () => { cd(`${outDir}`);