From d95c35d122b308282ad16e1814fabc10367b0b8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren?= Date: Mon, 4 Dec 2023 14:00:13 +0100 Subject: [PATCH] Create GH Actions workflow to publish web-client to npm with provenance --- .github/workflows/npm_publish.yml | 41 +++++++++++++++++++++++++++++++ web-client/scripts/build.sh | 12 +++++++-- web-client/scripts/npm-publish.sh | 7 ------ 3 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/npm_publish.yml delete mode 100755 web-client/scripts/npm-publish.sh diff --git a/.github/workflows/npm_publish.yml b/.github/workflows/npm_publish.yml new file mode 100644 index 0000000000..b55b9571b7 --- /dev/null +++ b/.github/workflows/npm_publish.yml @@ -0,0 +1,41 @@ +name: Publish web-client to npm +on: + push: + branches: + - soeren/web-client-package-provenance + release: + types: [created] + workflow_dispatch: + +jobs: + build-and-publish: + runs-on: ubuntu-22.04 + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + targets: wasm32-unknown-unknown + - uses: Swatinem/rust-cache@v2 + - name: Install Protoc + run: sudo apt-get install protobuf-compiler + - uses: jetli/wasm-bindgen-action@v0.2.0 + with: + # Optional version of wasm-bindgen to install(eg. '0.2.83', 'latest') + version: 'latest' + - name: Build package + working-directory: ./web-client + run: ./scripts/build.sh + - uses: actions/setup-node@v3 + with: + node-version: '18.x' + registry-url: 'https://registry.npmjs.org' + - run: npm install -g npm + - name: Publish to npm + working-directory: ./web-client/dist + run: npm publish --tag next --provenance + env: + NODE_AUTH_TOKEN: ${{ secrets.SISOU_NPM_TOKEN }} diff --git a/web-client/scripts/build.sh b/web-client/scripts/build.sh index 533a81a986..085d086e46 100755 --- a/web-client/scripts/build.sh +++ b/web-client/scripts/build.sh @@ -40,8 +40,16 @@ function generate() { } # Prepare build environment -printf "Preparing build environment...\n" -cargo install wasm-bindgen-cli wasm-opt +if ! command -v wasm-bindgen &> /dev/null +then + printf "Installing wasm-bindgen...\n" + cargo install wasm-bindgen-cli +fi +if ! command -v wasm-opt &> /dev/null +then + printf "Installing wasm-opt...\n" + cargo install wasm-opt +fi # Primitives compile "primitives" diff --git a/web-client/scripts/npm-publish.sh b/web-client/scripts/npm-publish.sh deleted file mode 100755 index 56ff4974c5..0000000000 --- a/web-client/scripts/npm-publish.sh +++ /dev/null @@ -1,7 +0,0 @@ -set -e - -./scripts/build.sh - -cd dist -npm publish --tag next -cd ..