From 283636ffb2bc11ad2663deec732a9f1d34cbe41d Mon Sep 17 00:00:00 2001 From: Paul Wankadia Date: Wed, 31 Jan 2024 15:36:37 +0000 Subject: [PATCH] Build and deploy to GitHub Pages from GitHub Actions. Change-Id: I4140492ee8ff367bbe65dd27f7dbd11f6fc7ad6f Reviewed-on: https://code-review.googlesource.com/c/re2/+/62610 Reviewed-by: Alex Chernyakhovsky Reviewed-by: Paul Wankadia --- .github/workflows/pages.yml | 40 +++++++++++++++++++++++++++ app/build.sh | 54 +++++++++++++++---------------------- 2 files changed, 61 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/pages.yml diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 000000000..c6c7a5c34 --- /dev/null +++ b/.github/workflows/pages.yml @@ -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 diff --git a/app/build.sh b/app/build.sh index 09d931fcb..a46374446 100755 --- a/app/build.sh +++ b/app/build.sh @@ -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 +mkdir deploy/app +cp ${DSTDIR}/deploy/* deploy/app +ls -lR deploy exit 0