Skip to content

Commit

Permalink
chore: use bazel-contrib/setup-bazel
Browse files Browse the repository at this point in the history
  • Loading branch information
lacolaco committed Jul 13, 2024
1 parent ab697d3 commit 5a1d946
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 32 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/adev-preview-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ on:

permissions: read-all

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

jobs:
adev-build:
runs-on: ubuntu-latest
Expand All @@ -35,6 +32,17 @@ jobs:
bazelisk-cache: true
disk-cache: true
repository-cache: true
bazelrc: |
# 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
# More details on failures
build --verbose_failures=true
# CI supports colors but Bazel does not detect it.
common --color=yes
- run: yarn install
- run: yarn build
- run: chmod 755 build/dist/bin/adev/build/browser
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/adev-preview-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,21 @@ jobs:
echo "COMMIT_HASH=$COMMIT_HASH" >> $GITHUB_ENV
working-directory: build/dist/bin/adev/build/browser
- run: echo $PR_NUMBER $COMMIT_HASH
- name: Deploy to cloudflare pages
run: npx wrangler publish ./ --project-name $CLOUDFLARE_PAGES_PROJECT --branch pr-$PR_NUMBER --commit-hash $COMMIT_HASH
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_PAGES_PROJECT: ${{ var.CLOUDFLARE_PAGES_PROJECT }}
- name: Comment on pull request
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = process.env.PR_NUMBER;
github.issues.createComment({
issue_number: ${{ github.event.workflow_run.head_branch }},
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Preview deployed to [Cloudflare Pages](https://pr-${prNumber}.dev-angular-jp.pages.dev)'
})

Check failure

Code scanning / CodeQL

Expression injection in Actions Critical

Potential injection from the ${{ github.event.workflow_run.head_branch }}, which may be controlled by an external user.
19 changes: 19 additions & 0 deletions .github/workflows/adev-production-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches:
- main

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

jobs:
adev-build:
runs-on: ubuntu-latest
Expand All @@ -16,6 +19,22 @@ jobs:
with:
node-version-file: '.node-version'
cache: yarn
- uses: bazel-contrib/[email protected]
with:
bazelisk-cache: true
disk-cache: true
repository-cache: true
bazelrc: |
# 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
# More details on failures
build --verbose_failures=true
# CI supports colors but Bazel does not detect it.
common --color=yes
- run: yarn install
- run: yarn build
- name: Deploy to cloudflare pages
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on: [pull_request]
permissions:
contents: read

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

jobs:
# test:
# runs-on: ubuntu-latest
Expand All @@ -31,6 +34,22 @@ jobs:
with:
node-version-file: '.node-version'
cache: yarn
- uses: bazel-contrib/[email protected]
with:
bazelisk-cache: true
disk-cache: true
repository-cache: true
bazelrc: |
# 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
# More details on failures
build --verbose_failures=true
# CI supports colors but Bazel does not detect it.
common --color=yes
- run: yarn install
- run: yarn build
# build-windows:
Expand Down
2 changes: 0 additions & 2 deletions tools/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { chalk, argv } from 'zx';
import {
applyPatches,
buildAdev,
setupBazelrc,
copyLocalizedFiles,
remove404HTML,
copyRobots,
Expand All @@ -31,7 +30,6 @@ try {

async function setup({ init }) {
await resetBuildDir({ init });
await setupBazelrc();
}

async function preBuild({ init }) {
Expand Down
28 changes: 1 addition & 27 deletions tools/lib/common.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { watch } from 'chokidar';
import { writeFile } from 'node:fs/promises';
import { resolve } from 'node:path';
import { $, cd, chalk, glob, os, within } from 'zx';
import { $, cd, chalk, glob, within } from 'zx';
import { cpRf, exists, initDir, rename, sed } from './fileutils.mjs';

const rootDir = resolve(__dirname, '../');
Expand All @@ -23,31 +22,6 @@ 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 5a1d946

Please sign in to comment.