From a2deed2613643b24ee0b4e5ee9896d797ab0cb23 Mon Sep 17 00:00:00 2001 From: Kevin Hakanson Date: Mon, 12 Feb 2024 16:42:27 -0600 Subject: [PATCH] build: create build_and_test.yml workflow (#11) --- .github/workflows/build_and_test.yml | 78 ++++++++++++++++++++++++++++ Dockerfile | 14 ++++- 2 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/build_and_test.yml diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml new file mode 100644 index 0000000..cfe2fba --- /dev/null +++ b/.github/workflows/build_and_test.yml @@ -0,0 +1,78 @@ +name: Build and Test + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + workflow_dispatch: + +jobs: + build_and_test: + runs-on: ubuntu-latest + + steps: + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Install Node 18 + uses: actions/setup-node@v4 + with: + node-version: '18' + cache: 'npm' + + - name: Install XVFB for testing with VS Code + run: | + sudo apt-get -y update + sudo apt-get -y install --fix-missing xvfb + + - name: Update rust and install wasm-pack + run: | + rustup update stable && rustup default stable + npm install -g wasm-pack + + - name: Cache cargo build artifacts + # https://doc.rust-lang.org/cargo/guide/build-cache.html + uses: actions/cache@v4 + with: + path: | + vscode-cedar-wasm/target + key: cargo-build-cache-${{ hashFiles('vscode-cedar-wasm/Cargo.lock') }} + + - name: Build + run: | + npm ci + npm run wasm-build + npm run compile + + - name: Find VS Code stable release version + id: code-stable + run: | + echo "VSCODE_VERSION=`curl --silent https://update.code.visualstudio.com/api/releases/stable | jq -r '.[0]'`" >> "$GITHUB_OUTPUT" + + - name: Cache VS Code download + uses: actions/cache@v4 + with: + path: | + .vscode-test + key: vscode-test-cache-${{ steps.code-stable.outputs.VSCODE_VERSION }} + + - name: Test using VS Code + # commands before `xvfb-run -a npm run test` avoid these ERROR messages: + # - Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix") + # - Exiting GPU process due to errors during initialization + run: | + export XDG_RUNTIME_DIR=/run/user/$(id -u) + export DBUS_SESSION_BUS_ADDRESS=unix:path=$XDG_RUNTIME_DIR/bus + dbus-daemon --session --address=$DBUS_SESSION_BUS_ADDRESS --nofork --nopidfile --syslog-only & + mkdir ~/.vscode && echo '{ "disable-hardware-acceleration": true }' > ~/.vscode/argv.json + xvfb-run -a npm run test + + - name: Package VSIX + run: npm run package + + - name: Upload VSIX as a workflow artifact + uses: actions/upload-artifact@v4 + with: + name: vsix + path: ./*.vsix \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index a0fd754..96d52b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,10 +4,20 @@ RUN apt-get -y install --fix-missing xvfb RUN apt-get -y install libnss3 libatk1.0-0 libatk-bridge2.0-0 libgtk-3-0 libgbm-dev libasound2 RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y ENV PATH="/root/.cargo/bin:${PATH}" -RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh +ENV XDG_RUNTIME_DIR=/run/user/0 +ENV DBUS_SESSION_BUS_ADDRESS=unix:path=$XDG_RUNTIME_DIR/bus +RUN mkdir $XDG_RUNTIME_DIR && chmod 700 $XDG_RUNTIME_DIR && chown root:root $XDG_RUNTIME_DIR WORKDIR /src COPY <<-EOT /src/build.sh -npm install +# commands before `xvfb-run -a npm run test` avoid these ERROR messages: +# - Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix") +# - Exiting GPU process due to errors during initialization +service dbus start +dbus-daemon --session --address=$DBUS_SESSION_BUS_ADDRESS --nofork --nopidfile --syslog-only & +mkdir ~/.vscode && echo '{ "disable-hardware-acceleration": true }' > ~/.vscode/argv.json +# Build and Test +npm ci +npm install -g wasm-pack npm run wasm-build xvfb-run -a npm run test npm run package