From 560039fa3c0529de231f7c38aa114e4f14c4e653 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Sat, 6 Aug 2022 20:32:27 +0000 Subject: [PATCH] wasm-pack-plugin --- .woodpecker/tools-wasm-pack-docker.yml | 17 ------------ .woodpecker/tools-wasm-pack-plugin.yml | 25 +++++++++++++++++ tools/wasm-pack-docker/Dockerfile | 2 -- tools/wasm-pack-plugin/Dockerfile | 12 +++++++++ tools/wasm-pack-plugin/README.md | 20 ++++++++++++++ tools/wasm-pack-plugin/plugin.sh | 37 ++++++++++++++++++++++++++ 6 files changed, 94 insertions(+), 19 deletions(-) delete mode 100644 .woodpecker/tools-wasm-pack-docker.yml create mode 100644 .woodpecker/tools-wasm-pack-plugin.yml delete mode 100644 tools/wasm-pack-docker/Dockerfile create mode 100644 tools/wasm-pack-plugin/Dockerfile create mode 100644 tools/wasm-pack-plugin/README.md create mode 100755 tools/wasm-pack-plugin/plugin.sh diff --git a/.woodpecker/tools-wasm-pack-docker.yml b/.woodpecker/tools-wasm-pack-docker.yml deleted file mode 100644 index 664cb59..0000000 --- a/.woodpecker/tools-wasm-pack-docker.yml +++ /dev/null @@ -1,17 +0,0 @@ -pipeline: - build and publish: - image: plugins/docker - settings: - registry: git.koval.net - username: cyclane - password: - from_secret: DEPLOY_TOKEN - repo: git.koval.net/cyclane/game-algorithms/wasm-pack - tags: latest - context: tools/wasm-pack-docker - dockerfile: tools/wasm-pack-docker/Dockerfile - when: - path: - include: - - tools/wasm-pack-docker/Dockerfile - - .woodpecker/tools-wasm-pack-docker.yml \ No newline at end of file diff --git a/.woodpecker/tools-wasm-pack-plugin.yml b/.woodpecker/tools-wasm-pack-plugin.yml new file mode 100644 index 0000000..12041fa --- /dev/null +++ b/.woodpecker/tools-wasm-pack-plugin.yml @@ -0,0 +1,25 @@ +clone: + git: + image: woodpeckerci/plugin-git + when: + path: + include: + - tools/wasm-pack-plugin/Dockerfile + - .woodpecker/tools-wasm-pack-plugin.yml +pipeline: + build and publish: + image: plugins/docker + settings: + registry: git.koval.net + username: cyclane + password: + from_secret: DEPLOY_TOKEN + repo: git.koval.net/cyclane/game-algorithms/wasm-pack-plugin + tags: latest + context: tools/wasm-pack-plugin + dockerfile: tools/wasm-pack-plugin/Dockerfile + when: + path: + include: + - tools/wasm-pack-plugin/* + - .woodpecker/tools-wasm-pack-plugin.yml \ No newline at end of file diff --git a/tools/wasm-pack-docker/Dockerfile b/tools/wasm-pack-docker/Dockerfile deleted file mode 100644 index cacba42..0000000 --- a/tools/wasm-pack-docker/Dockerfile +++ /dev/null @@ -1,2 +0,0 @@ -FROM rust -RUN cargo install wasm-pack \ No newline at end of file diff --git a/tools/wasm-pack-plugin/Dockerfile b/tools/wasm-pack-plugin/Dockerfile new file mode 100644 index 0000000..11b5808 --- /dev/null +++ b/tools/wasm-pack-plugin/Dockerfile @@ -0,0 +1,12 @@ +FROM rust:alpine + +RUN apk add --no-cache \ + npm \ + musl-dev \ + make \ + && cargo install wasm-pack \ + && rustup target add wasm32-unknown-unknown + +COPY plugin.sh /plugin.sh + +ENTRYPOINT ["/plugin.sh"] \ No newline at end of file diff --git a/tools/wasm-pack-plugin/README.md b/tools/wasm-pack-plugin/README.md new file mode 100644 index 0000000..1793c1e --- /dev/null +++ b/tools/wasm-pack-plugin/README.md @@ -0,0 +1,20 @@ +# wasm-pack plugin + +This is a drone/woodpecker plugin for building and publishing wasm-pack packages. + +## Settings + +- `actions` (required): Actions (see below) to run +- `folder`: Project folder +- `scope`: NPM package scope + +### Build + +- `build_profile` (default=`release`): Build profile to use for `wasm-pack build` +- `make`: Optionally run a make target building + +### Publish + +- `username` (required): NPM registry username +- `token` (required): NPM registry auth token (secret recommended) +- `registry` (default=`https://registry.npmjs.org`): NPM registry to publish to diff --git a/tools/wasm-pack-plugin/plugin.sh b/tools/wasm-pack-plugin/plugin.sh new file mode 100755 index 0000000..8eec291 --- /dev/null +++ b/tools/wasm-pack-plugin/plugin.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +# Properties: actions +# username, token, registry=https://registry.npmjs.org, scope, folder=. +# build_profile=release, make + +# publish: username, token +# build: + +set -eu + +cd ${PLUGIN_FOLDER:-.} + +if [[ "${PLUGIN_ACTIONS}" =~ '(^|,)build(,|$)' ]]; then + if [ "${PLUGIN_SCOPE:-}" = "" ]; then + wasm-pack build --${PLUGIN_BUILD_PROFILE:-release} + else + wasm-pack build --${PLUGIN_BUILD_PROFILE:-release} --scope ${PLUGIN_SCOPE} + fi + + if [ "${PLUGIN_MAKE:-}" != ""]; then + make ${PLUGIN_MAKE} + fi +fi + +if [[ "${PLUGIN_ACTIONS}" =~ '(^|,)publish(,|$)' ]]; then + REGISTY=${PLUGIN_REGISTRY:-https://registry.npmjs.org/} + + if [ "${PLUGIN_SCOPE:-}" = "" ]; then + npm config set registry ${REGISTRY} + else + npm config set ${PLUGIN_SCOPE}:registry ${REGISTRY} + fi + + npm config set -- $(echo ${REGISTRY} | sed -Ee "s/^https?://"):_authToken "${PLUGIN_TOKEN}" + npm publish +fi \ No newline at end of file