diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e03b4a6..f4e44ec 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,7 @@ jobs: steps: - uses: 7mind/github-env@minimal - name: Run test build - run: ./run --nix :test + run: nix develop --command mdl --github-actions :test publish-scala: runs-on: ubuntu-latest @@ -45,7 +45,7 @@ jobs: popd fi - ./run --nix :publish-scala + nix develop --command mdl --github-actions :publish-scala publish-sjs: runs-on: ubuntu-latest @@ -77,7 +77,7 @@ jobs: popd fi - ./run --nix :build-sjs + nix develop --command mdl --github-actions :build-sjs - uses: softprops/action-gh-release@v2 id: create-release if: startsWith(github.ref, 'refs/tags/') @@ -86,7 +86,7 @@ jobs: ./json-sick-scala/target/dist/** - name: Prepare and Publish to npm if: startsWith(github.ref, 'refs/tags/') - run: ./run --nix :publish-npm + run: nix develop --command mdl --github-actions :publish-npm publish-cs: runs-on: ubuntu-latest @@ -101,4 +101,4 @@ jobs: secrets: | 637c5cad-a680-4ea3-ac8b-b193010bee40 > TOKEN_NUGET - name: Build and Test - run: ./run --nix :publish-cs + run: nix develop --command mdl --github-actions :publish-cs diff --git a/.gitignore b/.gitignore index 236300f..f50a107 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ target .bsp metals.sbt .direnv +.mdl/runs npm-publish node_modules/ diff --git a/.mdl/defs/actions.md b/.mdl/defs/actions.md new file mode 100644 index 0000000..f5d0637 --- /dev/null +++ b/.mdl/defs/actions.md @@ -0,0 +1,207 @@ +# SICK Build Actions + +# environment +- `LANG=C.UTF-8` + +## passthrough +- `HOME` +- `USER` +- `CI_BRANCH` +- `CI_BRANCH_TAG` +- `CI_BUILD_UNIQ_SUFFIX` +- `CI_PULL_REQUEST` +- `TOKEN_NUGET` +- `NODE_AUTH_TOKEN` + +# action: clean-worktree + +```bash +set -euo pipefail + +PROJECT_ROOT="${sys.project-root}" +cd "$PROJECT_ROOT" + +git clean -fxd -e private -e .idea -e .mdl -e .mdl/runs + +ret cleaned:bool=true +``` + +# action: test-scala + +```bash +dep action.clean-worktree + +set -euo pipefail + +SCALA_DIR="${sys.project-root}/json-sick-scala" +cd "$SCALA_DIR" + +sbt +clean +test:compile +test + +ret success:bool=true +``` + +# action: test-csharp + +```bash +dep action.test-scala + +set -euo pipefail + +CS_DIR="${sys.project-root}/json-sick-csharp" +cd "$CS_DIR" + +dotnet build +dotnet test + +ret success:bool=true +``` + +# action: test + +```bash +dep action.test-csharp + +ret success:bool=true +``` + +# action: publish-scala + +```bash +set -euo pipefail + +SCALA_DIR="${sys.project-root}/json-sick-scala" + +CI_PULL_REQUEST_VAL="${CI_PULL_REQUEST:-true}" +CI_BRANCH_TAG_VAL="${CI_BRANCH_TAG:-}" + +if [[ "$CI_PULL_REQUEST_VAL" != "false" ]]; then + echo "Skipping Scala publish because this is a pull request." + ret skipped:bool=true + exit 0 +fi + +if [[ -z "$CI_BRANCH_TAG_VAL" ]]; then + echo "CI_BRANCH_TAG is required to publish Scala artifacts." >&2 + exit 1 +fi + +cd "$SCALA_DIR" + +if [[ "$CI_BRANCH_TAG_VAL" =~ ^v.*$ ]]; then + sbt +clean +compile +publishSigned sonaUpload sonaRelease + sbt '++2.13 json-sickJS/fullOptJS' +else + sbt +clean +compile +publishSigned +fi + +ret success:bool=true +``` + +# action: build-sjs + +```bash +set -euo pipefail + +SCALA_DIR="${sys.project-root}/json-sick-scala" +DIST_DIR="${SCALA_DIR}/target/dist" + +CI_PULL_REQUEST_VAL="${CI_PULL_REQUEST:-true}" +if [[ "$CI_PULL_REQUEST_VAL" != "false" ]]; then + echo "Skipping Scala.js build because this is a pull request." + mkdir -p "$DIST_DIR" + ret skipped:bool=true + ret dist-dir:directory="$DIST_DIR" + exit 0 +fi + +cd "$SCALA_DIR" +sbt '++2.13 json-sickJS/fullOptJS' + +ret dist-dir:directory="$DIST_DIR" +``` + +# action: publish-cs + +```bash +set -euo pipefail + +CI_PULL_REQUEST_VAL="${CI_PULL_REQUEST:-true}" +TOKEN_NUGET_VAL="${TOKEN_NUGET:-}" +CI_BUILD_UNIQ_SUFFIX_VAL="${CI_BUILD_UNIQ_SUFFIX:-}" +CI_BRANCH_TAG_VAL="${CI_BRANCH_TAG:-}" + +if [[ "$CI_PULL_REQUEST_VAL" != "false" ]]; then + echo "Skipping C# publish because this is a pull request." + ret skipped:bool=true + exit 0 +fi + +if [[ -z "$TOKEN_NUGET_VAL" ]]; then + echo "TOKEN_NUGET is required to publish C# artifacts; skipping." >&2 + ret skipped:bool=true + exit 0 +fi + +if [[ -z "$CI_BUILD_UNIQ_SUFFIX_VAL" ]]; then + echo "CI_BUILD_UNIQ_SUFFIX is required to publish C# artifacts; skipping." >&2 + ret skipped:bool=true + exit 0 +fi + +CS_DIR="${sys.project-root}/json-sick-csharp" +cd "$CS_DIR" + +if [[ "$CI_BRANCH_TAG_VAL" =~ ^v.*$ ]]; then + dotnet build -c Release +else + dotnet build -c Release --version-suffix "alpha.${CI_BUILD_UNIQ_SUFFIX_VAL}" +fi + +find . -name '*.nupkg' -type f -print0 | xargs -I % -n 1 -0 dotnet nuget push % -k "${TOKEN_NUGET_VAL}" --source https://api.nuget.org/v3/index.json + +ret success:bool=true +``` + +# action: publish-npm + +```bash +dep action.build-sjs + +set -euo pipefail + +CI_PULL_REQUEST_VAL="${CI_PULL_REQUEST:-true}" +if [[ "$CI_PULL_REQUEST_VAL" != "false" ]]; then + echo "Skipping npm publish because this is a pull request." + ret skipped:bool=true + exit 0 +fi + +PROJECT_ROOT="${sys.project-root}" +DIST_DIR="${action.build-sjs.dist-dir}" +PUBLISH_DIR="${PROJECT_ROOT}/npm-publish" +VERSION_FILE="${PROJECT_ROOT}/version.txt" +VERSION=$(tr -d '\n' < "$VERSION_FILE") + +if [[ ! -d "$DIST_DIR" ]]; then + echo "Scala.js distribution directory '$DIST_DIR' is missing." >&2 + exit 1 +fi + +rm -rf "$PUBLISH_DIR" +mkdir -p "$PUBLISH_DIR" + +cp "${DIST_DIR}"/* "$PUBLISH_DIR"/ +cp "${PROJECT_ROOT}/json-sick-scala/npm-template/"* "$PUBLISH_DIR"/ + +sed -i "s/VERSION_PLACEHOLDER/$VERSION/g" "$PUBLISH_DIR/package.json" + +cd "$PUBLISH_DIR" + +npm install --save-dev ava +npm test +npm publish --provenance --access public + +ret success:bool=true +ret publish-dir:directory="$PUBLISH_DIR" +``` diff --git a/.mobala/env.sh b/.mobala/env.sh deleted file mode 100755 index f81166f..0000000 --- a/.mobala/env.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail -if [[ "${DO_VERBOSE}" == 1 ]] ; then set -x ; fi - -set_jvm_options -debug_env - -# this script receives all the CLI args from the main script and may decide which flows should be enabled -flow_enable do-build \ No newline at end of file diff --git a/.mobala/flows/do-build.sh b/.mobala/flows/do-build.sh deleted file mode 100755 index f94a80a..0000000 --- a/.mobala/flows/do-build.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -function do-build() { - step_run_cond run-test - step_run_cond run-publish-scala - step_run_cond run-build-sjs - step_run_cond run-publish-cs - step_run_cond run-publish-npm -} diff --git a/.mobala/keep.env b/.mobala/keep.env deleted file mode 100644 index 599c834..0000000 --- a/.mobala/keep.env +++ /dev/null @@ -1 +0,0 @@ -TOKEN_NUGET \ No newline at end of file diff --git a/.mobala/steps/run-build-sjs.sh b/.mobala/steps/run-build-sjs.sh deleted file mode 100755 index f0bd6c1..0000000 --- a/.mobala/steps/run-build-sjs.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -function run-build-sjs() { - cd json-sick-scala - - [[ "$CI_PULL_REQUEST" != "false" ]] && exit 0 - - sbt '++2.13 json-sickJS/fullOptJS' -} diff --git a/.mobala/steps/run-publish-cs.sh b/.mobala/steps/run-publish-cs.sh deleted file mode 100755 index 2502846..0000000 --- a/.mobala/steps/run-publish-cs.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -function run-publish-cs() { - cd json-sick-csharp - - [[ "$CI_PULL_REQUEST" != "false" ]] && exit 0 - [[ -z "$TOKEN_NUGET" ]] && exit 0 - [[ -z "$CI_BUILD_UNIQ_SUFFIX" ]] && exit 0 - - if [[ "$CI_BRANCH_TAG" =~ ^v.*$ ]] ; then - dotnet build -c Release - else - dotnet build -c Release --version-suffix "alpha.${CI_BUILD_UNIQ_SUFFIX}" - fi - - find . -name '*.nupkg' -type f -print0 | xargs -I % -n 1 -0 dotnet nuget push % -k "${TOKEN_NUGET}" --source https://api.nuget.org/v3/index.json -} \ No newline at end of file diff --git a/.mobala/steps/run-publish-npm.sh b/.mobala/steps/run-publish-npm.sh deleted file mode 100644 index 7b8ad1c..0000000 --- a/.mobala/steps/run-publish-npm.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -function run-publish-npm() { - [[ "$CI_PULL_REQUEST" != "false" ]] && exit 0 - - VERSION=$(cat version.txt | tr -d '\n') - mkdir -p npm-publish - cp ./json-sick-scala/target/dist/* npm-publish/ - cp ./json-sick-scala/npm-template/* npm-publish/ - sed -i "s/VERSION_PLACEHOLDER/$VERSION/g" npm-publish/package.json - ls -la npm-publish/ - cat npm-publish/package.json - - cd npm-publish - - nix develop --command bash -c " - npm install --save-dev ava - npm test - npm publish --provenance --access public - " -} diff --git a/.mobala/steps/run-publish-scala.sh b/.mobala/steps/run-publish-scala.sh deleted file mode 100755 index 4fbcbef..0000000 --- a/.mobala/steps/run-publish-scala.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -function run-publish-scala() { - cd json-sick-scala - - [[ "$CI_PULL_REQUEST" != "false" ]] && exit 0 - - if [[ "$CI_BRANCH_TAG" =~ ^v.*$ ]] ; then - sbt +clean +compile +publishSigned sonaUpload sonaRelease - sbt '++2.13 json-sickJS/fullOptJS' - else - sbt +clean +compile +publishSigned - fi -} diff --git a/.mobala/steps/run-test.sh b/.mobala/steps/run-test.sh deleted file mode 100755 index c1e6846..0000000 --- a/.mobala/steps/run-test.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -function run-test() { - git clean -fxd -e private -e .idea - - pushd . - cd ./json-sick-scala - sbt +clean +test:compile +test - popd - - pushd . - cd ./json-sick-csharp - dotnet build - dotnet test - - popd -} \ No newline at end of file diff --git a/.mobala/version-commit.lock b/.mobala/version-commit.lock deleted file mode 100644 index cec2249..0000000 --- a/.mobala/version-commit.lock +++ /dev/null @@ -1,2 +0,0 @@ -87a6a202f917745e826d6f245f78db48cb92965b -0 \ No newline at end of file diff --git a/.mobala/version.txt b/.mobala/version.txt deleted file mode 100644 index ce57f64..0000000 --- a/.mobala/version.txt +++ /dev/null @@ -1 +0,0 @@ -develop \ No newline at end of file diff --git a/flake.lock b/flake.lock index 9eb9bcc..d16760f 100644 --- a/flake.lock +++ b/flake.lock @@ -18,6 +18,45 @@ "type": "github" } }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "mudyla": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1764278888, + "narHash": "sha256-RRmR6hLsW97AFoVJ3UCH//mcewTQpNrZHItIzxodzbs=", + "owner": "7mind", + "repo": "mudyla", + "rev": "aa1e86c5cbcc8c9b00e1cbf8a188a0ab36c42149", + "type": "github" + }, + "original": { + "owner": "7mind", + "repo": "mudyla", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1761827546, @@ -37,6 +76,7 @@ "root": { "inputs": { "flake-utils": "flake-utils", + "mudyla": "mudyla", "nixpkgs": "nixpkgs" } }, @@ -54,6 +94,21 @@ "repo": "default", "type": "github" } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 9a350d6..b220226 100644 --- a/flake.nix +++ b/flake.nix @@ -5,7 +5,10 @@ inputs.flake-utils.url = "github:numtide/flake-utils"; - outputs = { self, nixpkgs, flake-utils }: + inputs.mudyla.url = "github:7mind/mudyla"; + inputs.mudyla.inputs.nixpkgs.follows = "nixpkgs"; + + outputs = { self, nixpkgs, flake-utils, mudyla }: flake-utils.lib.eachDefaultSystem (system: let @@ -25,6 +28,8 @@ openssl scala-cli + ] ++ [ + mudyla.packages.${system}.default ]; in { @@ -32,8 +37,8 @@ # use nix develop .#ide to enable JetBrains Rider from nixpkgs devShells.ide = pkgs.mkShell { - nativeBuildInputs = with pkgs.buildPackages; sharedPkgs ++ [ - jetbrains.rider + nativeBuildInputs = sharedPkgs ++ [ + pkgs.buildPackages.jetbrains.rider ]; # LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ pkgs.stdenv.cc.cc.lib ]; }; diff --git a/run b/run index 1d6e53f..47d9dbd 100755 --- a/run +++ b/run @@ -2,84 +2,16 @@ set -euo pipefail -read_trimmed_string() { [[ -s "$1" ]] && sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' "$1" || echo "$2"; } +PROJECT_ROOT="$(cd "$(dirname "$0")" && pwd)" +cd "$PROJECT_ROOT" -export CACHE_DIR="${XDG_CACHE_HOME:-"${HOME}/.cache"}" -export MOBALA_CACHE_MAIN="${CACHE_DIR}/mobala.sh" -export MOBALA_CACHE_LIB="${CACHE_DIR}/mobala-lib.sh" -export MOBALA_VERSION=$(read_trimmed_string ".mobala/version.txt" "release") -export MOBALA_BASE="https://raw.githubusercontent.com/7mind/mobala/refs/heads/${MOBALA_VERSION}" -export MOBALA_FILE="${MOBALA_BASE}/mobala.sh" -export MOBALA_LIB_FILE="${MOBALA_BASE}/mobala-lib.sh" -export MOBALA_SELF_UPDATE=${MOBALA_SELF_UPDATE:-1} -export MOBALA_CACHE_UPDATE=${MOBALA_CACHE_UPDATE:-1} +args=("$@") +if [[ "${args[0]:-}" == "--nix" ]]; then + args=("${args[@]:1}") +fi -script_path="$(realpath "$0")" -script_dirname="$(dirname "$script_path")" +if command -v mdl >/dev/null 2>&1; then + exec mdl "${args[@]}" +fi -export MOBALA_PATH="${script_dirname}" -export MOBALA_SUBDIR=${MOBALA_SUBDIR:-".mobala"} -export MOBALA_KEEP=${MOBALA_KEEP:-"${MOBALA_PATH}/${MOBALA_SUBDIR}/keep.env"} -export MOBALA_ENV=${MOBALA_ENV:-"${MOBALA_PATH}/${MOBALA_SUBDIR}/env.sh"} -export MOBALA_MODS=${MOBALA_MODS:-"${MOBALA_PATH}/${MOBALA_SUBDIR}/mods"} -export MOBALA_PARAMS=${MOBALA_PARAMS:-"${MOBALA_PATH}/${MOBALA_SUBDIR}/params"} - -function check-cache() { - if [[ -f "${MOBALA_CACHE_MAIN}" && -f "${MOBALA_CACHE_LIB}" ]]; then - echo "[info] mobala.sh cache found at '${MOBALA_CACHE_MAIN}'" - else - echo "[info] mobala.sh cache not found at '${MOBALA_CACHE_MAIN}'" - fi -} - -function download-file() { - origin="${1}" - target="${2}" - mkdir -p "${CACHE_DIR}" - cache_name="$(basename "$target")" - cache_tmp="${CACHE_DIR}/${cache_name}.tmp" - rm -rf "${cache_tmp}" - download_response=$(curl -sLJ0 -H 'Cache-Control: no-cache, no-store' -o "${cache_tmp}" -w "%{response_code}" "${origin}" || true) - if [[ "${download_response}" == "200" ]]; then - rm -rf "${target}" - mv "${cache_tmp}" "${target}" - echo "[info] cache updated: ${target}" - else - echo "[warn] download failed with ${download_response} status code for ${target}" - rm "${cache_tmp}" - fi -} - - -function update-cache() { - if [[ "${MOBALA_CACHE_UPDATE}" == 1 ]] ; then - download-file "${MOBALA_LIB_FILE}" "${MOBALA_CACHE_LIB}" - download-file "${MOBALA_FILE}" "${MOBALA_CACHE_MAIN}" - fi -} - -function verify-cache() { - if ! [[ -f "${MOBALA_CACHE_MAIN}" ]]; then - >&2 echo "[error] mobala.sh cache not found." - exit 1 - fi - if ! [[ -f "${MOBALA_CACHE_LIB}" ]]; then - >&2 echo "[error] mobala-lib.sh cache not found." - exit 1 - fi -} - -function update-self(){ - if [[ "${CI:-false}" == "false" && "${MOBALA_SELF_UPDATE}" == 1 ]] ; then - download-file "${MOBALA_BASE}/mobala-resolver.sh" "${script_path}" - chmod +x "${script_path}" - fi -} - -trap 'update-self' EXIT - -check-cache -update-cache -verify-cache - -bash "${MOBALA_CACHE_MAIN}" "$@" +exec nix run github:7mind/mudyla -- "${args[@]}"