Skip to content

Commit

Permalink
Build and deploy to GitHub Pages from GitHub Actions.
Browse files Browse the repository at this point in the history
Change-Id: I4140492ee8ff367bbe65dd27f7dbd11f6fc7ad6f
Reviewed-on: https://code-review.googlesource.com/c/re2/+/62610
Reviewed-by: Alex Chernyakhovsky <[email protected]>
Reviewed-by: Paul Wankadia <[email protected]>
  • Loading branch information
junyer committed Jan 31, 2024
1 parent 9665465 commit 283636f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 33 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Pages
on:
workflow_dispatch:
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
container:
image: emscripten/emsdk
# Don't run as root within the container.
# Neither Git nor Bazel appreciates that.
# 1001 is the GitHub Actions runner user.
options: --init --user 1001
env:
BAZELISK_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Bazel fails if the username is unknown.
USER: runner
steps:
- uses: actions/checkout@v4
# TODO(junyer): Use `v2` whenever a new release is tagged.
- uses: bazelbuild/setup-bazelisk@6244971d4f7ba9aca943c2f3ede2bbd813fcca51
- run: app/build.sh
shell: bash
- uses: actions/upload-pages-artifact@v3
with:
path: app/deploy
deploy:
needs:
- build
permissions:
contents: read
# Needed for Pages deployment.
id-token: write
pages: write
environment: github-pages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/deploy-pages@v4
54 changes: 21 additions & 33 deletions app/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,29 @@ set -eux
SRCDIR=$(readlink --canonicalize $(dirname $0))
DSTDIR=$(mktemp --directory --tmpdir $(basename $0).XXXXXXXXXX)

BAZEL=/tmp/bazel
BAZELISK_RELEASE=v1.17.0

if [[ ${UID} -ne 0 ]]; then
if [[ -d deploy ]]; then
echo -e '\033[1;31m' "** The ${PWD}/deploy directory exists! Refusing to clobber it! **" '\033[0m'
exit 1
fi
mkdir deploy
sudo docker run -i -t --pull always --rm -v ${SRCDIR}/..:/src -v ${PWD}:/dst emscripten/emsdk /src/app/$(basename $0)
ls -l deploy
else
wget -O ${BAZEL} https://github.com/bazelbuild/bazelisk/releases/download/${BAZELISK_RELEASE}/bazelisk-linux-amd64
chmod +x ${BAZEL}

cd ${SRCDIR}
# Emscripten doesn't support `-fstack-protector`.
AR=emar CC=emcc \
${BAZEL} build --compilation_mode=opt \
--copt=-fno-stack-protector \
-- :all
cp ../bazel-bin/app/_re2.js ${DSTDIR}
# Clean up the sundry Bazel output directories.
${BAZEL} clean --expunge
cp app.ts index.html _re2.d.ts ${DSTDIR}
cp package.json rollup.config.js tsconfig.json ${DSTDIR}
cd ${SRCDIR}
# Emscripten doesn't support `-fstack-protector`.
AR=emar CC=emcc \
bazel build --compilation_mode=opt \
--copt=-fno-stack-protector \
-- :all
cp ../bazel-bin/app/_re2.js ${DSTDIR}
bazel clean --expunge
cp app.ts index.html _re2.d.ts ${DSTDIR}
cp package.json rollup.config.js tsconfig.json ${DSTDIR}

cd ${DSTDIR}
npm install
npx tsc
npx rollup -c rollup.config.js -d deploy
mv deploy/* /dst/deploy
fi
cd ${DSTDIR}
npm install
npx tsc
npx rollup -c rollup.config.js -d deploy

cd ${SRCDIR}
rm -rf ${DSTDIR}
mkdir deploy
cat >deploy/index.html <<EOF
<html><head><meta http-equiv="refresh" content="0; url=https://github.com/google/re2"></head><body></body></html>
EOF
mkdir deploy/app
cp ${DSTDIR}/deploy/* deploy/app
ls -lR deploy

exit 0

0 comments on commit 283636f

Please sign in to comment.