From 7c5bc8f412284edcb608a8d27ef37f42540411d0 Mon Sep 17 00:00:00 2001 From: bom Date: Fri, 10 May 2024 12:10:59 +0200 Subject: [PATCH] Update build to gitlab and ddadevops --- .gitlab_ci.yml | 55 ++++++++++++++++++++ build.py | 133 ++++++++++++++++++++++++++++++++++++++++++++++++ shadow-cljs.edn | 4 +- 3 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 .gitlab_ci.yml create mode 100644 build.py diff --git a/.gitlab_ci.yml b/.gitlab_ci.yml new file mode 100644 index 0000000..822f9fc --- /dev/null +++ b/.gitlab_ci.yml @@ -0,0 +1,55 @@ +stages: + - build_and_test + - package + - upload + +.cljs-job: &cljs + image: "domaindrivenarchitecture/ddadevops-clj-cljs:4.11.3" + cache: + key: ${CI_COMMIT_REF_SLUG} + paths: + - node_modules/ + - .shadow-cljs/ + - .m2 + before_script: + - export RELEASE_ARTIFACT_TOKEN=$MEISSA_REPO_BUERO_RW + - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc + - npm install + +.tag_only: &tag_only + rules: + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + when: never + - if: '$CI_COMMIT_TAG =~ /^[0-9]+\.[0-9]+\.[0-9]+$/' + +test-cljs: + <<: *cljs + stage: build_and_test + script: + - pyb test_cljs + +report-frontend: + <<: *cljs + stage: package + script: + - pyb report_frontend + artifacts: + paths: + - target/frontend-build/build-report.html + +package-frontend: + <<: *cljs + stage: package + script: + - pyb package_frontend + artifacts: + paths: + - target/frontend-build + +release-to-forgejo: + <<: *cljs + <<: *tag_only + stage: upload + script: + - pyb publish_artifacts + diff --git a/build.py b/build.py new file mode 100644 index 0000000..7fa9f02 --- /dev/null +++ b/build.py @@ -0,0 +1,133 @@ +from os import environ +from subprocess import run +from pybuilder.core import init, task +from ddadevops import * + +default_task = "dev" +base_name = "dda-masto-embed" +name = 'dda-masto-embed' +MODULE = 'not-used' +PROJECT_ROOT_PATH = '.' + +version = "0.2.5" + +@init +def initialize(project): + project.build_depends_on("ddadevops>=4.7.0") + + input = { + "name": name, + "module": MODULE, + "stage": "notused", + "project_root_path": PROJECT_ROOT_PATH, + "build_types": [], + "mixin_types": ["RELEASE"], + "release_primary_build_file": "package.json", + "release_secondary_build_files": [ + "build.py" + ], + "release_artifact_server_url": "https://repo.prod.meissa.de", + "release_organisation": "meissa", + "release_repository_name": name, + "release_artifacts": [ + f"target/{name}.js", + ], + "release_main_branch": "master", + } + + build = ReleaseMixin(project, input) + build.initialize_build_dir() + + +@task +def test(project): + test_cljs(project) + + +@task +def test_cljs(project): + run("shadow-cljs compile test", shell=True, check=True) + run("node target/node-tests.js", shell=True, check=True) + + +@task +def report_frontend(project): + run("mkdir -p target/frontend-build", shell=True, check=True) + run( + "shadow-cljs run shadow.cljs.build-report frontend target/build-report.html", + shell=True, + check=True, + ) + + +@task +def package_frontend(project): + run("mkdir -p target/", shell=True, check=True) + run("shadow-cljs release frontend", shell=True, check=True) + run( + f"cp public/js/main.js target/{name}.js", + shell=True, + check=True, + ) + run( + f"sha256sum target/{name}.js > target/{name}.js.sha256", + shell=True, + check=True, + ) + run( + f"sha512sum target/{name}.js > target/{name}.js.sha512", + shell=True, + check=True, + ) + + +@task +def patch(project): + linttest(project, "PATCH") + release(project) + + +@task +def minor(project): + linttest(project, "MINOR") + release(project) + + +@task +def major(project): + linttest(project, "MAJOR") + release(project) + + +@task +def dev(project): + linttest(project, "NONE") + + +@task +def prepare(project): + build = get_devops_build(project) + build.prepare_release() + + +@task +def tag(project): + build = get_devops_build(project) + build.tag_bump_and_push_release() + + +@task +def publish_artifacts(project): + build = get_devops_build(project) + build.publish_artifacts() + + +def release(project): + prepare(project) + tag(project) + + +def linttest(project, release_type): + build = get_devops_build(project) + build.update_release_type(release_type) + test_cljs(project) diff --git a/shadow-cljs.edn b/shadow-cljs.edn index 757b154..539e868 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -14,9 +14,9 @@ :output-to "target/node-tests.js" :autorun true} :lib {:target :node-library - :output-to "target/lib.js" + :output-to "target/dda-masto-embed.js" :exports {:init dda.masto-embed.app/init} - :release {:compiler-options {:optimizations :simple}}} + :release {:compiler-options {:optimizations :advanced}}} :frontend {:target :browser :modules {:main {:init-fn dda.masto-embed.app/init}} :release {}}}}