CI: Build and publish #7

Merged
lsr merged 14 commits from temp/ci-work into main 2024-09-24 21:31:21 +00:00
7 changed files with 111 additions and 6 deletions

38
.drone.yml Normal file
View File

@ -0,0 +1,38 @@
kind: pipeline
type: docker
name: default
when:
event:
- push
- pull_request
- tag
steps:
- name: test
image: rust:1.81-bookworm
commands:
- cargo test --verbose --all
- name: build (wasm_pack)
image: rust:1.81-bookworm
commands:
- curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- (cd um_wasm && wasm-pack build --release --target web --out-dir ../um_wasm_loader/pkg)
- name: build (node)
image: node:22.9-bookworm
environment:
NPM_TOKEN:
from_secret: NPM_TOKEN
COREPACK_ENABLE_AUTO_PIN: 0
BUILD_SKIP_WASM_PACK: 1
depends_on:
- "build (wasm_pack)"
commands:
- corepack enable
- cd um_wasm_loader
- pnpm i
- pnpm build
- ./ci_publish.sh

1
.gitignore vendored
View File

@ -2,4 +2,5 @@ target/
pkg/
pkg-*/
node_modules/
.pnpm-store
*.local

18
Dockerfile Normal file
View File

@ -0,0 +1,18 @@
FROM rust:1.81-bookworm
RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
ARG uid=1998
ARG gid=1998
RUN groupadd -g "$gid" builder \
&& useradd -u "$uid" -g "$gid" -m -d /h builder
USER builder
RUN curl -fsL https://get.pnpm.io/install.sh | ENV="$HOME/.bashrc" SHELL="$(which bash)" bash -
RUN git config --global --add safe.directory /a
ENV PATH="/h/.local/share/pnpm:$PATH"
WORKDIR /a
CMD ["/usr/bin/sleep", "infinity"]

35
build.sh Executable file
View File

@ -0,0 +1,35 @@
#!/bin/bash -ex
docker volume create umc_rust_cache
docker volume create umc_rust_pnpm_cache
docker volume create umc_rust_target_cache
docker volume create umc_pnpm_loader_cache
docker buildx build --build-arg uid="$(id -u)" --build-arg gid="$(id -g)" -t umc_rust .
run_container() {
docker run -d \
-v umc_rust_cache:/h/.cargo \
-v "${PWD}:/a" \
-v umc_rust_pnpm_cache:/a/.pnpm-store \
-v umc_rust_target_cache:/a/target \
-v umc_pnpm_loader_cache:/a/um_wasm_loader/node_modules \
umc_rust
}
umc_rust_id="$(run_container)"
docker exec -i -u root "${umc_rust_id}" chown "$(id -u):$(id -g)" \
/h/.cargo \
/a/.pnpm-store \
/a/target \
/a/um_wasm_loader/node_modules
docker exec -i "${umc_rust_id}" bash <<'EOF'
export npm_config_use_node_version=22.9.0
cd um_wasm_loader
pnpm --package-import-method=copy i
pnpm build
pnpm pack
EOF
docker stop "${umc_rust_id}"
docker rm -f "${umc_rust_id}"

View File

@ -77,12 +77,15 @@ async function main() {
const wasmSourceDir = path.join(__dirname, '..', 'um_wasm');
const wasmOutDir = path.resolve(__dirname, 'pkg');
const wasmDistDir = path.resolve(__dirname, 'dist');
await rm(wasmOutDir, { recursive: true, force: true });
const wasmRelOutDir = path.relative(wasmSourceDir, wasmOutDir);
const profileFlag = parseBoolean(process.env.BUILD_RELEASE, true) ? '--release' : '--dev';
await run(['wasm-pack', 'build', profileFlag, '--target', 'web', '--out-dir', wasmRelOutDir], {
cwd: path.resolve(__dirname, '..', 'um_wasm'),
});
if (process.env.BUILD_SKIP_WASM_PACK !== '1') {
await rm(wasmOutDir, { recursive: true, force: true });
await run(['wasm-pack', 'build', profileFlag, '--target', 'web', '--out-dir', wasmRelOutDir], {
cwd: path.resolve(__dirname, '..', 'um_wasm'),
});
}
// Remove unneeded files
await Promise.all([
@ -93,7 +96,7 @@ async function main() {
]);
const homeDir = os.homedir();
const dummyHome = '/h' + homeDir.slice(3).replace(/./g, '_') + '/';
const dummyHome = '/h' + homeDir.slice(2).replace(/./g, '_');
// Patch some files...
await Promise.all([

10
um_wasm_loader/ci_publish.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
if [[ -z "${DRONE_TAG}" ]]; then
echo "skip package publish, pack only."
pnpm pack
exit 0
fi
echo '//git.unlock-music.dev/api/packages/um/npm/:_authToken=${NPM_TOKEN}' > $HOME/.npmrc
pnpm publish --access=public --no-git-checks

View File

@ -1,6 +1,6 @@
{
"name": "@unlock-music/crypto",
"version": "0.0.0-alpha.18",
"version": "0.0.0-alpha.19",
"description": "Project Unlock Music: 加解密支持库",
"scripts": {
"build": "node build.js",