Skip to content

Commit

Permalink
chore: use bazel repo cache
Browse files Browse the repository at this point in the history
  • Loading branch information
lacolaco committed Jul 13, 2024
1 parent acbb8d3 commit a99e93b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/adev-preview-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:

permissions: read-all

env:
BAZEL_REPO_CACHE_PATH: '~/.cache/bazel_repo_cache'

jobs:
adev-build:
runs-on: ubuntu-latest
Expand All @@ -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
Expand Down
24 changes: 14 additions & 10 deletions tools/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { chalk, argv } from 'zx';
import {
applyPatches,
buildAdev,
setupBazelrc,
copyLocalizedFiles,
remove404HTML,
copyRobots,
Expand All @@ -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 ===='));
Expand All @@ -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() {
Expand Down
30 changes: 28 additions & 2 deletions tools/lib/common.mjs
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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}`);
Expand Down

0 comments on commit a99e93b

Please sign in to comment.