├── .bazelversion ├── .factory └── automation.yml ├── .github ├── CODEOWNERS └── pull_request_template.md ├── .gitignore ├── BUILD ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── WORKSPACE ├── apt ├── BUILD ├── generate_depends_file.py ├── rules.bzl └── templates │ ├── BUILD │ └── deploy.py ├── artifact ├── BUILD ├── rules.bzl └── templates │ ├── BUILD │ └── deploy.py ├── aws ├── BUILD ├── packer.template.json └── rules.bzl ├── azure ├── BUILD ├── packer.template.json └── rules.bzl ├── brew ├── BUILD ├── rules.bzl └── templates │ ├── BUILD │ └── deploy.py ├── common ├── BUILD ├── Logging.kt ├── Property.kt ├── assemble_versioned │ ├── BUILD │ ├── assemble-versioned.py │ └── rules.bzl ├── checksum │ ├── BUILD │ └── rules.bzl ├── deps.bzl ├── generate_json_config │ ├── BUILD │ └── rules.bzl ├── java_deps │ ├── BUILD │ ├── java_deps.py │ └── rules.bzl ├── rename │ ├── BUILD │ └── rules.bzl ├── rules.bzl ├── shell │ ├── BUILD │ └── Shell.kt ├── targz │ ├── BUILD │ └── rules.bzl ├── tgz2zip │ ├── BUILD │ ├── rules.bzl │ └── tgz2zip.py ├── uploader │ ├── BUILD │ ├── __init__.py │ ├── cloudsmith.py │ ├── deps.bzl │ ├── nexus.py │ ├── requirements.txt │ └── uploader.py ├── util │ ├── BUILD │ ├── FileUtil.kt │ ├── PropertiesUtil.kt │ └── SystemUtil.kt ├── workspace_refs │ ├── BUILD │ └── rules.bzl └── zip │ ├── BUILD │ └── rules.bzl ├── crates ├── BUILD ├── CrateAssembler.kt ├── CrateDeployer.kt ├── rules.bzl └── templates │ ├── BUILD │ └── deploy.sh ├── doc_hub.bzl ├── docs ├── BUILD ├── doxygen │ ├── doxyfile.template │ └── rules.bzl ├── java │ └── deps.bzl └── python │ ├── deps.bzl │ ├── requirements.txt │ ├── rules.bzl │ └── sphinx_html_builder.py ├── gcp ├── BUILD ├── packer.template.json └── rules.bzl ├── github ├── BUILD ├── deps.bzl ├── rules.bzl └── templates │ ├── BUILD │ └── deploy.py ├── helm ├── BUILD ├── rules.bzl └── templates │ ├── BUILD │ └── deploy.py ├── maven ├── BUILD ├── JarAssembler.kt ├── PomGenerator.kt ├── deps.bzl ├── rules.bzl └── templates │ ├── BUILD │ └── deploy.py ├── npm ├── BUILD ├── assemble │ ├── BUILD │ ├── assemble.py │ └── rules.bzl ├── deploy │ ├── BUILD │ ├── DeployNPM.kt │ ├── Deployer.kt │ ├── Options.kt │ ├── deploy.sh.template │ └── rules.bzl └── rules.bzl ├── nuget ├── BUILD ├── rules.bzl └── templates │ ├── BUILD │ └── push.py ├── packer ├── BUILD ├── deps.bzl ├── rules.bzl └── templates │ ├── BUILD │ └── deploy_packer.py ├── pip ├── BUILD ├── assemble.py ├── deps.bzl ├── repackage.py ├── replace_imports.py ├── requirements.txt ├── rules.bzl └── templates │ ├── BUILD │ ├── deploy.py │ └── setup.py └── platform ├── BUILD ├── constraints.bzl └── jvm ├── AppleCodeSigner.kt ├── BUILD ├── CommandLineParams.kt ├── JVMPlatformAssembler.kt ├── MacAppNotarizer.kt ├── Main.kt ├── Options.kt ├── ShellArgs.kt └── rules.bzl /.bazelversion: -------------------------------------------------------------------------------- 1 | 6.2.0 2 | -------------------------------------------------------------------------------- /.factory/automation.yml: -------------------------------------------------------------------------------- 1 | build: 2 | correctness: 3 | build: 4 | image: typedb-ubuntu-22.04 5 | type: foreground 6 | command: | 7 | bazel build //... 8 | execution: 9 | - build 10 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | /* @alexjpwalker 2 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ## Usage and product changes 2 | 3 | 4 | ## Motivation 5 | 6 | 7 | ## Implementation 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IDEA files 2 | *.iml 3 | .ijwb/ 4 | bazel-* 5 | -------------------------------------------------------------------------------- /BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@bazel_stardoc//stardoc:stardoc.bzl", "stardoc") 21 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 22 | 23 | 24 | stardoc( 25 | name = "docs", 26 | input = "doc_hub.bzl", 27 | out = "README.md", 28 | deps = [ 29 | "//apt:lib", 30 | "//aws:lib", 31 | "//azure:lib", 32 | "//brew:lib", 33 | "//common:lib", 34 | "//crates:lib", 35 | "//docs:lib", 36 | "//gcp:lib", 37 | "//github:lib", 38 | "//maven:lib", 39 | "//npm:lib", 40 | "//npm/assemble:lib", 41 | "//npm/deploy:lib", 42 | "//packer:lib", 43 | "//pip:lib", 44 | ], 45 | symbol_names = [ 46 | # From: //apt:rules.bzl 47 | "assemble_apt", 48 | "deploy_apt", 49 | 50 | # From: //aws:rules.bzl 51 | "assemble_aws", 52 | 53 | # From: //azure:rules.bzl 54 | "assemble_azure", 55 | 56 | # From: //brew:rules.bzl 57 | "deploy_brew", 58 | 59 | 60 | # From: //common/java_deps:rules.bzl 61 | "MAVEN_COORDINATES_PREFIX", 62 | "JarToMavenCoordinatesMapping", 63 | "TransitiveJarToMavenCoordinatesMapping", 64 | "java_deps", 65 | 66 | # From: //common:rules.bzl 67 | "assemble_targz", 68 | "assemble_versioned", 69 | "assemble_zip", 70 | "checksum", 71 | "file_rename", 72 | "generate_json_config", 73 | "tgz2zip", 74 | "workspace_refs", 75 | 76 | # From: //crates:rules.bzl 77 | "assemble_crate", 78 | "deploy_crate", 79 | 80 | # From: //docs:*/rules.bzl 81 | "doxygen_docs", 82 | "sphinx_docs", 83 | 84 | # From: //gcp:rules.bzl 85 | "assemble_gcp", 86 | 87 | # From: //github:rules.bzl 88 | "deploy_github", 89 | 90 | # From: //maven:rules.bzl 91 | "JavaLibInfo", 92 | "MavenPomInfo", 93 | "MavenDeploymentInfo", 94 | "assemble_maven", 95 | "deploy_maven", 96 | 97 | # From: //npm:rules.bzl 98 | "assemble_npm", 99 | "deploy_npm", 100 | 101 | # From: //packer:rules.bzl 102 | "assemble_packer", 103 | "deploy_packer", 104 | 105 | # From: //pip:rules.bzl 106 | "assemble_pip", 107 | "deploy_pip", 108 | ], 109 | ) 110 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Want to contribute? Your contribution is warmly welcomed! Please be aware of the following caveats: 2 | 3 | ### Large contributions 4 | 5 | Before you start working on a larger contribution, you should get in touch with us first to 6 | explain your idea so we can help and possibly guide you, which you can do using: 7 | 8 | - The GitHub issue tracker; 9 | - [Discord](https://discord.gg/typedb). 10 | 11 | If you don't do this, large contributions are unlikely to be reviewed. 12 | 13 | ### Code reviews and other contributions. 14 | 15 | All submissions, including submissions by project members, require review. 16 | -------------------------------------------------------------------------------- /WORKSPACE: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | workspace(name="typedb_bazel_distribution") 21 | 22 | load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") 23 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 24 | 25 | # Load @rules_python, @io_bazel_rules_kotlin and @rules_jvm_external 26 | load("//common:deps.bzl", "rules_python", "rules_kotlin", "rules_jvm_external", "rules_rust") 27 | rules_python() 28 | rules_kotlin() 29 | rules_jvm_external() 30 | rules_rust() 31 | 32 | # Load @rules_python 33 | load("@rules_python//python:repositories.bzl", "py_repositories") 34 | py_repositories() 35 | 36 | # Load @io_bazel_rules_kotlin 37 | load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") 38 | kotlin_repositories() 39 | kt_register_toolchains() 40 | 41 | load("@typedb_bazel_distribution//maven:deps.bzl", "maven_artifacts_with_versions") 42 | load("@rules_jvm_external//:defs.bzl", "maven_install") 43 | maven_install( 44 | artifacts = maven_artifacts_with_versions, 45 | repositories = [ 46 | "https://repo1.maven.org/maven2", 47 | ], 48 | strict_visibility = True, 49 | version_conflict_policy = "pinned", 50 | fetch_sources = True, 51 | ) 52 | 53 | # Load @typedb_bazel_distribution_pip 54 | load("//pip:deps.bzl", "typedb_bazel_distribution_pip") 55 | typedb_bazel_distribution_pip() 56 | load("@typedb_bazel_distribution_pip//:requirements.bzl", pip_install_deps = "install_deps") 57 | pip_install_deps() 58 | 59 | # Load //docs 60 | load("//docs:python/deps.bzl", "typedb_bazel_distribution_docs_py") 61 | typedb_bazel_distribution_docs_py() 62 | load("@typedb_bazel_distribution_docs_py//:requirements.bzl", docs_py_install_deps = "install_deps") 63 | docs_py_install_deps() 64 | 65 | # TODO: remove this declaration once we upgrade to @io_bazel_stardoc with Bazel 5 support 66 | # Load @bazel_skylib 67 | http_archive( 68 | name = "bazel_skylib", 69 | sha256 = "66ffd9315665bfaafc96b52278f57c7e2dd09f5ede279ea6d39b2be471e7e3aa", 70 | urls = [ 71 | "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz", 72 | "https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz" 73 | ], 74 | ) 75 | 76 | load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") 77 | bazel_skylib_workspace() 78 | 79 | # Load @rules_pkg 80 | load("//common:deps.bzl", "rules_pkg") 81 | rules_pkg() 82 | load("@rules_pkg//pkg:deps.bzl", "rules_pkg_dependencies") 83 | rules_pkg_dependencies() 84 | 85 | 86 | # Load @io_bazel_stardoc 87 | http_archive( 88 | name = "bazel_stardoc", 89 | sha256 = "dfbc364aaec143df5e6c52faf1f1166775a5b4408243f445f44b661cfdc3134f", 90 | urls = [ 91 | "https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.5.6/stardoc-0.5.6.tar.gz", 92 | "https://github.com/bazelbuild/stardoc/releases/download/0.5.6/stardoc-0.5.6.tar.gz", 93 | ], 94 | ) 95 | 96 | load("@bazel_stardoc//:setup.bzl", "stardoc_repositories") 97 | stardoc_repositories() 98 | 99 | # Load @typedb_bazel_distribution_uploader 100 | load("//common/uploader:deps.bzl", "typedb_bazel_distribution_uploader") 101 | typedb_bazel_distribution_uploader() 102 | load("@typedb_bazel_distribution_uploader//:requirements.bzl", uploader_install_deps = "install_deps") 103 | uploader_install_deps() 104 | -------------------------------------------------------------------------------- /apt/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 21 | 22 | bzl_library( 23 | name = "lib", 24 | srcs = [ 25 | "rules.bzl", 26 | "@rules_pkg//:pkg.bzl", 27 | "@rules_pkg//pkg:pkg.bzl", 28 | ], 29 | deps = [ 30 | "@rules_pkg//doc_build:rules_pkg_lib", 31 | ], 32 | visibility = ["//visibility:public"] 33 | ) 34 | 35 | py_binary( 36 | name = "generate_depends_file", 37 | srcs = ["generate_depends_file.py"], 38 | visibility = ["//visibility:public"] 39 | ) 40 | -------------------------------------------------------------------------------- /apt/generate_depends_file.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one 5 | # or more contributor license agreements. See the NOTICE file 6 | # distributed with this work for additional information 7 | # regarding copyright ownership. The ASF licenses this file 8 | # to you under the Apache License, Version 2.0 (the 9 | # "License"); you may not use this file except in compliance 10 | # with the License. You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, 15 | # software distributed under the License is distributed on an 16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | # KIND, either express or implied. See the License for the 18 | # specific language governing permissions and limitations 19 | # under the License. 20 | # 21 | 22 | import argparse 23 | import json 24 | import re 25 | 26 | WORKSPACE_REF_PATTERN = re.compile(r'.*%{@(?P.*)}.*') 27 | 28 | parser = argparse.ArgumentParser() 29 | parser.add_argument('--output', required=True, help='Output file') 30 | parser.add_argument('--version_file', required=True, help='File containing version of package being built') 31 | parser.add_argument('--workspace_refs', help='File with workspace references (optional)') 32 | parser.add_argument('--deps', nargs='+', help='Dependency declarations (optional)') 33 | args = parser.parse_args() 34 | 35 | workspace_refs = { 36 | 'commits': {}, 37 | 'tags': {} 38 | } 39 | 40 | with open(args.version_file) as f: 41 | version = f.read().strip() 42 | 43 | replacements = { 44 | "%{version}": version 45 | } 46 | 47 | if args.workspace_refs: 48 | with open(args.workspace_refs) as f: 49 | workspace_refs = json.load(f) 50 | 51 | all_workspaces = set() 52 | 53 | for ws, commit in workspace_refs['commits'].items(): 54 | replacements["%{{@{}}}".format(ws)] = "0.0.0-" + commit 55 | all_workspaces.add(ws) 56 | 57 | for ws, tag in workspace_refs['tags'].items(): 58 | replacements["%{{@{}}}".format(ws)] = tag 59 | all_workspaces.add(ws) 60 | 61 | deps = [] 62 | 63 | for dep in (args.deps or []): 64 | match = WORKSPACE_REF_PATTERN.match(dep) 65 | if match: 66 | workspace_ref = match.group('workspace_ref') 67 | if workspace_ref not in all_workspaces: 68 | raise Exception('invalid workspace was referenced: `{}`; valid workspaces to reference are: {}'.format( 69 | workspace_ref, list(all_workspaces) 70 | )) 71 | for replacement_key, replacement_val in replacements.items(): 72 | dep = dep.replace(replacement_key, replacement_val) 73 | deps.append(dep) 74 | 75 | with open(args.output, 'w') as out: 76 | out.write(', '.join(deps)) 77 | -------------------------------------------------------------------------------- /apt/templates/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | exports_files(["deploy.py"]) 21 | -------------------------------------------------------------------------------- /apt/templates/deploy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one 5 | # or more contributor license agreements. See the NOTICE file 6 | # distributed with this work for additional information 7 | # regarding copyright ownership. The ASF licenses this file 8 | # to you under the Apache License, Version 2.0 (the 9 | # "License"); you may not use this file except in compliance 10 | # with the License. You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, 15 | # software distributed under the License is distributed on an 16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | # KIND, either express or implied. See the License for the 18 | # specific language governing permissions and limitations 19 | # under the License. 20 | # 21 | 22 | import argparse 23 | import os 24 | import subprocess 25 | import shutil 26 | 27 | # usual importing is not possible because 28 | # this script and module with common functions 29 | # are at different directory levels in sandbox 30 | import tarfile 31 | import tempfile 32 | from runpy import run_path 33 | 34 | import sys, glob 35 | # Prefer using the runfile dependency than system dependency 36 | runfile_deps = [path for path in map(os.path.abspath, glob.glob('external/*/*'))] 37 | sys.path = runfile_deps + sys.path 38 | 39 | from common.uploader.uploader import Uploader 40 | 41 | parser = argparse.ArgumentParser() 42 | parser.add_argument('repo_type') 43 | args = parser.parse_args() 44 | 45 | repo_type_key = args.repo_type 46 | 47 | apt_repositories = { 48 | 'snapshot' : "{snapshot}", 49 | 'release' : "{release}" 50 | } 51 | 52 | repo_url = apt_repositories[repo_type_key] 53 | 54 | apt_username, apt_password = ( 55 | os.getenv('DEPLOY_APT_USERNAME'), 56 | os.getenv('DEPLOY_APT_PASSWORD'), 57 | ) 58 | 59 | if not apt_username: 60 | raise Exception( 61 | 'username should be passed via ' 62 | '$DEPLOY_APT_USERNAME env variable' 63 | ) 64 | 65 | if not apt_password: 66 | raise Exception( 67 | 'password should be passed via ' 68 | '$DEPLOY_APT_PASSWORD env variable' 69 | ) 70 | 71 | package_path = "{package_path}" 72 | # Cloudsmith has a bug where packages with the same filename can break downloads 73 | uploaded_filename = package_path.rstrip(".deb") + "_{version}.deb" 74 | 75 | uploader = Uploader.create(apt_username, apt_password, repo_url) 76 | uploader.apt(package_path, uploaded_filename=uploaded_filename) 77 | 78 | print('Deployment completed.') 79 | -------------------------------------------------------------------------------- /artifact/BUILD: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typedb/bazel-distribution/056a8d7ede9b552d23dcfdc2d47b9395510652f4/artifact/BUILD -------------------------------------------------------------------------------- /artifact/templates/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | exports_files(["deploy.py"]) 21 | -------------------------------------------------------------------------------- /artifact/templates/deploy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one 5 | # or more contributor license agreements. See the NOTICE file 6 | # distributed with this work for additional information 7 | # regarding copyright ownership. The ASF licenses this file 8 | # to you under the Apache License, Version 2.0 (the 9 | # "License"); you may not use this file except in compliance 10 | # with the License. You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, 15 | # software distributed under the License is distributed on an 16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | # KIND, either express or implied. See the License for the 18 | # specific language governing permissions and limitations 19 | # under the License. 20 | # 21 | 22 | from __future__ import print_function 23 | 24 | import os 25 | import re 26 | import subprocess as sp 27 | import sys 28 | from posixpath import join as urljoin 29 | 30 | import glob 31 | # Prefer using the runfile dependency than system dependency 32 | runfile_deps = [path for path in map(os.path.abspath, glob.glob('external/*/*'))] 33 | sys.path = runfile_deps + sys.path 34 | 35 | from common.uploader.uploader import Uploader 36 | 37 | if len(sys.argv) != 2: 38 | raise ValueError('Should pass only as arguments') 39 | 40 | _, repo_type = sys.argv 41 | 42 | username, password = os.getenv('DEPLOY_ARTIFACT_USERNAME'), os.getenv('DEPLOY_ARTIFACT_PASSWORD') 43 | 44 | if not username: 45 | raise ValueError('Error: username should be passed via $DEPLOY_ARTIFACT_USERNAME env variable') 46 | 47 | if not password: 48 | raise ValueError('Error: password should be passed via $DEPLOY_ARTIFACT_PASSWORD env variable') 49 | 50 | version = open("{version_file}", "r").read().strip() 51 | 52 | snapshot = 'snapshot' 53 | version_snapshot_regex = '^.*[0-9a-fA-F]{40}$' 54 | release = 'release' 55 | version_release_regex = '^[0-9]+.[0-9]+.[0-9]+(-[a-zA-Z0-9]+)*$' 56 | 57 | if repo_type not in [snapshot, release]: 58 | raise ValueError("Invalid repository type: {}. It should be one of these: {}" 59 | .format(repo_type, [snapshot, release])) 60 | if repo_type == 'snapshot' and len(re.findall(version_snapshot_regex, version)) == 0: 61 | raise ValueError('Invalid version: {}. An artifact uploaded to a {} repository ' 62 | 'must have a version which complies to this regex: {}' 63 | .format(version, repo_type, version_snapshot_regex)) 64 | if repo_type == 'release' and len(re.findall(version_release_regex, version)) == 0: 65 | raise ValueError('Invalid version: {}. An artifact uploaded to a {} repository ' 66 | 'must have a version which complies to this regex: {}' 67 | .format(version, repo_type, version_snapshot_regex)) 68 | 69 | filename = '{artifact_filename}' 70 | filename = filename.format(version = version) 71 | 72 | base_url = None 73 | if repo_type == 'release': 74 | base_url = '{release}' 75 | else: 76 | base_url = '{snapshot}' 77 | 78 | uploader = Uploader.create(username, password, base_url) 79 | uploader.artifact("{artifact_group}", version, '{artifact_path}', filename) 80 | -------------------------------------------------------------------------------- /aws/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | exports_files(["packer.template.json"]) 21 | 22 | 23 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 24 | 25 | bzl_library( 26 | name = "lib", 27 | srcs = [ 28 | "rules.bzl" 29 | ], 30 | deps = [ 31 | "//packer:lib", 32 | "//common:lib" 33 | ], 34 | visibility = ["//visibility:public"] 35 | ) 36 | -------------------------------------------------------------------------------- /aws/packer.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "access_key": "{{env `DEPLOY_PACKER_AWS_ACCESS_KEY`}}", 4 | "secret_key": "{{env `DEPLOY_PACKER_AWS_SECRET_KEY`}}", 5 | "version": "{{env `DEPLOY_PACKER_VERSION`}}" 6 | }, 7 | "builders": [{ 8 | "type": "amazon-ebs", 9 | "region": "{region}", 10 | "source_ami_filter": { 11 | "filters": { 12 | "virtualization-type": "hvm", 13 | "name": "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*", 14 | "root-device-type": "ebs" 15 | }, 16 | "owners": ["099720109477"], 17 | "most_recent": true 18 | }, 19 | "instance_type": "t2.medium", 20 | "ssh_username": "ubuntu", 21 | "ami_name": "{ami_name}", 22 | "access_key": "{{user `access_key`}}", 23 | "secret_key": "{{user `secret_key`}}", 24 | "force_deregister": "true", 25 | "force_delete_snapshot": "true" 26 | } 27 | ], 28 | 29 | "provisioners": [ 30 | { 31 | "type": "shell", 32 | "inline": [ "mkdir /tmp/deployment" ] 33 | }, 34 | { 35 | "type": "file", 36 | "source": "files/", 37 | "destination": "/tmp/deployment/" 38 | }, 39 | { 40 | "type": "shell", 41 | "inline": ["sudo /tmp/deployment/{install}"] 42 | } 43 | ] 44 | } 45 | -------------------------------------------------------------------------------- /aws/rules.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("//packer:rules.bzl", "assemble_packer") 21 | load("//common/generate_json_config:rules.bzl", "generate_json_config") 22 | 23 | def assemble_aws(name, 24 | ami_name, 25 | install, 26 | region, 27 | files): 28 | """Assemble files for AWS deployment 29 | 30 | Args: 31 | name: A unique name for this target. 32 | ami_name: AMI name of deployed image 33 | install: Bazel label for install file 34 | region: AWS region to deploy image to 35 | files: Files to include into AWS deployment 36 | """ 37 | install_fn = Label(install).name 38 | generated_config_target_name = name + "__do_not_reference_config" 39 | generate_json_config( 40 | name = generated_config_target_name, 41 | template = "@typedb_bazel_distribution//aws:packer.template.json", 42 | substitutions = { 43 | "{ami_name}": ami_name, 44 | "{install}": install_fn, 45 | "{region}": region 46 | } 47 | ) 48 | files[install] = install_fn 49 | assemble_packer( 50 | name = name, 51 | config = generated_config_target_name, 52 | files = files 53 | ) 54 | -------------------------------------------------------------------------------- /azure/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | exports_files(["packer.template.json"]) 21 | 22 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 23 | 24 | bzl_library( 25 | name = "lib", 26 | srcs = [ 27 | "rules.bzl", 28 | ], 29 | visibility = ["//visibility:public"] 30 | ) 31 | -------------------------------------------------------------------------------- /azure/packer.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "subscription_id": "{{env `DEPLOY_PACKER_AZURE_SUBSCRIPTION_ID`}}", 4 | "client_id": "{{env `DEPLOY_PACKER_AZURE_CLIENT_ID`}}", 5 | "client_secret": "{{env `DEPLOY_PACKER_AZURE_CLIENT_SECRET`}}", 6 | "version": "{{env `DEPLOY_PACKER_VERSION`}}" 7 | }, 8 | "builders": [ 9 | { 10 | "type": "azure-arm", 11 | "subscription_id": "{{user `subscription_id`}}", 12 | "client_id": "{{user `client_id`}}", 13 | "client_secret": "{{user `client_secret`}}", 14 | "managed_image_name": "{image_name}", 15 | "managed_image_resource_group_name": "{resource_group_name}", 16 | "os_type": "Linux", 17 | "image_publisher": "{image_publisher}", 18 | "image_offer": "{image_offer}", 19 | "image_sku": "{image_sku}", 20 | "build_resource_group_name": "{resource_group_name}", 21 | "vm_size": "Standard_B2s", 22 | "os_disk_size_gb": "{disk_size_gb}" 23 | } 24 | ], 25 | 26 | "provisioners": [ 27 | { 28 | "type": "shell", 29 | "inline": [ "mkdir /tmp/deployment" ] 30 | }, 31 | { 32 | "type": "file", 33 | "source": "files/", 34 | "destination": "/tmp/deployment/" 35 | }, 36 | { 37 | "type": "shell", 38 | "inline": [ "sudo /tmp/deployment/{install}" ] 39 | } 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /azure/rules.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("//packer:rules.bzl", "assemble_packer") 21 | load("//common/generate_json_config:rules.bzl", "generate_json_config") 22 | 23 | def assemble_azure(name, 24 | image_name, 25 | resource_group_name, 26 | install, 27 | image_publisher="Canonical", 28 | image_offer="0001-com-ubuntu-server-focal", 29 | image_sku="20_04-lts", 30 | disk_size_gb=60, 31 | files=None): 32 | """Assemble files for Azure deployment 33 | 34 | Args: 35 | name: A unique name for this target. 36 | image_name: name of deployed image 37 | resource_group_name: name of the resource group to place image in 38 | install: Bazel label for install file 39 | image_publisher: Publisher of the image used as base 40 | image_offer: Offer of the image used as base 41 | image_sku: SKU of the image used as base 42 | disk_size_gb: Size of the resulting OS disk 43 | files: Files to include into Azure deployment 44 | """ 45 | if not files: 46 | files = {} 47 | install_fn = Label(install).name 48 | generated_config_target_name = name + "__do_not_reference_config" 49 | generate_json_config( 50 | name = generated_config_target_name, 51 | template = "@typedb_bazel_distribution//azure:packer.template.json", 52 | substitutions = { 53 | "{image_name}": image_name, 54 | "{resource_group_name}": resource_group_name, 55 | "{install}": install_fn, 56 | "{image_publisher}": image_publisher, 57 | "{image_offer}": image_offer, 58 | "{image_sku}": image_sku, 59 | "{disk_size_gb}": str(disk_size_gb), 60 | } 61 | ) 62 | files[install] = install_fn 63 | assemble_packer( 64 | name = name, 65 | config = generated_config_target_name, 66 | files = files 67 | ) 68 | -------------------------------------------------------------------------------- /brew/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 21 | 22 | bzl_library( 23 | name = "lib", 24 | srcs = [ 25 | "rules.bzl" 26 | ], 27 | visibility = ["//visibility:public"] 28 | ) 29 | -------------------------------------------------------------------------------- /brew/templates/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | exports_files(["deploy.py"]) -------------------------------------------------------------------------------- /common/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | exports_files(["archiver.py", "common.py"]) 21 | 22 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 23 | load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") 24 | 25 | bzl_library( 26 | name = "lib", 27 | srcs = [ "rules.bzl" ], 28 | deps = [ 29 | "//common/assemble_versioned:lib", 30 | "//common/checksum:lib", 31 | "//common/generate_json_config:lib", 32 | "//common/java_deps:lib", 33 | "//common/rename:lib", 34 | "//common/targz:lib", 35 | "//common/tgz2zip:lib", 36 | "//common/workspace_refs:lib", 37 | "//common/zip:lib" 38 | ], 39 | visibility = ["//visibility:public"] 40 | ) 41 | 42 | kt_jvm_library( 43 | name = "common", 44 | srcs = glob(["*.kt"]), 45 | deps = [], 46 | visibility = ["//visibility:public"], 47 | ) 48 | -------------------------------------------------------------------------------- /common/Logging.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.typedb.bazel.distribution.common 21 | 22 | object Logging { 23 | class Logger(private val logLevel: LogLevel) { 24 | fun debug(message: () -> String) { 25 | if (logLevel == LogLevel.DEBUG) println(message()) 26 | } 27 | } 28 | 29 | enum class LogLevel { 30 | DEBUG, 31 | ERROR, 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /common/Property.kt: -------------------------------------------------------------------------------- 1 | package com.typedb.bazel.distribution.common 2 | 3 | enum class OS(private val displayName: String) { 4 | WINDOWS("Windows"), 5 | MAC("MacOS"), 6 | LINUX("Linux"); 7 | 8 | override fun toString(): String { 9 | return displayName 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /common/assemble_versioned/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 21 | 22 | bzl_library( 23 | name = "lib", 24 | srcs = [ "rules.bzl" ], 25 | visibility = ["//visibility:public"] 26 | ) 27 | 28 | py_binary( 29 | name = "assemble-versioned", 30 | srcs = ["assemble-versioned.py"], 31 | visibility = ["//visibility:public"] 32 | ) 33 | -------------------------------------------------------------------------------- /common/assemble_versioned/assemble-versioned.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one 5 | # or more contributor license agreements. See the NOTICE file 6 | # distributed with this work for additional information 7 | # regarding copyright ownership. The ASF licenses this file 8 | # to you under the Apache License, Version 2.0 (the 9 | # "License"); you may not use this file except in compliance 10 | # with the License. You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, 15 | # software distributed under the License is distributed on an 16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | # KIND, either express or implied. See the License for the 18 | # specific language governing permissions and limitations 19 | # under the License. 20 | # 21 | 22 | 23 | import os 24 | import sys 25 | import zipfile 26 | 27 | # This ZipFile extends Python's ZipFile and fixes the lost permission issue 28 | class ZipFile(zipfile.ZipFile): 29 | def extract(self, member, path=None, pwd=None): 30 | if not isinstance(member, zipfile.ZipInfo): 31 | member = self.getinfo(member) 32 | 33 | if path is None: 34 | path = os.getcwd() 35 | 36 | ret_val = self._extract_member(member, path, pwd) 37 | attr = member.external_attr >> 16 38 | os.chmod(ret_val, attr) 39 | return ret_val 40 | 41 | 42 | output_path = sys.argv[1] 43 | version_path = sys.argv[2] 44 | target_paths = sys.argv[3:] 45 | 46 | version = open(version_path, 'r').read().strip() 47 | 48 | with ZipFile(output_path, 'w', compression=zipfile.ZIP_STORED) as output: 49 | for target in sorted(target_paths): 50 | if target.endswith('zip') or target.endswith('tar.gz'): 51 | path_components = os.path.basename(target).split('.') 52 | original_zip_basedir = path_components[0] 53 | extension = '.'.join(path_components[1:]) 54 | repackaged_archive_fn = '{}-{}.{}'.format(original_zip_basedir, version, extension) 55 | output.write(target, repackaged_archive_fn) 56 | else: 57 | raise ValueError('This file is neither a zip nor a tar.gz: {}'.format(target)) 58 | -------------------------------------------------------------------------------- /common/assemble_versioned/rules.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | def _assemble_versioned_impl(ctx): 21 | if not ctx.attr.version_file: 22 | version_file = ctx.actions.declare_file(ctx.attr.name + "__do_not_reference.version") 23 | version = ctx.var.get('version', '0.0.0') 24 | 25 | ctx.actions.run_shell( 26 | inputs = [], 27 | outputs = [version_file], 28 | command = "echo {} > {}".format(version, version_file.path) 29 | ) 30 | else: 31 | version_file = ctx.file.version_file 32 | 33 | # assemble-version.py $output $version $targets 34 | ctx.actions.run( 35 | inputs = ctx.files.targets + [version_file], 36 | outputs = [ctx.outputs.archive], 37 | executable = ctx.executable._assemble_versioned_py, 38 | arguments = [ctx.outputs.archive.path, version_file.path] + [target.path for target in ctx.files.targets], 39 | progress_message = "Versioning assembled distributions to {}".format(version_file.short_path) 40 | ) 41 | 42 | return DefaultInfo(data_runfiles = ctx.runfiles(files=[ctx.outputs.archive])) 43 | 44 | assemble_versioned = rule( 45 | attrs = { 46 | "targets": attr.label_list( 47 | allow_files = [".zip", ".tar.gz"], 48 | doc = "Archives to version and put into output archive" 49 | ), 50 | "version_file": attr.label( 51 | allow_single_file = True, 52 | doc = "File containing version string" 53 | ), 54 | "_assemble_versioned_py": attr.label( 55 | default = "//common/assemble_versioned:assemble-versioned", 56 | executable = True, 57 | cfg = "host" 58 | ) 59 | }, 60 | implementation = _assemble_versioned_impl, 61 | outputs = { 62 | "archive": "%{name}.zip" 63 | }, 64 | output_to_genfiles = True, 65 | doc = "Version multiple archives for subsequent simultaneous deployment" 66 | ) 67 | -------------------------------------------------------------------------------- /common/checksum/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 21 | 22 | bzl_library( 23 | name = "lib", 24 | srcs = [ "rules.bzl" ], 25 | visibility = ["//visibility:public"] 26 | ) 27 | -------------------------------------------------------------------------------- /common/checksum/rules.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | def _checksum(ctx): 21 | ctx.actions.run_shell( 22 | inputs = [ctx.file.archive], 23 | outputs = [ctx.outputs.checksum_file], 24 | command = 'shasum -a 256 {} | cut -d" " -f1 > {}'.format(ctx.file.archive.path, ctx.outputs.checksum_file.path) 25 | ) 26 | 27 | checksum = rule( 28 | attrs = { 29 | 'archive': attr.label( 30 | allow_single_file = True, 31 | mandatory = True, 32 | doc = "Archive to compute checksum of" 33 | ) 34 | }, 35 | outputs = { 36 | 'checksum_file': '%{name}.sha256' 37 | }, 38 | implementation = _checksum, 39 | doc = "Computes SHA256 checksum of file" 40 | ) 41 | -------------------------------------------------------------------------------- /common/deps.bzl: -------------------------------------------------------------------------------- 1 | load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") 2 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 3 | 4 | def rules_python(): 5 | git_repository( 6 | name = "rules_python", 7 | remote = "https://github.com/bazelbuild/rules_python.git", 8 | tag = "0.31.0", 9 | ) 10 | 11 | def rules_pkg(): 12 | git_repository( 13 | name = "rules_pkg", 14 | remote = "https://github.com/bazelbuild/rules_pkg", 15 | tag = "0.9.1", 16 | ) 17 | 18 | def rules_kotlin(): 19 | http_archive( 20 | name = "io_bazel_rules_kotlin", 21 | urls = ["https://github.com/typedb/rules_kotlin/archive/c2519b00299cff9df22267e8359784e9948dba67.zip"], 22 | type = "zip", 23 | strip_prefix = "rules_kotlin-c2519b00299cff9df22267e8359784e9948dba67", 24 | sha256 = "1455f2ec4bf7ea12d2c90b0dfd6402553c3bb6cbc0271023e2e01ccdefb4a49a", 25 | ) 26 | 27 | def rules_jvm_external(): 28 | http_archive( 29 | name = "rules_jvm_external", 30 | strip_prefix = "rules_jvm_external-3.2", 31 | sha256 = "82262ff4223c5fda6fb7ff8bd63db8131b51b413d26eb49e3131037e79e324af", 32 | url = "https://github.com/bazelbuild/rules_jvm_external/archive/3.2.zip", 33 | ) 34 | 35 | def rules_rust(): 36 | http_archive( 37 | name = "rules_rust", 38 | sha256 = "9d04e658878d23f4b00163a72da3db03ddb451273eb347df7d7c50838d698f49", 39 | urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.26.0/rules_rust-v0.26.0.tar.gz"], 40 | ) 41 | -------------------------------------------------------------------------------- /common/generate_json_config/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 21 | 22 | bzl_library( 23 | name = "lib", 24 | srcs = [ "rules.bzl" ], 25 | visibility = ["//visibility:public"] 26 | ) 27 | -------------------------------------------------------------------------------- /common/generate_json_config/rules.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | def _generate_json_config_impl(ctx): 21 | ctx.actions.expand_template( 22 | template = ctx.file.template, 23 | output = ctx.outputs.config, 24 | substitutions = ctx.attr.substitutions 25 | ) 26 | 27 | generate_json_config = rule( 28 | attrs = { 29 | "template": attr.label( 30 | allow_single_file = [".json"], 31 | doc = "JSON template to fill in values" 32 | ), 33 | "substitutions": attr.string_dict( 34 | doc = "Values to fill in" 35 | ) 36 | }, 37 | implementation = _generate_json_config_impl, 38 | outputs = { 39 | "config": "%{name}.json" 40 | }, 41 | doc = "Fills in JSON template with provided values" 42 | ) 43 | -------------------------------------------------------------------------------- /common/java_deps/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 21 | 22 | bzl_library( 23 | name = "lib", 24 | srcs = [ "rules.bzl" ], 25 | visibility = ["//visibility:public"] 26 | ) 27 | 28 | py_binary( 29 | name = "java_deps", 30 | srcs = ["java_deps.py"], 31 | visibility = ["//visibility:public"] 32 | ) 33 | 34 | -------------------------------------------------------------------------------- /common/java_deps/java_deps.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one 5 | # or more contributor license agreements. See the NOTICE file 6 | # distributed with this work for additional information 7 | # regarding copyright ownership. The ASF licenses this file 8 | # to you under the Apache License, Version 2.0 (the 9 | # "License"); you may not use this file except in compliance 10 | # with the License. You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, 15 | # software distributed under the License is distributed on an 16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | # KIND, either express or implied. See the License for the 18 | # specific language governing permissions and limitations 19 | # under the License. 20 | # 21 | 22 | from __future__ import print_function 23 | import tarfile 24 | import platform 25 | import json 26 | 27 | import sys 28 | import os 29 | 30 | 31 | WINDOWS = "windows" 32 | 33 | 34 | def tarfile_remove_mtime(info): 35 | info.mtime = 0 36 | return info 37 | 38 | 39 | _, moves_file_location, distribution_tgz_location, version_file_location = sys.argv 40 | with open(moves_file_location) as moves_file: 41 | moves = json.load(moves_file) 42 | 43 | with open(version_file_location) as version_file: 44 | version = version_file.read().strip() 45 | 46 | with tarfile.open(distribution_tgz_location, 'w:gz', dereference=True) as tgz: 47 | for fn, arcfn in sorted(moves.items()): 48 | path = "\\\\?\\" + os.path.abspath(fn) if platform.system() == WINDOWS else fn 49 | tgz.add(path, arcfn.replace('{pom_version}', version), filter=tarfile_remove_mtime) 50 | -------------------------------------------------------------------------------- /common/rename/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 21 | 22 | bzl_library( 23 | name = "lib", 24 | srcs = [ "rules.bzl" ], 25 | visibility = ["//visibility:public"] 26 | ) 27 | -------------------------------------------------------------------------------- /common/rename/rules.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | def _file_rename_impl(ctx): 21 | output_file_name = ctx.attr.output 22 | replace_count = output_file_name.count("{") 23 | start_index = 0 24 | for i in range(replace_count): 25 | open_curly_index = output_file_name.find("{", start_index) 26 | close_curly_index = output_file_name.find("}", start_index) 27 | if open_curly_index == -1 or close_curly_index == -1: 28 | fail("Could not find matching {} from index: {}.".format(start_index)) 29 | variable = output_file_name[open_curly_index + 1: close_curly_index] 30 | value = ctx.var.get(variable) 31 | if value == None: 32 | fail("Cound not find variable '{}' in the context.".format(variable)) 33 | output_file_name = output_file_name.replace("{" + variable + "}", value) 34 | 35 | input_file = ctx.attr.target.files.to_list()[0] 36 | if output_file_name == input_file.short_path: 37 | return DefaultInfo(files = depset([input_file])) 38 | 39 | output_file = ctx.actions.declare_file(output_file_name) 40 | ctx.actions.run_shell( 41 | inputs = [input_file], 42 | command = "cp $1 $2", 43 | arguments = [ctx.attr.target.files.to_list()[0].path, output_file.path], 44 | outputs = [output_file], 45 | ) 46 | 47 | return DefaultInfo( 48 | files = depset([output_file]) 49 | ) 50 | 51 | 52 | file_rename = rule( 53 | implementation = _file_rename_impl, 54 | attrs = { 55 | "target": attr.label( 56 | allow_single_file = True, 57 | mandatory = True, 58 | doc = "Target producing a file to which to append the variable value.", 59 | ), 60 | "output": attr.string( 61 | mandatory = True, 62 | doc = "Output filename to produce. Can substitute defined variables using {variable}.", 63 | ), 64 | } 65 | ) -------------------------------------------------------------------------------- /common/rules.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@typedb_bazel_distribution//common/assemble_versioned:rules.bzl", _assemble_versioned = "assemble_versioned") 21 | load("@typedb_bazel_distribution//common/checksum:rules.bzl", _checksum = "checksum") 22 | load("@typedb_bazel_distribution//common/generate_json_config:rules.bzl", _generate_json_config = "generate_json_config") 23 | load("@typedb_bazel_distribution//common/java_deps:rules.bzl", _java_deps = "java_deps") 24 | load("@typedb_bazel_distribution//common/tgz2zip:rules.bzl", _tgz2zip = "tgz2zip") 25 | load("@typedb_bazel_distribution//common/targz:rules.bzl", _assemble_targz = "assemble_targz") 26 | load("@typedb_bazel_distribution//common/workspace_refs:rules.bzl", _workspace_refs = "workspace_refs") 27 | load("@typedb_bazel_distribution//common/zip:rules.bzl", _assemble_zip = "assemble_zip", _unzip_file = "unzip_file") 28 | load("@typedb_bazel_distribution//common/rename:rules.bzl", _file_rename = "file_rename") 29 | 30 | assemble_targz = _assemble_targz 31 | assemble_versioned = _assemble_versioned 32 | assemble_zip = _assemble_zip 33 | checksum = _checksum 34 | file_rename = _file_rename 35 | generate_json_config = _generate_json_config 36 | java_deps = _java_deps 37 | tgz2zip = _tgz2zip 38 | unzip_file = _unzip_file 39 | workspace_refs = _workspace_refs 40 | -------------------------------------------------------------------------------- /common/shell/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") 21 | 22 | kt_jvm_library( 23 | name = "shell", 24 | srcs = glob(["*.kt"]), 25 | deps = [ 26 | "@typedb_bazel_distribution//common", 27 | 28 | "@maven//:org_zeroturnaround_zt_exec", 29 | ], 30 | visibility = ["//visibility:public"], 31 | ) 32 | -------------------------------------------------------------------------------- /common/shell/Shell.kt: -------------------------------------------------------------------------------- 1 | package com.typedb.bazel.distribution.common.shell 2 | 3 | import com.typedb.bazel.distribution.common.shell.Shell.Command.Companion.arg 4 | import com.typedb.bazel.distribution.common.Logging.Logger 5 | import org.zeroturnaround.exec.ProcessExecutor 6 | import org.zeroturnaround.exec.ProcessResult 7 | import java.nio.file.Path 8 | import java.nio.file.Paths 9 | 10 | class Shell(private val logger: Logger, private val verbose: Boolean = false, private val printSensitiveData: Boolean = false) { 11 | fun execute( 12 | command: List, baseDir: Path = Paths.get("."), 13 | env: Map = mapOf(), outputIsSensitive: Boolean = false, throwOnError: Boolean = true 14 | ): ProcessResult { 15 | return execute(Command(*command.map { arg(it) }.toTypedArray()), baseDir, env, outputIsSensitive, throwOnError) 16 | } 17 | 18 | fun execute( 19 | command: Command, baseDir: Path = Paths.get("."), 20 | env: Map = mapOf(), outputIsSensitive: Boolean = false, throwOnError: Boolean = true 21 | ): ProcessResult { 22 | val executor = ProcessExecutor(command.args.map { it.value }).apply { 23 | readOutput(true) 24 | redirectError(System.err) 25 | directory(baseDir.toFile()) 26 | environment(env) 27 | if (shouldPrintOutput(outputIsSensitive)) redirectOutput(System.out) 28 | } 29 | 30 | return executor.execute().also { 31 | val message = "Execution of $command finished with exit code '${it.exitValue}'" 32 | if (it.exitValue != 0 && throwOnError) throw IllegalStateException(message) 33 | else if (verbose) logger.debug { "Execution of $command finished with exit code '${it.exitValue}'" } 34 | } 35 | } 36 | 37 | private fun shouldPrintOutput(sensitive: Boolean): Boolean { 38 | return verbose && (!sensitive || printSensitiveData) 39 | } 40 | 41 | class Command(val args: List) { 42 | constructor(vararg args: Argument): this(args.toList()) 43 | 44 | override fun toString(): String { 45 | return args.toString() 46 | } 47 | 48 | companion object { 49 | fun arg(value: String, printable: Boolean = true) = Argument(value, printable) 50 | } 51 | 52 | class Argument(val value: String, private val printable: Boolean = true) { 53 | override fun toString(): String { 54 | return if (printable) value else "(hidden)" 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /common/targz/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 21 | 22 | bzl_library( 23 | name = "lib", 24 | srcs = [ "rules.bzl" ], 25 | visibility = ["//visibility:public"] 26 | ) 27 | -------------------------------------------------------------------------------- /common/tgz2zip/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 21 | 22 | bzl_library( 23 | name = "lib", 24 | srcs = [ "rules.bzl" ], 25 | visibility = ["//visibility:public"] 26 | ) 27 | 28 | py_binary( 29 | name = "tgz2zip", 30 | srcs = ["tgz2zip.py"], 31 | visibility = ["//visibility:public"] 32 | ) 33 | -------------------------------------------------------------------------------- /common/tgz2zip/rules.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | def _tgz2zip_impl(ctx): 21 | ctx.actions.run( 22 | inputs = [ctx.file.tgz], 23 | outputs = [ctx.outputs.zip], 24 | executable = ctx.executable._tgz2zip_py, 25 | arguments = [ctx.file.tgz.path, ctx.outputs.zip.path], 26 | progress_message = "Converting {} to {}".format(ctx.file.tgz.short_path, ctx.outputs.zip.short_path) 27 | ) 28 | 29 | return DefaultInfo(data_runfiles = ctx.runfiles(files=[ctx.outputs.zip])) 30 | 31 | 32 | tgz2zip = rule( 33 | attrs = { 34 | "tgz": attr.label( 35 | allow_single_file=[".tar.gz"], 36 | mandatory = True, 37 | doc = "Input .tar.gz archive" 38 | ), 39 | "output_filename": attr.string( 40 | mandatory = True, 41 | doc = 'Resulting filename' 42 | ), 43 | "_tgz2zip_py": attr.label( 44 | default = "//common/tgz2zip", 45 | executable = True, 46 | cfg = "host" 47 | ) 48 | }, 49 | implementation = _tgz2zip_impl, 50 | outputs = { 51 | "zip": "%{output_filename}.zip" 52 | }, 53 | output_to_genfiles = True, 54 | doc = 'Converts .tar.gz into .zip' 55 | ) 56 | -------------------------------------------------------------------------------- /common/tgz2zip/tgz2zip.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one 5 | # or more contributor license agreements. See the NOTICE file 6 | # distributed with this work for additional information 7 | # regarding copyright ownership. The ASF licenses this file 8 | # to you under the Apache License, Version 2.0 (the 9 | # "License"); you may not use this file except in compliance 10 | # with the License. You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, 15 | # software distributed under the License is distributed on an 16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | # KIND, either express or implied. See the License for the 18 | # specific language governing permissions and limitations 19 | # under the License. 20 | # 21 | 22 | from __future__ import print_function 23 | import os 24 | import stat 25 | 26 | import sys 27 | import zipfile 28 | import tarfile 29 | 30 | _, tgz_fn, zip_fn = sys.argv 31 | 32 | 33 | with tarfile.open(tgz_fn, mode='r:gz') as tgz: 34 | with zipfile.ZipFile(zip_fn, 'w', compression=zipfile.ZIP_DEFLATED) as zip: 35 | for tarinfo in sorted(tgz.getmembers(), key=lambda x: x.name): 36 | f = '' 37 | is_dir = tarinfo.isdir() 38 | name = os.path.normpath(tarinfo.name) 39 | if not is_dir: 40 | f = tgz.extractfile(tarinfo).read() 41 | else: 42 | name += '/' 43 | zi = zipfile.ZipInfo(name) 44 | zi.compress_type = zipfile.ZIP_DEFLATED 45 | zi.external_attr = tarinfo.mode << 16 46 | if not is_dir: 47 | # Mark regular files with S_IFREG so 48 | # permissions are preserved when unpacking 49 | # in macOS's Finder 50 | zi.external_attr |= (stat.S_IFREG << 16) 51 | zip.writestr(zi, f) 52 | -------------------------------------------------------------------------------- /common/uploader/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | load("@typedb_bazel_distribution_uploader//:requirements.bzl", cloudsmith_requirement = "requirement") 20 | 21 | py_library( 22 | name = "uploader", 23 | srcs = glob(["*.py"]), 24 | deps = [cloudsmith_requirement("requests")], 25 | visibility = ["//visibility:public"], 26 | ) 27 | -------------------------------------------------------------------------------- /common/uploader/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typedb/bazel-distribution/056a8d7ede9b552d23dcfdc2d47b9395510652f4/common/uploader/__init__.py -------------------------------------------------------------------------------- /common/uploader/deps.bzl: -------------------------------------------------------------------------------- 1 | load("@rules_python//python:pip.bzl", "pip_parse") 2 | 3 | def typedb_bazel_distribution_uploader(): 4 | pip_parse( 5 | name = "typedb_bazel_distribution_uploader", 6 | requirements_lock = "@typedb_bazel_distribution//common/uploader:requirements.txt", 7 | ) 8 | -------------------------------------------------------------------------------- /common/uploader/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.28.2 2 | certifi==2022.12.7 3 | charset-normalizer==3.0.1 4 | idna==3.4 5 | urllib3==1.26.14 6 | -------------------------------------------------------------------------------- /common/uploader/uploader.py: -------------------------------------------------------------------------------- 1 | import os 2 | from abc import ABC,abstractmethod 3 | 4 | class DeploymentException(Exception): 5 | def __init__(self, msg, response=None): 6 | self.msg = msg 7 | self.response = response 8 | 9 | def __str__(self): 10 | ret = "DeploymentException: %s" % (self.msg) 11 | if self.response is not None: 12 | ret += ". HTTP response was [%d]: %s" % (self.response.status_code, self.response.text) 13 | return ret 14 | 15 | class Uploader(ABC): 16 | @staticmethod 17 | def create(username, password, repo_url): 18 | if repo_url.startswith("cloudsmith"): 19 | from .cloudsmith import CloudsmithUploader 20 | return CloudsmithUploader(username, password, repo_url) 21 | elif repo_url.startswith("http"): 22 | from .nexus import NexusUploader 23 | return NexusUploader(username, password, repo_url) 24 | else: 25 | raise ValueError("Unrecognised url: ", repo_url) 26 | 27 | @staticmethod 28 | def _maven_names(artifact_id, version, sources_path, javadoc_path, tests_path): 29 | filename_base = '{artifact}-{version}'.format(artifact=artifact_id, version=version) 30 | jar_filename = filename_base + ".jar" 31 | pom_filename = filename_base + ".pom" 32 | sources_filename = filename_base + "-sources.jar" if sources_path and os.path.exists(sources_path) else None 33 | javadoc_filename = filename_base + "-javadoc.jar" if javadoc_path and os.path.exists(javadoc_path) else None 34 | tests_path = filename_base + "-tests.jar" if tests_path and os.path.exists(tests_path) else None 35 | return jar_filename, pom_filename, sources_filename, javadoc_filename, tests_path 36 | 37 | # Specific 38 | @abstractmethod 39 | def apt(self, deb_file, distro, opts={}): 40 | raise NotImplementedError("Abstract") 41 | 42 | @abstractmethod 43 | def artifact(self, artifact_group, version, artifact_path, filename, opts={}): 44 | raise NotImplementedError("Abstract") 45 | 46 | @abstractmethod 47 | def helm(self, tar_path, opts={}): 48 | raise NotImplementedError("Abstract") 49 | 50 | @abstractmethod 51 | def maven(self, group_id, artifact_id, version, 52 | jar_path, pom_path, 53 | sources_path=None, javadoc_path=None, tests_path = None, 54 | should_sign = True, 55 | opts={}): 56 | raise NotImplementedError("Abstract") 57 | -------------------------------------------------------------------------------- /common/util/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") 21 | 22 | kt_jvm_library( 23 | name = "util", 24 | srcs = glob(["*.kt"]), 25 | deps = [ 26 | "@typedb_bazel_distribution//common" 27 | ], 28 | visibility = ["//visibility:public"], 29 | ) 30 | -------------------------------------------------------------------------------- /common/util/FileUtil.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.typedb.bazel.distribution.common.util 21 | 22 | import java.io.File 23 | 24 | object FileUtil { 25 | fun File.listFilesRecursively(): List { 26 | if (isFile) return listOf(this) 27 | if (!isDirectory) return emptyList() 28 | return listFiles()!!.flatMap { it.listFilesRecursively() } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /common/util/PropertiesUtil.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.typedb.bazel.distribution.common.util 21 | 22 | import java.util.Properties 23 | 24 | object PropertiesUtil { 25 | fun require(key: String, value: String?): String { 26 | if (value.isNullOrBlank()) throw IllegalStateException("Missing value for required property '$key'") 27 | return value 28 | } 29 | 30 | fun Properties.getStringOrNull(key: String): String? { 31 | return getProperty(key) 32 | } 33 | 34 | fun Properties.requireString(key: String): String { 35 | return require(key, getProperty(key)) 36 | } 37 | 38 | fun Properties.getBooleanOrDefault(key: String, defaultValue: Boolean = false): Boolean { 39 | return getProperty(key)?.toBoolean() ?: defaultValue 40 | } 41 | 42 | fun Properties.requireBoolean(key: String): Boolean { 43 | return require(key, getProperty(key)).toBoolean() 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /common/util/SystemUtil.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.typedb.bazel.distribution.common.util 21 | 22 | import com.typedb.bazel.distribution.common.OS 23 | import com.typedb.bazel.distribution.common.OS.LINUX 24 | import com.typedb.bazel.distribution.common.OS.MAC 25 | import com.typedb.bazel.distribution.common.OS.WINDOWS 26 | import java.util.Locale.ENGLISH 27 | 28 | object SystemUtil { 29 | val currentOS: OS 30 | get() { 31 | val osName = System.getProperty("os.name").lowercase(ENGLISH) 32 | return when { 33 | "mac" in osName || "darwin" in osName -> MAC 34 | "win" in osName -> WINDOWS 35 | else -> LINUX 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /common/workspace_refs/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 21 | 22 | bzl_library( 23 | name = "lib", 24 | srcs = [ "rules.bzl" ], 25 | visibility = ["//visibility:public"] 26 | ) 27 | -------------------------------------------------------------------------------- /common/workspace_refs/rules.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | def _workspace_refs_impl(repository_ctx): 21 | repository_ctx.file('BUILD', content='exports_files(["refs.json"])', executable=False) 22 | workspace_refs_dict = { 23 | "commits": repository_ctx.attr.workspace_commit_dict, 24 | "tags": repository_ctx.attr.workspace_tag_dict, 25 | } 26 | repository_ctx.file('refs.json', content=struct(**workspace_refs_dict).to_json(), executable=False) 27 | 28 | 29 | _workspace_refs = repository_rule( 30 | implementation = _workspace_refs_impl, 31 | attrs = { 32 | 'workspace_commit_dict': attr.string_dict(), 33 | 'workspace_tag_dict': attr.string_dict(), 34 | }, 35 | ) 36 | 37 | def workspace_refs(name): 38 | 39 | workspace_commit_dict = {} 40 | workspace_tag_dict = {} 41 | 42 | for k, v in native.existing_rules().items(): 43 | if 'tags' in v: 44 | for t in v['tags']: 45 | key, eq, value = t.partition("=") 46 | if eq == "=": 47 | if key == "tag": 48 | workspace_tag_dict[k] = value 49 | elif key == "commit": 50 | workspace_commit_dict[k] = value 51 | 52 | if 'tag' in v and len(v['tag'])>0: 53 | workspace_tag_dict[k] = v['tag'] 54 | elif 'commit' in v and len(v['commit'])>0: 55 | workspace_commit_dict[k] = v['commit'] 56 | 57 | 58 | _workspace_refs( 59 | name = name, 60 | workspace_commit_dict = workspace_commit_dict, 61 | workspace_tag_dict = workspace_tag_dict 62 | ) 63 | -------------------------------------------------------------------------------- /common/zip/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 21 | 22 | bzl_library( 23 | name = "lib", 24 | srcs = [ "rules.bzl" ], 25 | visibility = ["//visibility:public"] 26 | ) 27 | -------------------------------------------------------------------------------- /common/zip/rules.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # This program is free software: you can redistribute it and/or modify 3 | # it under the terms of the GNU Affero General Public License as 4 | # published by the Free Software Foundation, either version 3 of the 5 | # License, or (at your option) any later version. 6 | # 7 | # This program is distributed in the hope that it will be useful, 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | # GNU Affero General Public License for more details. 11 | # 12 | # You should have received a copy of the GNU Affero General Public License 13 | # along with this program. If not, see . 14 | # 15 | 16 | load("@typedb_bazel_distribution//common/targz:rules.bzl", "assemble_targz") 17 | load("@typedb_bazel_distribution//common/tgz2zip:rules.bzl", "tgz2zip") 18 | 19 | def assemble_zip( 20 | name, 21 | output_filename, 22 | targets = [], 23 | additional_files = {}, 24 | empty_directories = [], 25 | permissions = {}, 26 | append_version = True, 27 | visibility = ["//visibility:private"], 28 | tags = [], 29 | target_compatible_with = []): 30 | """Assemble distribution archive (.zip) 31 | 32 | Args: 33 | name: A unique name for this target. 34 | output_filename: filename of resulting archive 35 | targets: Bazel labels of archives that go into .tar.gz package 36 | additional_files: mapping between Bazel labels of files that go into archive 37 | and their resulting location in archive 38 | empty_directories: list of empty directories created at archive installation 39 | permissions: mapping between paths and UNIX permissions 40 | append_version: append version to root folder inside the archive 41 | visibility: controls whether the target can be used by other packages 42 | """ 43 | assemble_targz( 44 | name = "{}__do_not_reference__targz".format(name), 45 | output_filename = output_filename, 46 | targets = targets, 47 | additional_files = additional_files, 48 | empty_directories = empty_directories, 49 | permissions = permissions, 50 | append_version = append_version, 51 | visibility = ["//visibility:private"], 52 | target_compatible_with = target_compatible_with, 53 | ) 54 | tgz2zip( 55 | name = name, 56 | tgz = ":{}__do_not_reference__targz".format(name), 57 | output_filename = output_filename, 58 | visibility = visibility, 59 | tags = tags, 60 | ) 61 | 62 | def unzip_file(name, target, output, **kwargs): 63 | """Unzip a single-file archive 64 | 65 | Args: 66 | name: unique name for this target 67 | target: single input .zip archive 68 | output: name for the unzipped file 69 | """ 70 | native.genrule( 71 | name = name, 72 | srcs = [target], 73 | outs = [output], 74 | tools = ["@bazel_tools//tools/zip:zipper"], 75 | cmd_bash = "mkdir -p $(@D)/tmp && $(location @bazel_tools//tools/zip:zipper) x $< -d $(@D)/tmp && mv $(@D)/tmp/* $@", 76 | cmd_bat = "MD $(@D)\\tmp && $(location @bazel_tools//tools/zip:zipper) x $< -d $(@D)\\tmp && MOVE $(@D)\\tmp\\* $@", 77 | **kwargs 78 | ) 79 | -------------------------------------------------------------------------------- /crates/BUILD: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | exports_files(["rules.bzl"]) 20 | 21 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 22 | load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") 23 | 24 | bzl_library( 25 | name = "lib", 26 | srcs = [ 27 | "rules.bzl", 28 | ], 29 | deps = [ 30 | "@rules_rust//rust:bzl_lib" 31 | ], 32 | visibility = ["//visibility:public"], 33 | ) 34 | 35 | kt_jvm_library( 36 | name = "crate-assembler-lib", 37 | srcs = [ 38 | "CrateAssembler.kt", 39 | ], 40 | deps = [ 41 | "@maven//:com_eclipsesource_minimal_json_minimal_json", 42 | "@maven//:com_electronwill_night_config_core", 43 | "@maven//:com_electronwill_night_config_toml", 44 | "@maven//:info_picocli_picocli", 45 | "@maven//:org_apache_commons_commons_compress", 46 | ], 47 | ) 48 | 49 | java_binary( 50 | name = "crate-assembler", 51 | main_class = "com.typedb.bazel.distribution.crates.CrateAssemblerKt", 52 | visibility = ["//visibility:public"], 53 | runtime_deps = [ 54 | ":crate-assembler-lib", 55 | ], 56 | ) 57 | 58 | kt_jvm_library( 59 | name = "crate-deployer-lib", 60 | srcs = [ 61 | "CrateDeployer.kt", 62 | ], 63 | deps = [ 64 | "@maven//:com_eclipsesource_minimal_json_minimal_json", 65 | "@maven//:com_google_http_client_google_http_client", 66 | "@maven//:info_picocli_picocli", 67 | ], 68 | ) 69 | 70 | java_binary( 71 | name = "crate-deployer", 72 | main_class = "com.typedb.bazel.distribution.crates.CrateDeployerKt", 73 | visibility = ["//visibility:public"], 74 | runtime_deps = [ 75 | ":crate-deployer-lib", 76 | ], 77 | ) 78 | -------------------------------------------------------------------------------- /crates/CrateDeployer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.typedb.bazel.distribution.crates 21 | 22 | import com.eclipsesource.json.Json 23 | import com.google.api.client.http.* 24 | import com.google.api.client.http.javanet.NetHttpTransport 25 | import picocli.CommandLine 26 | import picocli.CommandLine.Command 27 | import picocli.CommandLine.Option 28 | import picocli.CommandLine.Parameters 29 | import java.io.File 30 | import java.util.concurrent.Callable 31 | import kotlin.system.exitProcess 32 | import java.nio.ByteBuffer 33 | import java.nio.ByteOrder 34 | 35 | 36 | enum class CrateRepoType { 37 | Snapshot, 38 | Release, 39 | } 40 | 41 | 42 | @Command(name = "crate-deployer", mixinStandardHelpOptions = true) 43 | class CrateDeployer : Callable { 44 | @Option(names = ["--crate"], required = true) 45 | lateinit var crate: File 46 | 47 | @Option(names = ["--metadata-json"], required = true) 48 | lateinit var metadataJson: File 49 | 50 | @Option(names = ["--snapshot-repo"], required = true) 51 | lateinit var snapshotRepo: String 52 | 53 | @Option(names = ["--release-repo"], required = true) 54 | lateinit var releaseRepo: String 55 | 56 | @Parameters(index = "0") 57 | lateinit var releaseMode: CrateRepoType 58 | 59 | private val repoUrl: String 60 | get() = when (releaseMode) { 61 | CrateRepoType.Snapshot -> snapshotRepo.trim('/') 62 | CrateRepoType.Release -> releaseRepo.trim('/') 63 | } + "/api/v1/crates/new" 64 | 65 | private val token = System.getenv("DEPLOY_CRATE_TOKEN") ?: throw RuntimeException( 66 | "token should be passed via DEPLOY_CRATE_TOKEN token" 67 | ) 68 | 69 | override fun call() { 70 | val metadataJsonContent = metadataJson.readBytes() 71 | val crateContent = crate.readBytes() 72 | /* 73 | * Cargo repository expects a single-part body containing both metadata in JSON 74 | * and the actual crate in a tarball. Each part is prefixed with a 75 | * 32-bit little-endian length identifier. 76 | */ 77 | val payload = ByteBuffer.allocate(Int.SIZE_BYTES + metadataJsonContent.size + Int.SIZE_BYTES + crateContent.size) 78 | .order(ByteOrder.LITTLE_ENDIAN) 79 | .putInt(metadataJsonContent.size) 80 | .put(metadataJsonContent) 81 | .putInt(crateContent.size) 82 | .put(crateContent) 83 | .array() 84 | 85 | val response = httpPut(repoUrl, token, payload).parseAsString() 86 | if (response.isNotBlank()) { 87 | // for invalid uploads, crates.io responds with 200 HTTP OK 88 | // but response contains a JSON object with validation errors 89 | val responseJson = Json.parse(response).asObject() 90 | if (responseJson.get("errors") != null) { 91 | println("Could not deploy crate; server responded with '$responseJson'") 92 | exitProcess(1) 93 | } 94 | } 95 | } 96 | 97 | private fun httpPut(url: String, token: String, content: ByteArray): HttpResponse { 98 | return NetHttpTransport() 99 | .createRequestFactory() 100 | .buildPutRequest(GenericUrl(url), ByteArrayContent(null, content)) // TODO: Verify it works with crates.io 101 | .setHeaders( 102 | HttpHeaders().setAuthorization(token) 103 | ) 104 | .execute() 105 | } 106 | } 107 | 108 | fun main(args: Array): Unit = 109 | exitProcess(CommandLine(CrateDeployer()).setCaseInsensitiveEnumValuesAllowed(true).execute(*args)) 110 | -------------------------------------------------------------------------------- /crates/templates/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | exports_files(["deploy.sh"]) 21 | -------------------------------------------------------------------------------- /crates/templates/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # 20 | 21 | exec java -jar "$DEPLOYER_PATH" \ 22 | --crate="$CRATE_PATH" \ 23 | --metadata-json="$METADATA_JSON_PATH" \ 24 | --snapshot-repo="$SNAPSHOT_REPO" \ 25 | --release-repo="$RELEASE_REPO" "$*" 26 | -------------------------------------------------------------------------------- /doc_hub.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | # File which loads *all* rules to make them visible for doc generation 21 | # Rules *do* need to be reexported because otherwise they are not visible 22 | 23 | load("//apt:rules.bzl", _assemble_apt = "assemble_apt", _deploy_apt = "deploy_apt") 24 | 25 | load("//aws:rules.bzl", _assemble_aws = "assemble_aws") 26 | 27 | load("//azure:rules.bzl", _assemble_azure = "assemble_azure") 28 | 29 | load("//brew:rules.bzl", _deploy_brew = "deploy_brew") 30 | 31 | load("//common/assemble_versioned:rules.bzl", _assemble_versioned = "assemble_versioned") 32 | 33 | load("//common/checksum:rules.bzl", _checksum = "checksum") 34 | 35 | load("//common/generate_json_config:rules.bzl", _generate_json_config = "generate_json_config") 36 | 37 | load("//common/java_deps:rules.bzl", 38 | _MAVEN_COORDINATES_PREFIX = "MAVEN_COORDINATES_PREFIX", 39 | _JarToMavenCoordinatesMapping = "JarToMavenCoordinatesMapping", 40 | _TransitiveJarToMavenCoordinatesMapping = "TransitiveJarToMavenCoordinatesMapping", 41 | _java_deps = "java_deps", 42 | ) 43 | 44 | load("//common:rules.bzl", _assemble_targz = "assemble_targz", _assemble_zip = "assemble_zip") 45 | 46 | load("//common/tgz2zip:rules.bzl", _tgz2zip = "tgz2zip") 47 | 48 | load("//crates:rules.bzl", _assemble_crate = "assemble_crate", _deploy_crate = "deploy_crate") 49 | 50 | load("//docs/doxygen:rules.bzl", _doxygen_docs = "doxygen_docs") 51 | load("//docs/python:rules.bzl", _sphinx_docs = "sphinx_docs") 52 | 53 | load("//gcp:rules.bzl", _assemble_gcp = "assemble_gcp") 54 | 55 | load('//github:rules.bzl', _deploy_github = "deploy_github") 56 | 57 | load('//maven:rules.bzl', 58 | _JarInfo = "JarInfo", 59 | _MavenDeploymentInfo = "MavenDeploymentInfo", 60 | _assemble_maven = "assemble_maven", 61 | _deploy_maven = "deploy_maven", 62 | ) 63 | 64 | load("//npm:rules.bzl", _assemble_npm = "assemble_npm", _deploy_npm = "deploy_npm") 65 | 66 | load("//packer:rules.bzl", _assemble_packer = "assemble_packer", _deploy_packer = "deploy_packer") 67 | 68 | load("//pip:rules.bzl", _assemble_pip = "assemble_pip", _deploy_pip = "deploy_pip") 69 | 70 | assemble_apt = _assemble_apt 71 | deploy_apt = _deploy_apt 72 | 73 | assemble_aws = _assemble_aws 74 | 75 | assemble_azure = _assemble_azure 76 | 77 | deploy_brew = _deploy_brew 78 | 79 | assemble_versioned = _assemble_versioned 80 | 81 | checksum = _checksum 82 | 83 | generate_json_config = _generate_json_config 84 | 85 | MAVEN_COORDINATES_PREFIX = _MAVEN_COORDINATES_PREFIX 86 | JarToMavenCoordinatesMapping = _JarToMavenCoordinatesMapping 87 | TransitiveJarToMavenCoordinatesMapping = _TransitiveJarToMavenCoordinatesMapping 88 | java_deps = _java_deps 89 | 90 | assemble_targz = _assemble_targz 91 | assemble_zip = _assemble_zip 92 | 93 | tgz2zip = _tgz2zip 94 | 95 | assemble_crate = _assemble_crate 96 | deploy_crate = _deploy_crate 97 | 98 | doxygen_docs = _doxygen_docs 99 | sphinx_docs = _sphinx_docs 100 | 101 | assemble_gcp = _assemble_gcp 102 | 103 | deploy_github = _deploy_github 104 | 105 | JarInfo = _JarInfo 106 | MavenDeploymentInfo = _MavenDeploymentInfo 107 | assemble_maven = _assemble_maven 108 | deploy_maven = _deploy_maven 109 | 110 | assemble_npm = _assemble_npm 111 | deploy_npm = _deploy_npm 112 | 113 | assemble_packer = _assemble_packer 114 | deploy_packer = _deploy_packer 115 | 116 | assemble_pip = _assemble_pip 117 | deploy_pip = _deploy_pip 118 | -------------------------------------------------------------------------------- /docs/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | exports_files(["doxygen/doxyfile.template"]) 21 | 22 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 23 | load("@typedb_bazel_distribution_docs_py//:requirements.bzl", docs_requirement = "requirement") 24 | 25 | py_binary( 26 | name = "sphinx_runner", 27 | srcs = [ 28 | "python/sphinx_html_builder.py", 29 | ], 30 | main = "sphinx_html_builder.py", 31 | deps = [docs_requirement("sphinx")], 32 | visibility = ["//visibility:public"] 33 | ) 34 | 35 | bzl_library( 36 | name = "lib", 37 | srcs = [ 38 | "doxygen/rules.bzl", 39 | "python/rules.bzl", 40 | ], 41 | deps = [], 42 | visibility = ["//visibility:public"], 43 | ) 44 | -------------------------------------------------------------------------------- /docs/doxygen/doxyfile.template: -------------------------------------------------------------------------------- 1 | # Doxyfile 1.9.8 2 | 3 | # This file describes the settings to be used by the documentation system 4 | # doxygen (www.doxygen.org) for a project. 5 | # 6 | # All text after a double hash (##) is considered a comment and is placed in 7 | # front of the TAG it is preceding. 8 | # 9 | # All text after a single hash (#) is considered a comment and will be ignored. 10 | # The format is: 11 | # TAG = value [value, ...] 12 | # For lists, items can also be appended using: 13 | # TAG += value [value, ...] 14 | # Values that contain spaces should be placed between quotes (\" \"). 15 | #--------------------------------------------------------------------------- 16 | # NOTE: 17 | # This file has been cleaned up for doxygen doc generation via bazel 18 | # To see all the options, generate a fresh one with 19 | # `doxygen -g ` 20 | 21 | #--------------------------------------------------------------------------- 22 | # Project related configuration options 23 | #--------------------------------------------------------------------------- 24 | DOXYFILE_ENCODING = UTF-8 25 | PROJECT_NAME = ##{{PROJECT_NAME}} 26 | PROJECT_NUMBER = ##{{PROJECT_NUMBER}} 27 | PROJECT_BRIEF = ##{{PROJECT_BRIEF}} 28 | OUTPUT_DIRECTORY = ##{{OUTPUT_DIRECTORY}} 29 | CREATE_SUBDIRS = NO 30 | ALLOW_UNICODE_NAMES = NO 31 | OUTPUT_LANGUAGE = English 32 | 33 | BRIEF_MEMBER_DESC = YES 34 | ALWAYS_DETAILED_SEC = YES 35 | REPEAT_BRIEF = YES 36 | STRIP_FROM_PATH = ##{{STRIP_FROM_PATH}} 37 | INHERIT_DOCS = YES 38 | INLINE_INHERITED_MEMB = NO 39 | 40 | MARKDOWN_SUPPORT = YES 41 | AUTOLINK_SUPPORT = YES 42 | FILE_PATTERNS = *.h *.hpp *.md *.html 43 | CASE_SENSE_NAMES = NO 44 | 45 | #--------------------------------------------------------------------------- 46 | # Build related configuration options 47 | #--------------------------------------------------------------------------- 48 | HIDE_FRIEND_COMPOUNDS = YES 49 | SHOW_HEADERFILE = NO ## Show which header to include 50 | SHOW_INCLUDE_FILES = NO 51 | SORT_BRIEF_DOCS = NO ## NO: The short description at the top is in declaration order 52 | SORT_MEMBER_DOCS = YES ## YES: The longer description which follows is sorted alphabetically 53 | SORT_BY_SCOPE_NAME = NO 54 | 55 | #--------------------------------------------------------------------------- 56 | # Configuration options related to warning and progress messages 57 | #--------------------------------------------------------------------------- 58 | QUIET = NO 59 | WARNINGS = YES 60 | WARN_IF_UNDOCUMENTED = YES 61 | WARN_IF_DOC_ERROR = YES 62 | WARN_IF_INCOMPLETE_DOC = YES 63 | WARN_NO_PARAMDOC = YES 64 | WARN_IF_UNDOC_ENUM_VAL = YES 65 | WARN_AS_ERROR = NO 66 | 67 | #--------------------------------------------------------------------------- 68 | # Configuration options related to the input files 69 | #--------------------------------------------------------------------------- 70 | INPUT = ##{{INPUT}} 71 | INPUT_ENCODING = UTF-8 72 | RECURSIVE = NO ## bazel explicitly specifies files 73 | EXCLUDE_SYMLINKS = NO ## bazel needs NO 74 | USE_MDFILE_AS_MAINPAGE = ##{{USE_MDFILE_AS_MAINPAGE}} 75 | VERBATIM_HEADERS = YES 76 | 77 | #--------------------------------------------------------------------------- 78 | # Configuration options related to the alphabetical class index 79 | #--------------------------------------------------------------------------- 80 | ALPHABETICAL_INDEX = YES 81 | 82 | #--------------------------------------------------------------------------- 83 | # Configuration options related to the HTML output 84 | #--------------------------------------------------------------------------- 85 | GENERATE_HTML = YES 86 | HTML_OUTPUT = html 87 | HTML_FILE_EXTENSION = .html 88 | HTML_COLORSTYLE = AUTO_LIGHT 89 | ENUM_VALUES_PER_LINE = 4 90 | OBFUSCATE_EMAILS = YES 91 | SEARCHENGINE = YES 92 | 93 | GENERATE_LATEX = NO 94 | 95 | #--------------------------------------------------------------------------- 96 | # Configuration options related to diagram generator tools 97 | #--------------------------------------------------------------------------- 98 | HIDE_UNDOC_RELATIONS = YES 99 | CLASS_GRAPH = YES 100 | HAVE_DOT = NO ## Disables many details 101 | 102 | #--------------------------------------------------------------------------- 103 | # Configuration options related to optional content included to the output 104 | #--------------------------------------------------------------------------- 105 | EXTRACT_STATIC = YES 106 | -------------------------------------------------------------------------------- /docs/doxygen/rules.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | def _doxygen_docs_impl(ctx): 21 | output_directory = ctx.actions.declare_directory(ctx.attr._output_directory) 22 | files = [] 23 | for target in ctx.attr.sources: 24 | files.extend(target.files.to_list()) 25 | 26 | replacements = { 27 | "PROJECT_NAME": '"' + ctx.attr.project_name + '"', 28 | "PROJECT_NUMBER" : ctx.attr.version, 29 | "PROJECT_BRIEF" : ctx.attr.desc, 30 | "OUTPUT_DIRECTORY" : output_directory.path, 31 | "STRIP_FROM_PATH": ctx.attr.strip_prefix, 32 | } 33 | if ctx.file.main_page_md != None: 34 | files.append(ctx.file.main_page_md) 35 | replacements["USE_MDFILE_AS_MAINPAGE"] = ctx.file.main_page_md.path 36 | 37 | replacements["INPUT"] = " ".join([f.path for f in files]) 38 | 39 | # Prepare doxyfile 40 | doxyfile = ctx.actions.declare_file("%s.doxyfile" % ctx.attr.name) 41 | ctx.actions.expand_template( 42 | template = ctx.file._doxyfile_template, 43 | output = doxyfile, 44 | substitutions = {"##{{%s}}"%k : replacements[k] for k in replacements} 45 | ) 46 | 47 | files = [doxyfile] + files 48 | print(doxyfile.path) 49 | ctx.actions.run( 50 | inputs = files, 51 | outputs = [output_directory], 52 | arguments = [doxyfile.path], 53 | executable = "doxygen", 54 | use_default_shell_env = True 55 | ) 56 | 57 | return DefaultInfo(files = depset([output_directory])) 58 | 59 | doxygen_docs = rule( 60 | implementation = _doxygen_docs_impl, 61 | test = False, 62 | attrs = { 63 | "project_name" : attr.string( 64 | doc = "The project name for the doxygen docs", 65 | mandatory = True, 66 | ), 67 | "version" : attr.string( 68 | doc = "The version of the project being documented", 69 | default = "" 70 | ), 71 | "desc" : attr.string( 72 | doc = "A description for the project", 73 | default = "" 74 | ), 75 | "sources" : attr.label_list( 76 | doc = "A list of files made available to doxygen. This is NOT automatically included in the doxyfile", 77 | mandatory = True, 78 | allow_files = True, 79 | ), 80 | "strip_prefix" : attr.string( 81 | doc = "Prefix to strip from path of files being processed", 82 | default = "" 83 | ), 84 | "main_page_md" : attr.label( 85 | doc = "The file to use as main page for the generate docs", 86 | allow_single_file = True, 87 | mandatory = False 88 | ), 89 | "_doxyfile_template" : attr.label( 90 | allow_single_file = True, 91 | default = "//docs:doxygen/doxyfile.template" 92 | ), 93 | "_output_directory" : attr.string( 94 | doc = "The output directory for the doxygen docs", 95 | default = "doxygen_docs" 96 | ) 97 | }, 98 | doc = """ 99 | Creates HTML documentation for C++ and C# projects using Doxygen. 100 | This rule is not hermetic, and requires doxygen to be installed on the host. 101 | """ 102 | ) 103 | -------------------------------------------------------------------------------- /docs/java/deps.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # This program is free software: you can redistribute it and/or modify 3 | # it under the terms of the GNU Affero General Public License as 4 | # published by the Free Software Foundation, either version 3 of the 5 | # License, or (at your option) any later version. 6 | # 7 | # This program is distributed in the hope that it will be useful, 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | # GNU Affero General Public License for more details. 11 | # 12 | # You should have received a copy of the GNU Affero General Public License 13 | # along with this program. If not, see . 14 | # 15 | 16 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 17 | 18 | def google_bazel_common(): 19 | # Bazel Common Libraries (with javadoc) 20 | http_archive( 21 | name = "google_bazel_common", 22 | sha256 = "e982cc2e4c9a7d664e77d97a99debb3d18261e6ac6ea5bc4d8f453a521fdf1cf", 23 | strip_prefix = "bazel-common-78cc73600ddfa62f953652625abd7c6f1656cfac", 24 | urls = ["https://github.com/google/bazel-common/archive/78cc73600ddfa62f953652625abd7c6f1656cfac.zip"], 25 | ) 26 | -------------------------------------------------------------------------------- /docs/python/deps.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # This program is free software: you can redistribute it and/or modify 3 | # it under the terms of the GNU Affero General Public License as 4 | # published by the Free Software Foundation, either version 3 of the 5 | # License, or (at your option) any later version. 6 | # 7 | # This program is distributed in the hope that it will be useful, 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | # GNU Affero General Public License for more details. 11 | # 12 | # You should have received a copy of the GNU Affero General Public License 13 | # along with this program. If not, see . 14 | # 15 | 16 | load("@rules_python//python:pip.bzl", "pip_parse") 17 | 18 | def typedb_bazel_distribution_docs_py(): 19 | pip_parse( 20 | name = "typedb_bazel_distribution_docs_py", 21 | requirements_lock = "@typedb_bazel_distribution//docs:python/requirements.txt", 22 | ) 23 | -------------------------------------------------------------------------------- /docs/python/requirements.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | alabaster==0.7.13 21 | Babel==2.12.1 22 | certifi==2022.12.7 23 | charset-normalizer==3.1.0 24 | docutils==0.18.1 25 | idna==3.4 26 | imagesize==1.4.1 27 | importlib-metadata==6.1.0 28 | Jinja2==3.1.2 29 | MarkupSafe==2.1.2 30 | packaging==23.0 31 | Pygments==2.14.0 32 | pytz==2023.2 33 | requests==2.28.2 34 | snowballstemmer==2.2.0 35 | Sphinx==6.1.3 36 | sphinx-rtd-theme==1.2.0 37 | sphinxcontrib-applehelp==1.0.4 38 | sphinxcontrib-devhelp==1.0.2 39 | sphinxcontrib-htmlhelp==2.0.1 40 | sphinxcontrib-jquery==4.1 41 | sphinxcontrib-jsmath==1.0.1 42 | sphinxcontrib-qthelp==1.0.3 43 | sphinxcontrib-serializinghtml==1.1.5 44 | typing-extensions==4.5.0 45 | urllib3==1.26.15 46 | zipp==3.15.0 47 | -------------------------------------------------------------------------------- /docs/python/rules.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | def _sphinx_docs_impl(ctx): 21 | package = ctx.actions.declare_directory("package") 22 | 23 | ctx.actions.run_shell( 24 | inputs = ctx.files.target, 25 | outputs = [package], 26 | command = 'PACKAGE=$(find . -name "*.tar.gz") && tar -xf ${PACKAGE} && mv */%s %s' 27 | % (ctx.attr.package_subdir, package.path), 28 | ) 29 | 30 | args = ctx.actions.args() 31 | args.add('--output', ctx.outputs.out.path) 32 | args.add('--package', package.path) 33 | args.add('--source_dir', ctx.files.sphinx_conf[0].dirname) 34 | 35 | ctx.actions.run( 36 | inputs = [ctx.executable._script, package] + ctx.files.sphinx_conf + ctx.files.sphinx_rst, 37 | outputs = [ctx.outputs.out], 38 | arguments = [args], 39 | executable = ctx.executable._script, 40 | env = {"PYTHONPATH": package.path}, 41 | ) 42 | 43 | return DefaultInfo(files = depset([ctx.outputs.out])) 44 | 45 | 46 | sphinx_docs = rule( 47 | attrs = { 48 | "_script": attr.label( 49 | default = ":sphinx_runner", 50 | executable = True, 51 | cfg = "exec", 52 | doc = "Script for running sphinx", 53 | ), 54 | "target": attr.label( 55 | mandatory = True, 56 | allow_files = True, 57 | doc = "Package including .tar.gz archive", 58 | ), 59 | "sphinx_conf": attr.label( 60 | mandatory = True, 61 | allow_files = True, 62 | doc = "Configuration file for the Sphinx documentation builder", 63 | ), 64 | "sphinx_rst": attr.label( 65 | mandatory = True, 66 | allow_files = True, 67 | doc = "Sphinx documentation master file for the package", 68 | ), 69 | "out": attr.output( 70 | mandatory = True, 71 | doc = "Output directory", 72 | ), 73 | "package_subdir": attr.string( 74 | mandatory = True, 75 | doc = "Directory with the module files in the package archive", 76 | ) 77 | }, 78 | implementation = _sphinx_docs_impl, 79 | doc = """ 80 | Creates an HTML documentation for python module using Sphinx. 81 | """ 82 | ) 83 | -------------------------------------------------------------------------------- /docs/python/sphinx_html_builder.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | import argparse 21 | import sys 22 | 23 | from sphinx.cmd.build import main 24 | from sphinx.ext import apidoc 25 | 26 | if __name__ == '__main__': 27 | parser = argparse.ArgumentParser() 28 | parser.add_argument('--output', help="Output directory") 29 | parser.add_argument('--package', help="Package directory") 30 | parser.add_argument('--source_dir', help="Sphinx source directory") 31 | args = parser.parse_args() 32 | 33 | apidoc.main(["-o", args.source_dir, args.package]) 34 | sys.exit(main(["-M", "html", args.source_dir, args.output])) 35 | -------------------------------------------------------------------------------- /gcp/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | exports_files(["packer.template.json"]) 21 | 22 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 23 | 24 | bzl_library( 25 | name = "lib", 26 | srcs = [ 27 | "rules.bzl", 28 | ], 29 | visibility = ["//visibility:public"] 30 | ) 31 | -------------------------------------------------------------------------------- /gcp/packer.template.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "gcp_account_file": "{{env `DEPLOY_PACKER_GCP_ACCOUNT_FILE`}}", 4 | "version": "{{env `DEPLOY_PACKER_VERSION`}}" 5 | }, 6 | "builders": [ 7 | { 8 | "type": "googlecompute", 9 | "account_file": "{{user `gcp_account_file`}}", 10 | "project_id": "{project_id}", 11 | "source_image_family": "{source_image_family}", 12 | "zone": "{zone}", 13 | "ssh_username": "ubuntu", 14 | "image_name": "{image_name}", 15 | "image_family": "{image_family}", 16 | "image_licenses": {image_licenses}, 17 | "disk_size": 50, 18 | "disable_default_service_account": {disable_default_service_account} 19 | } 20 | ], 21 | 22 | "provisioners": [ 23 | { 24 | "type": "shell", 25 | "inline": [ "mkdir /tmp/deployment" ] 26 | }, 27 | { 28 | "type": "file", 29 | "source": "files/", 30 | "destination": "/tmp/deployment/" 31 | }, 32 | { 33 | "type": "shell", 34 | "inline": [ "sudo /tmp/deployment/{install}" ] 35 | } 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /gcp/rules.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("//packer:rules.bzl", "assemble_packer") 21 | load("//common/generate_json_config:rules.bzl", "generate_json_config") 22 | 23 | 24 | def assemble_gcp(name, 25 | project_id, 26 | install, 27 | zone, 28 | image_name, 29 | image_family="", 30 | files=None, 31 | image_licenses=None, 32 | disable_default_service_account=False, 33 | source_image_family="ubuntu-1604-lts"): 34 | """Assemble files for GCP deployment 35 | 36 | Args: 37 | name: A unique name for this target. 38 | project_id: Google project id 39 | install: Bazel label for install file 40 | zone: GCP zone to deploy image to 41 | image_name: name of deployed image 42 | image_family: family of deployed image 43 | files: Files to include into GCP deployment 44 | image_licenses: licenses to attach to deployed image 45 | disable_default_service_account: disable default service account 46 | source_image_family: Family of GCP base image 47 | """ 48 | if not files: 49 | files = {} 50 | install_fn = Label(install).name 51 | generated_config_target_name = name + "__do_not_reference_config" 52 | generate_json_config( 53 | name = generated_config_target_name, 54 | template = "@typedb_bazel_distribution//gcp:packer.template.json", 55 | substitutions = { 56 | "{project_id}": project_id, 57 | "{zone}": zone, 58 | "{image_name}": image_name, 59 | "{image_family}": image_family, 60 | "{image_licenses}": "[\"{}\"]".format(image_licenses) if image_licenses else "[]", 61 | "{install}": install_fn, 62 | "{source_image_family}": source_image_family, 63 | "{disable_default_service_account}": str(disable_default_service_account).lower() 64 | } 65 | ) 66 | files[install] = install_fn 67 | assemble_packer( 68 | name = name, 69 | config = generated_config_target_name, 70 | files = files 71 | ) 72 | -------------------------------------------------------------------------------- /github/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 21 | 22 | bzl_library( 23 | name = "lib", 24 | srcs = [ 25 | "rules.bzl", 26 | ], 27 | visibility = ["//visibility:public"] 28 | ) 29 | -------------------------------------------------------------------------------- /github/deps.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 21 | 22 | def ghr_osx_zip(): 23 | http_archive( 24 | name = "ghr_osx_zip", 25 | urls = ["https://github.com/tcnksm/ghr/releases/download/v0.12.1/ghr_v0.12.1_darwin_amd64.zip"], 26 | sha256 = "b5d1379e519fc3b795f3b81e5404d427e0abd8837d9e249f483a72f999dd4f47", 27 | strip_prefix = "ghr_v0.12.1_darwin_amd64", 28 | build_file_content = 'exports_files(["ghr"])' 29 | ) 30 | 31 | def ghr_linux_tar(): 32 | http_archive( 33 | name = "ghr_linux_tar", 34 | urls = ["https://github.com/tcnksm/ghr/releases/download/v0.12.1/ghr_v0.12.1_linux_amd64.tar.gz"], 35 | sha256 = "471c2eb1aee20dedffd00254f6c445abb5eb7d479bcae32c4210fdcf036b2dce", 36 | strip_prefix = "ghr_v0.12.1_linux_amd64", 37 | build_file_content = 'exports_files(["ghr"])' 38 | ) 39 | -------------------------------------------------------------------------------- /github/rules.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | def _deploy_github_impl(ctx): 21 | _deploy_script = ctx.actions.declare_file("{}_deploy.py".format(ctx.attr.name)) 22 | 23 | if not ctx.attr.version_file: 24 | version_file = ctx.actions.declare_file(ctx.attr.name + "__do_not_reference.version") 25 | version = ctx.var.get('version', '0.0.0') 26 | 27 | ctx.actions.run_shell( 28 | inputs = [], 29 | outputs = [version_file], 30 | command = "echo {} > {}".format(version, version_file.path) 31 | ) 32 | else: 33 | version_file = ctx.file.version_file 34 | 35 | ctx.actions.expand_template( 36 | template = ctx.file._deploy_script, 37 | output = _deploy_script, 38 | substitutions = { 39 | "{organisation}" : ctx.attr.organisation, 40 | "{repository}" : ctx.attr.repository, 41 | "{title}": ctx.attr.title or "", 42 | "{title_append_version}": str(bool(ctx.attr.title_append_version)), 43 | "{release_description}": str(bool(ctx.file.release_description)), 44 | "{archive}": ctx.file.archive.short_path if (ctx.file.archive!=None) else "", 45 | "{draft}": str(bool(ctx.attr.draft)), 46 | "{ghr_binary_mac}": ctx.files._ghr[0].path, 47 | "{ghr_binary_linux}": ctx.files._ghr[1].path, 48 | } 49 | ) 50 | files = [ 51 | version_file, 52 | ] + ctx.files._ghr 53 | 54 | if ctx.file.archive!=None: 55 | files.append(ctx.file.archive) 56 | 57 | symlinks = { 58 | 'VERSION': version_file 59 | } 60 | 61 | if ctx.file.release_description: 62 | files.append(ctx.file.release_description) 63 | symlinks["release_description.txt"] = ctx.file.release_description 64 | 65 | return DefaultInfo( 66 | executable = _deploy_script, 67 | runfiles = ctx.runfiles( 68 | files = files, 69 | symlinks = symlinks 70 | ), 71 | ) 72 | 73 | 74 | deploy_github = rule( 75 | attrs = { 76 | "organisation" : attr.string( 77 | mandatory = True, 78 | doc = "Github organisation to deploy to", 79 | ), 80 | "repository" : attr.string( 81 | mandatory = True, 82 | doc = "Github repository to deploy to within organisation", 83 | ), 84 | "title": attr.string( 85 | mandatory = False, 86 | doc = "Title of GitHub release" 87 | ), 88 | "title_append_version": attr.bool( 89 | default = False, 90 | doc = "Append version to GitHub release title" 91 | ), 92 | "release_description": attr.label( 93 | allow_single_file = True, 94 | doc = "Description of GitHub release" 95 | ), 96 | "archive": attr.label( 97 | mandatory = False, 98 | allow_single_file = [".zip"], 99 | doc = "`assemble_versioned` label to be deployed.", 100 | ), 101 | "version_file": attr.label( 102 | allow_single_file = True, 103 | doc = """ 104 | File containing version string. 105 | Alternatively, pass --define version=VERSION to Bazel invocation. 106 | Not specifying version at all defaults to '0.0.0' 107 | """ 108 | ), 109 | "draft": attr.bool( 110 | default = True, 111 | doc = """ 112 | Creates an unpublished / draft release when set to True. 113 | Defaults to True. 114 | """ 115 | ), 116 | "_deploy_script": attr.label( 117 | allow_single_file = True, 118 | default = "//github/templates:deploy.py", 119 | ), 120 | "_ghr": attr.label_list( 121 | allow_files = True, 122 | default = ["@ghr_osx_zip//:ghr", "@ghr_linux_tar//:ghr"] 123 | ), 124 | }, 125 | implementation = _deploy_github_impl, 126 | executable = True, 127 | doc = "Deploy `assemble_versioned` target to GitHub Releases" 128 | ) 129 | -------------------------------------------------------------------------------- /github/templates/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | exports_files(["deploy.py"]) 21 | -------------------------------------------------------------------------------- /github/templates/deploy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one 5 | # or more contributor license agreements. See the NOTICE file 6 | # distributed with this work for additional information 7 | # regarding copyright ownership. The ASF licenses this file 8 | # to you under the Apache License, Version 2.0 (the 9 | # "License"); you may not use this file except in compliance 10 | # with the License. You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, 15 | # software distributed under the License is distributed on an 16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | # KIND, either express or implied. See the License for the 18 | # specific language governing permissions and limitations 19 | # under the License. 20 | # 21 | 22 | from __future__ import print_function 23 | import argparse 24 | import os 25 | import platform 26 | import shutil 27 | import subprocess as sp 28 | import sys 29 | import tempfile 30 | import zipfile 31 | 32 | 33 | GHR_BINARIES = { 34 | "Darwin": os.path.abspath("{ghr_binary_mac}"), 35 | "Linux": os.path.abspath("{ghr_binary_linux}"), 36 | } 37 | 38 | system = platform.system() 39 | if system not in GHR_BINARIES: 40 | raise ValueError('Error - your platform ({}) is not supported. Try Linux or macOS instead.'.format(system)) 41 | 42 | 43 | # This ZipFile extends Python's ZipFile and fixes the lost permission issue 44 | class ZipFile(zipfile.ZipFile): 45 | def extract(self, member, path=None, pwd=None): 46 | if not isinstance(member, zipfile.ZipInfo): 47 | member = self.getinfo(member) 48 | 49 | if path is None: 50 | path = os.getcwd() 51 | 52 | ret_val = self._extract_member(member, path, pwd) 53 | attr = member.external_attr >> 16 54 | os.chmod(ret_val, attr) 55 | return ret_val 56 | 57 | 58 | if not os.getenv('DEPLOY_GITHUB_TOKEN'): 59 | print('Error - $DEPLOY_GITHUB_TOKEN must be defined') 60 | sys.exit(1) 61 | 62 | parser = argparse.ArgumentParser() 63 | parser.add_argument('commit_id') 64 | parser.add_argument('--archive', help="Archive to deploy") 65 | args = parser.parse_args() 66 | 67 | if args.archive and not os.path.isfile(args.archive): 68 | raise Exception("argument supplied in --archive is not a file") 69 | 70 | archive = "{archive}" or args.archive 71 | 72 | github_organisation = "{organisation}" 73 | github_repository = "{repository}" 74 | title = "{title}" 75 | title_append_version = {title_append_version} 76 | release_description = {release_description} 77 | draft = {draft} 78 | github_token = os.getenv('DEPLOY_GITHUB_TOKEN') 79 | target_commit_id = args.commit_id 80 | ghr = GHR_BINARIES[system] 81 | 82 | with open('VERSION') as version_file: 83 | github_tag = version_file.read().strip() 84 | 85 | if title and title_append_version: 86 | title += " {}".format(github_tag) 87 | 88 | directory_to_upload = tempfile.mkdtemp() 89 | 90 | if archive: 91 | sp.call(['unzip', archive, '-d', directory_to_upload]) 92 | else: 93 | tempfile.mkdtemp(dir=directory_to_upload) 94 | # TODO: ideally, this should be fixed in ghr itself 95 | # Currently it does not allow supplying empty folders 96 | # However, it also filters out folders inside the folder you supply 97 | # So if we have a folder within a folder, both conditions are 98 | # satisfied and we're able to proceed 99 | 100 | try: 101 | cmd = [ 102 | ghr, 103 | '-u', github_organisation, 104 | '-r', github_repository, 105 | '-n', title, 106 | '-b', open('release_description.txt').read().replace('{version}', github_tag) if release_description else '', 107 | '-c', target_commit_id, 108 | ] 109 | cmd += [ '-replace', '-draft', github_tag ] if draft else [ '-replace', github_tag ] 110 | cmd += [ directory_to_upload ] 111 | exit_code = sp.call(cmd, env={'GITHUB_TOKEN': github_token}) 112 | finally: 113 | shutil.rmtree(directory_to_upload) 114 | sys.exit(exit_code) 115 | -------------------------------------------------------------------------------- /helm/BUILD: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typedb/bazel-distribution/056a8d7ede9b552d23dcfdc2d47b9395510652f4/helm/BUILD -------------------------------------------------------------------------------- /helm/rules.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file") 21 | 22 | def _deploy_helm_impl(ctx): 23 | _deploy_script = ctx.actions.declare_file(ctx.attr.deploy_script_name) 24 | ctx.actions.expand_template( 25 | template = ctx.file._deploy_script_template, 26 | output = _deploy_script, 27 | substitutions = { 28 | "{chart_path}": ctx.file.chart.short_path, 29 | "{release}": ctx.attr.release, 30 | "{snapshot}": ctx.attr.snapshot, 31 | }, 32 | ) 33 | 34 | deployment_lib_files = ctx.attr._deployment_wrapper_lib[DefaultInfo].default_runfiles.files.to_list() 35 | return DefaultInfo( 36 | executable = _deploy_script, 37 | runfiles = ctx.runfiles( 38 | files = [ctx.file.chart] + deployment_lib_files 39 | ), 40 | ) 41 | 42 | _deploy_helm = rule( 43 | attrs = { 44 | "chart": attr.label( 45 | allow_single_file = True, 46 | mandatory = True, 47 | doc = "Chart to deploy to repo", 48 | ), 49 | "_deployment_wrapper_lib": attr.label( 50 | default = "//common/uploader:uploader", 51 | ), 52 | "_deploy_script_template": attr.label( 53 | allow_single_file = True, 54 | default = "//helm/templates:deploy.py", 55 | ), 56 | "deploy_script_name": attr.string( 57 | mandatory = True, 58 | doc = 'Name of instantiated deployment script' 59 | ), 60 | "release": attr.string( 61 | mandatory = True, 62 | doc = "Repository that the release chart will be uploaded to" 63 | ), 64 | "snapshot": attr.string( 65 | mandatory = True, 66 | doc = "Repository that the snapshot chart will be uploaded to" 67 | ), 68 | }, 69 | executable = True, 70 | implementation = _deploy_helm_impl, 71 | doc = "Deploy helm chart into a raw repo", 72 | ) 73 | 74 | def deploy_helm(name, chart, snapshot, release, **kwargs): 75 | deploy_script_target_name = name + "__deploy" 76 | deploy_script_name = deploy_script_target_name + "-deploy.py" 77 | 78 | _deploy_helm( 79 | name = deploy_script_target_name, 80 | chart = chart, 81 | deploy_script_name = deploy_script_name, 82 | snapshot = snapshot, 83 | release = release, 84 | **kwargs 85 | ) 86 | 87 | native.py_binary( 88 | name = name, 89 | srcs = [deploy_script_target_name], 90 | main = deploy_script_name, 91 | ) 92 | -------------------------------------------------------------------------------- /helm/templates/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | exports_files(["deploy.py"]) 21 | -------------------------------------------------------------------------------- /helm/templates/deploy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one 5 | # or more contributor license agreements. See the NOTICE file 6 | # distributed with this work for additional information 7 | # regarding copyright ownership. The ASF licenses this file 8 | # to you under the Apache License, Version 2.0 (the 9 | # "License"); you may not use this file except in compliance 10 | # with the License. You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, 15 | # software distributed under the License is distributed on an 16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | # KIND, either express or implied. See the License for the 18 | # specific language governing permissions and limitations 19 | # under the License. 20 | # 21 | 22 | from __future__ import print_function 23 | 24 | import os 25 | import re 26 | import subprocess as sp 27 | import sys 28 | from posixpath import join as urljoin 29 | 30 | import glob 31 | # Prefer using the runfile dependency than system dependency 32 | runfile_deps = [path for path in map(os.path.abspath, glob.glob('external/*/*'))] 33 | sys.path = runfile_deps + sys.path 34 | 35 | from common.uploader.uploader import Uploader 36 | 37 | if len(sys.argv) != 2: 38 | raise ValueError('Should pass only as arguments') 39 | 40 | _, repo_type = sys.argv 41 | 42 | username, password = os.getenv('DEPLOY_HELM_USERNAME'), os.getenv('DEPLOY_HELM_PASSWORD') 43 | 44 | if not username: 45 | raise ValueError('Error: username should be passed via $DEPLOY_HELM_USERNAME env variable') 46 | 47 | if not password: 48 | raise ValueError('Error: password should be passed via $DEPLOY_HELM_PASSWORD env variable') 49 | 50 | chart_path = '{chart_path}' 51 | filename = os.path.basename('{chart_path}') 52 | 53 | snapshot = 'snapshot' 54 | version_snapshot_regex = '.*-0.0.0-[0-9|a-f|A-F]{40}.*' 55 | release = 'release' 56 | version_release_regex = '.*-[0-9]+.[0-9]+.[0-9]+(-[a-zA-Z0-9]+)*.*' 57 | 58 | if repo_type not in [snapshot, release]: 59 | raise ValueError("Invalid repository type: {}. It should be one of these: {}" 60 | .format(repo_type, [snapshot, release])) 61 | if repo_type == 'snapshot' and len(re.findall(version_snapshot_regex, filename)) == 0: 62 | raise ValueError('Invalid version: {}. A helm chart uploaded to a {} repository ' 63 | 'must contain a version in its filename which complies to this regex: {}' 64 | .format(filename, repo_type, version_snapshot_regex)) 65 | if repo_type == 'release' and len(re.findall(version_release_regex, filename)) == 0: 66 | raise ValueError('Invalid version: {}. An helm chart uploaded to a {} repository ' 67 | 'must contain a version in its filename which complies to this regex: {}' 68 | .format(filename, repo_type, version_snapshot_regex)) 69 | 70 | base_url = None 71 | if repo_type == 'release': 72 | base_url = '{release}' 73 | else: 74 | base_url = '{snapshot}' 75 | 76 | uploader = Uploader.create(username, password, base_url) 77 | uploader.helm(chart_path) 78 | -------------------------------------------------------------------------------- /maven/BUILD: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | exports_files(["rules.bzl"]) 20 | 21 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 22 | load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") 23 | 24 | bzl_library( 25 | name = "lib", 26 | srcs = [ 27 | "rules.bzl", 28 | ], 29 | visibility = ["//visibility:public"] 30 | ) 31 | 32 | 33 | # FIXME(vmax): I couldn't make it a kt_jvm_binary because 34 | # it complained it couldn't find `java` executable 35 | kt_jvm_library( 36 | name = "pom-generator-lib", 37 | deps = [ 38 | "@maven//:com_eclipsesource_minimal_json_minimal_json", 39 | "@maven//:info_picocli_picocli", 40 | ], 41 | srcs = [ 42 | "PomGenerator.kt", 43 | ] 44 | ) 45 | 46 | java_binary( 47 | name = "pom-generator", 48 | runtime_deps = [ 49 | ":pom-generator-lib" 50 | ], 51 | main_class = "com.typedb.bazel.distribution.maven.PomGeneratorKt", 52 | visibility = ["//visibility:public"] 53 | ) 54 | 55 | 56 | kt_jvm_library( 57 | name = "jar-assembler-lib", 58 | deps = [ 59 | "@maven//:info_picocli_picocli", 60 | ], 61 | srcs = [ 62 | "JarAssembler.kt" 63 | ] 64 | ) 65 | 66 | java_binary( 67 | name = "jar-assembler", 68 | runtime_deps = [ 69 | ":jar-assembler-lib" 70 | ], 71 | main_class = "com.typedb.bazel.distribution.maven.JarAssemblerKt", 72 | visibility = ["//visibility:public"] 73 | ) 74 | -------------------------------------------------------------------------------- /maven/deps.bzl: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | # 18 | 19 | maven_artifacts = [ 20 | "com.eclipsesource.minimal-json:minimal-json", 21 | "com.electronwill.night-config:core", 22 | "com.electronwill.night-config:toml", 23 | "com.google.http-client:google-http-client", 24 | "info.picocli:picocli", 25 | "org.apache.commons:commons-compress", 26 | "org.jsoup:jsoup", 27 | "org.zeroturnaround:zt-exec", 28 | ] 29 | 30 | maven_artifacts_with_versions = [ 31 | "com.eclipsesource.minimal-json:minimal-json:0.9.5", 32 | "com.electronwill.night-config:core:3.6.5", 33 | "com.electronwill.night-config:toml:3.6.5", 34 | "com.google.http-client:google-http-client:1.34.2", 35 | "info.picocli:picocli:4.3.2", 36 | "org.apache.commons:commons-compress:1.21", 37 | "org.jsoup:jsoup:1.16.1", 38 | "org.zeroturnaround:zt-exec:1.10", 39 | ] 40 | -------------------------------------------------------------------------------- /maven/templates/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | exports_files(["deploy.py"]) 21 | -------------------------------------------------------------------------------- /maven/templates/deploy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one 5 | # or more contributor license agreements. See the NOTICE file 6 | # distributed with this work for additional information 7 | # regarding copyright ownership. The ASF licenses this file 8 | # to you under the Apache License, Version 2.0 (the 9 | # "License"); you may not use this file except in compliance 10 | # with the License. You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, 15 | # software distributed under the License is distributed on an 16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | # KIND, either express or implied. See the License for the 18 | # specific language governing permissions and limitations 19 | # under the License. 20 | # 21 | 22 | from __future__ import print_function 23 | from xml.etree import ElementTree 24 | 25 | import hashlib 26 | import os 27 | import re 28 | import subprocess as sp 29 | import sys 30 | import tempfile 31 | from posixpath import join as urljoin 32 | 33 | import sys, glob 34 | 35 | # Prefer using the runfile dependency than system dependency 36 | runfile_deps = [path for path in map(os.path.abspath, glob.glob('external/*/*'))] 37 | sys.path = runfile_deps + sys.path 38 | 39 | from common.uploader.uploader import Uploader 40 | 41 | 42 | def unpack_args(_, a, b=False): 43 | return a, b == '--gpg' 44 | 45 | 46 | if len(sys.argv) < 2: 47 | raise ValueError('Should pass [--gpg] as arguments') 48 | 49 | repo_type, should_sign = unpack_args(*sys.argv) 50 | 51 | if should_sign: raise NotImplementedError("Signing is not implemented yet") 52 | 53 | username, password = os.getenv('DEPLOY_MAVEN_USERNAME'), os.getenv('DEPLOY_MAVEN_PASSWORD') 54 | 55 | if not username: 56 | raise ValueError('Error: username should be passed via $DEPLOY_MAVEN_USERNAME env variable') 57 | 58 | if not password: 59 | raise ValueError('Error: password should be passed via $DEPLOY_MAVEN_PASSWORD env variable') 60 | 61 | maven_repositories = { 62 | "snapshot": "{snapshot}", 63 | "release": "{release}" 64 | } 65 | maven_url = maven_repositories[repo_type] 66 | jar_path = "$JAR_PATH" 67 | pom_file_path = "$POM_PATH" 68 | srcjar_path = "$SRCJAR_PATH" 69 | 70 | namespace = {'namespace': 'http://maven.apache.org/POM/4.0.0'} 71 | root = ElementTree.parse(pom_file_path).getroot() 72 | group_id = root.find('namespace:groupId', namespace) 73 | artifact_id = root.find('namespace:artifactId', namespace) 74 | version = root.find('namespace:version', namespace) 75 | if group_id is None or len(group_id.text) == 0: 76 | raise Exception("Could not get groupId from pom.xml") 77 | if artifact_id is None or len(artifact_id.text) == 0: 78 | raise Exception("Could not get artifactId from pom.xml") 79 | if version is None or len(version.text) == 0: 80 | raise Exception("Could not get version from pom.xml") 81 | 82 | version = version.text 83 | 84 | if version != version.strip(): 85 | raise Exception('Version "{}" has leading or trailing whitespaces'.format(version)) 86 | 87 | snapshot = 'snapshot' 88 | version_snapshot_regex = '^[0-9]+.[0-9]+.[0-9]+-[0-9|a-f|A-F]{40}$|.*-SNAPSHOT$' 89 | release = 'release' 90 | version_release_regex = '^[0-9]+.[0-9]+.[0-9]+(-[a-zA-Z0-9]+)*$' 91 | 92 | if repo_type not in [snapshot, release]: 93 | raise ValueError("Invalid repository type: {}. It should be one of these: {}" 94 | .format(repo_type, [snapshot, release])) 95 | if repo_type == 'snapshot' and len(re.findall(version_snapshot_regex, version)) == 0: 96 | raise ValueError('Invalid version: {}. An artifact uploaded to a {} repository ' 97 | 'must have a version which complies to this regex: {}' 98 | .format(version, repo_type, version_snapshot_regex)) 99 | if repo_type == 'release' and len(re.findall(version_release_regex, version)) == 0: 100 | raise ValueError('Invalid version: {}. An artifact uploaded to a {} repository ' 101 | 'must have a version which complies to this regex: {}' 102 | .format(version, repo_type, version_release_regex)) 103 | 104 | uploader = Uploader.create(username, password, maven_url) 105 | uploader.maven(group_id.text, artifact_id.text, version, 106 | jar_path=jar_path, pom_path=pom_file_path, 107 | sources_path=srcjar_path if os.path.exists(srcjar_path) else None, 108 | javadoc_path=srcjar_path if os.path.exists(srcjar_path) else None, 109 | tests_path = None 110 | ) 111 | -------------------------------------------------------------------------------- /npm/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 21 | 22 | bzl_library( 23 | name = "lib", 24 | srcs = [ 25 | "rules.bzl", 26 | ], 27 | visibility = ["//visibility:public"] 28 | ) 29 | -------------------------------------------------------------------------------- /npm/assemble/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 21 | 22 | bzl_library( 23 | name = "lib", 24 | srcs = [ 25 | "rules.bzl", 26 | ], 27 | visibility = ["//visibility:public"] 28 | ) 29 | 30 | py_binary( 31 | name = "assemble", 32 | srcs = ["assemble.py"], 33 | visibility = ["//visibility:public"], 34 | ) 35 | -------------------------------------------------------------------------------- /npm/assemble/assemble.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one 5 | # or more contributor license agreements. See the NOTICE file 6 | # distributed with this work for additional information 7 | # regarding copyright ownership. The ASF licenses this file 8 | # to you under the Apache License, Version 2.0 (the 9 | # "License"); you may not use this file except in compliance 10 | # with the License. You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, 15 | # software distributed under the License is distributed on an 16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | # KIND, either express or implied. See the License for the 18 | # specific language governing permissions and limitations 19 | # under the License. 20 | # 21 | 22 | 23 | import argparse 24 | import glob 25 | import json 26 | import shutil 27 | import subprocess 28 | import os 29 | import tempfile 30 | 31 | parser = argparse.ArgumentParser() 32 | parser.add_argument('--package', help="NPM package to pack") 33 | parser.add_argument('--version_file', help="Version file") 34 | parser.add_argument('--output', help="Output archive") 35 | 36 | args = parser.parse_args() 37 | 38 | with open(args.version_file) as version_file: 39 | version = version_file.read().strip() 40 | 41 | new_package_root = tempfile.mktemp() 42 | 43 | shutil.copytree(args.package, new_package_root, 44 | ignore=lambda _, names: list( 45 | filter(lambda x: 'external' in x, names))) 46 | package_json_fn = os.path.join(new_package_root, 'package.json') 47 | 48 | with open(package_json_fn) as f: 49 | package_json = json.load(f) 50 | 51 | package_json['version'] = version 52 | 53 | os.chmod(package_json_fn, 0o755) 54 | 55 | with open(package_json_fn, 'w') as f: 56 | json.dump(package_json, f) 57 | 58 | 59 | os.chmod(new_package_root, 0o755) 60 | for root, dirs, files in os.walk(new_package_root): 61 | for d in dirs: 62 | os.chmod(os.path.join(root, d), 0o755) 63 | for f in files: 64 | os.chmod(os.path.join(root, f), 0o755) 65 | npm_cache = tempfile.mktemp() 66 | 67 | subprocess.check_call([ 68 | 'npm', 69 | 'pack' 70 | ], env={ 71 | 'npm_config_cache': npm_cache, 72 | 'PATH': ':'.join([ 73 | '/usr/bin/', 74 | '/bin/', 75 | os.path.realpath('external/nodejs/bin/nodejs/bin/'), 76 | os.path.realpath('external/nodejs_darwin_amd64/bin/'), 77 | os.path.realpath('external/nodejs_darwin_arm64/bin/'), 78 | os.path.realpath('external/nodejs_linux_amd64/bin/'), 79 | os.path.realpath('external/nodejs_windows_amd64/bin/'), 80 | ]) 81 | }, cwd=new_package_root) 82 | 83 | archives = glob.glob(os.path.join(new_package_root, '*.tgz')) 84 | if len(archives) != 1: 85 | raise Exception('expected one archive instead of {}'.format(archives)) 86 | 87 | shutil.copy(archives[0], args.output) 88 | shutil.rmtree(new_package_root) 89 | shutil.rmtree(npm_cache) -------------------------------------------------------------------------------- /npm/assemble/rules.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | def _assemble_npm_impl(ctx): 21 | if len(ctx.files.target) != 1: 22 | fail("target contains more files than expected") 23 | 24 | if not ctx.attr.version_file: 25 | version_file = ctx.actions.declare_file(ctx.attr.name + "__do_not_reference.version") 26 | version = ctx.var.get('version', '0.0.0') 27 | 28 | if len(version) == 40: 29 | # this is a commit SHA, most likely 30 | version = "0.0.0-{}".format(version) 31 | elif 'rc' in version and '-rc' not in version: 32 | version = version.replace('rc', '-rc') 33 | 34 | ctx.actions.run_shell( 35 | inputs = [], 36 | outputs = [version_file], 37 | command = "echo {} > {}".format(version, version_file.path) 38 | ) 39 | else: 40 | version_file = ctx.file.version_file 41 | 42 | args = ctx.actions.args() 43 | args.add('--package', ctx.files.target[0].path) 44 | args.add('--output', ctx.outputs.npm_package.path) 45 | args.add('--version_file', version_file.path) 46 | 47 | ctx.actions.run( 48 | inputs = ctx.files.target + ctx.files._npm + [version_file], 49 | outputs = [ctx.outputs.npm_package], 50 | arguments = [args], 51 | executable = ctx.executable._assemble_script, 52 | # note: do not run in RBE 53 | ) 54 | 55 | 56 | assemble_npm = rule( 57 | implementation = _assemble_npm_impl, 58 | attrs = { 59 | "target": attr.label( 60 | mandatory = True, 61 | doc = "`npm_library` label to be included in the package.", 62 | ), 63 | "version_file": attr.label( 64 | allow_single_file = True, 65 | doc = """ 66 | File containing version string. 67 | Alternatively, pass --define version=VERSION to Bazel invocation. 68 | Not specifying version at all defaults to '0.0.0'. 69 | """ 70 | ), 71 | "_assemble_script": attr.label( 72 | default = "//npm/assemble", 73 | executable = True, 74 | cfg = "host" 75 | ), 76 | "_npm": attr.label( 77 | default = Label("@nodejs//:npm"), 78 | allow_files = True 79 | ) 80 | }, 81 | outputs = { 82 | "npm_package": "%{name}.tar.gz", 83 | }, 84 | doc = "Assemble `npm_package` target for further deployment. Currently does not support remote execution (RBE)." 85 | ) 86 | -------------------------------------------------------------------------------- /npm/deploy/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 21 | load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") 22 | 23 | exports_files(["deploy.sh.template"]) 24 | 25 | bzl_library( 26 | name = "lib", 27 | srcs = [ 28 | "rules.bzl", 29 | ], 30 | visibility = ["//visibility:public"] 31 | ) 32 | 33 | kt_jvm_library( 34 | name = "deployer-lib", 35 | srcs = glob(["*.kt"]), 36 | deps = [ 37 | "@typedb_bazel_distribution//common", 38 | "@typedb_bazel_distribution//common/shell", 39 | "@typedb_bazel_distribution//common/util", 40 | 41 | "@maven//:info_picocli_picocli", 42 | "@maven//:org_zeroturnaround_zt_exec", 43 | ], 44 | ) 45 | 46 | java_binary( 47 | name = "deployer-bin", 48 | runtime_deps = [":deployer-lib"], 49 | main_class = "com.typedb.bazel.distribution.npm.deploy.DeployNPMKt", 50 | visibility = ["//visibility:public"], 51 | ) 52 | -------------------------------------------------------------------------------- /npm/deploy/DeployNPM.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.typedb.bazel.distribution.npm.deploy 21 | 22 | fun main(args: Array) { 23 | Deployer(Options.of(args)).deploy() 24 | } 25 | -------------------------------------------------------------------------------- /npm/deploy/Deployer.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.typedb.bazel.distribution.npm.deploy 21 | 22 | import com.typedb.bazel.distribution.common.Logging.LogLevel.DEBUG 23 | import com.typedb.bazel.distribution.common.Logging.Logger 24 | import com.typedb.bazel.distribution.common.OS.LINUX 25 | import com.typedb.bazel.distribution.common.OS.MAC 26 | import com.typedb.bazel.distribution.common.shell.Shell 27 | import com.typedb.bazel.distribution.common.shell.Shell.Command.Companion.arg 28 | import com.typedb.bazel.distribution.common.util.SystemUtil.currentOS 29 | import com.typedb.bazel.distribution.npm.deploy.Options.Env.DEPLOY_NPM_PASSWORD 30 | import com.typedb.bazel.distribution.npm.deploy.Options.Env.DEPLOY_NPM_TOKEN 31 | import com.typedb.bazel.distribution.npm.deploy.Options.Env.DEPLOY_NPM_USERNAME 32 | import java.nio.file.Files 33 | import java.nio.file.Path 34 | import java.util.* 35 | 36 | class Deployer(private val options: Options) { 37 | private val logger = Logger(logLevel = DEBUG) 38 | 39 | fun deploy() { 40 | Shell(logger = logger, verbose = true).execute( 41 | command = Shell.Command( 42 | arg(options.npmPath), arg("publish"), arg("--registry=${options.registryURL}"), 43 | arg(authURI(options), printable = false), 44 | arg("deploy_npm.tgz"), 45 | ) 46 | ) 47 | } 48 | 49 | private fun authURI(options: Options): String { 50 | val token = options.npmToken; 51 | val user = options.npmUsername 52 | val pass = options.npmPassword 53 | val uriPrefix = "--" + authParamFormattedURI(options.registryURL) 54 | if (token != null) { 55 | if (user != null || pass != null) { 56 | throw IllegalArgumentException("If using an NPM authentication token via '\\$DEPLOY_NPM_TOKEN', " + 57 | "do not provide NPM username and password via '\\$DEPLOY_NPM_USERNAME' and '\\$DEPLOY_NPM_PASSWORD'.") 58 | } 59 | return authTokenURI(uriPrefix, token) 60 | } else if (user != null && pass != null) { 61 | return authUsernamePasswordURI(uriPrefix, user, pass) 62 | } else { 63 | throw IllegalArgumentException("Either the NPM token must be supplied using '\\$DEPLOY_NPM_TOKEN', " + 64 | "or both NPM username and password must be supplied with '\\$DEPLOY_NPM_USERNAME' and '\\$DEPLOY_NPM_PASSWORD'.") 65 | } 66 | } 67 | 68 | /** 69 | * Convert a registry URL to the format expected when passing it together with an auth token. 70 | * 71 | * ### Examples: 72 | * - https://registry.npmjs.org/ --> //registry.npmjs.org 73 | * - registry.npmjs.org --> //registry.npmjs.org 74 | */ 75 | private fun authParamFormattedURI(url: String): String { 76 | return url.trimEnd('/').let { if (":" in it) it.split(":")[1] else "//$it" } 77 | } 78 | 79 | private fun authTokenURI(uriPrefix: String, token: String): String { 80 | return "$uriPrefix/:_authToken=$token"; 81 | } 82 | 83 | private fun authUsernamePasswordURI(uriPrefix: String, username: String, password: String): String { 84 | val base64 = base64(username + ":" + password) 85 | return "$uriPrefix/:_auth=$base64"; 86 | } 87 | 88 | private fun base64(string: String): String { 89 | return Base64.getEncoder().encodeToString(string.toByteArray()) 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /npm/deploy/Options.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.typedb.bazel.distribution.npm.deploy 21 | 22 | import com.typedb.bazel.distribution.npm.deploy.Options.CommandLineParams.NPM_PATH 23 | import com.typedb.bazel.distribution.npm.deploy.Options.CommandLineParams.RELEASE_REPO 24 | import com.typedb.bazel.distribution.npm.deploy.Options.CommandLineParams.SNAPSHOT_REPO 25 | import com.typedb.bazel.distribution.npm.deploy.Options.RepositoryType.RELEASE 26 | import com.typedb.bazel.distribution.npm.deploy.Options.RepositoryType.SNAPSHOT 27 | import picocli.CommandLine 28 | 29 | class Options { 30 | @CommandLine.Option(names = [NPM_PATH], required = true) 31 | lateinit var npmPath: String 32 | 33 | @CommandLine.Option(names = [SNAPSHOT_REPO], required = true) 34 | private lateinit var snapshotRepo: String 35 | 36 | @CommandLine.Option(names = [RELEASE_REPO], required = true) 37 | private lateinit var releaseRepo: String 38 | 39 | @CommandLine.Parameters 40 | private lateinit var params: List 41 | 42 | val registryURL: String 43 | get() { 44 | if (params.isEmpty() || params[0].isBlank()) { 45 | throw IllegalArgumentException("Missing required positional argument: <${RepositoryType.allValuesString}>") 46 | } 47 | return when (RepositoryType.of(params[0])) { 48 | SNAPSHOT -> snapshotRepo 49 | RELEASE -> releaseRepo 50 | } 51 | } 52 | 53 | val npmToken: String? 54 | get() { 55 | return System.getenv().get(Env.DEPLOY_NPM_TOKEN); 56 | } 57 | 58 | val npmUsername: String? 59 | get() { 60 | return System.getenv().get(Env.DEPLOY_NPM_USERNAME) 61 | } 62 | 63 | val npmPassword: String? 64 | get() { 65 | return System.getenv().get(Env.DEPLOY_NPM_PASSWORD) 66 | } 67 | 68 | companion object { 69 | fun of(args: Array): Options { 70 | val cliList: List = CommandLine(Options()).parseArgs(*args).asCommandLineList() 71 | assert(cliList.size == 1) 72 | return cliList[0].getCommand() 73 | } 74 | } 75 | 76 | private enum class RepositoryType(val displayName: String) { 77 | SNAPSHOT("snapshot"), 78 | RELEASE("release"); 79 | 80 | companion object { 81 | val allValuesString = values().joinToString("|") { it.displayName } 82 | 83 | fun of(displayName: String): RepositoryType { 84 | return values().find { it.displayName == displayName } 85 | ?: throw IllegalArgumentException("Invalid repo type: '$displayName' (valid values are <$allValuesString>)") 86 | } 87 | } 88 | } 89 | 90 | object CommandLineParams { 91 | const val NPM_PATH = "--npm-path" 92 | const val RELEASE_REPO = "--release-repo" 93 | const val SNAPSHOT_REPO = "--snapshot-repo" 94 | } 95 | 96 | object Env { 97 | const val DEPLOY_NPM_TOKEN = "DEPLOY_NPM_TOKEN" 98 | const val DEPLOY_NPM_USERNAME = "DEPLOY_NPM_USERNAME" 99 | const val DEPLOY_NPM_PASSWORD = "DEPLOY_NPM_PASSWORD" 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /npm/deploy/deploy.sh.template: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # 20 | 21 | exec java -jar "{deployer-path}" \ 22 | --npm-path="{npm-path}" \ 23 | --snapshot-repo="{snapshot-repo}" \ 24 | --release-repo="{release-repo}" "$*" 25 | -------------------------------------------------------------------------------- /npm/deploy/rules.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | def _deploy_npm_impl(ctx): 21 | deploy_npm_script = ctx.actions.declare_file(ctx.attr.name) 22 | 23 | ctx.actions.expand_template( 24 | template = ctx.file._npm_deployer_wrapper_template, 25 | output = deploy_npm_script, 26 | substitutions = { 27 | "{deployer-path}": ctx.file._npm_deployer.short_path, 28 | "{npm-path}": ctx.file._npm.short_path, 29 | "{snapshot-repo}": ctx.attr.snapshot, 30 | "{release-repo}": ctx.attr.release, 31 | }, 32 | ) 33 | 34 | return DefaultInfo( 35 | executable = deploy_npm_script, 36 | runfiles = ctx.runfiles( 37 | files = [ctx.file.target, ctx.file._npm_deployer, ctx.file._npm], 38 | symlinks = { 39 | "deploy_npm.tgz": ctx.file.target, 40 | }, 41 | ), 42 | ) 43 | 44 | 45 | deploy_npm = rule( 46 | attrs = { 47 | "target": attr.label( 48 | mandatory = True, 49 | allow_single_file = True, 50 | doc = "`assemble_npm` target to be included in the package.", 51 | ), 52 | "snapshot": attr.string( 53 | mandatory = True, 54 | doc = 'Snapshot repository to deploy npm artifact to.', 55 | ), 56 | "release": attr.string( 57 | mandatory = True, 58 | doc = 'Release repository to deploy npm artifact to.', 59 | ), 60 | "_npm_deployer": attr.label( 61 | allow_single_file = True, 62 | default = "@typedb_bazel_distribution//npm/deploy:deployer-bin_deploy.jar" 63 | ), 64 | "_npm_deployer_wrapper_template": attr.label( 65 | allow_single_file = True, 66 | default = "@typedb_bazel_distribution//npm/deploy:deploy.sh.template", 67 | ), 68 | "_npm": attr.label( 69 | allow_single_file = True, 70 | default = "@nodejs//:npm", 71 | ), 72 | }, 73 | executable = True, 74 | implementation = _deploy_npm_impl, 75 | doc = """ 76 | Deploy `assemble_npm` target into npm registry using token authentication. 77 | 78 | Select deployment to `snapshot` or `release` repository with `bazel run //:some-deploy-npm -- [snapshot|release] 79 | 80 | ## How to generate an auth token 81 | 82 | ### Using the command line (`npm adduser`) 83 | 1. Run `npm adduser ` (example: `npm adduser --registry=https://npm.cloudsmith.io/typedb/private/`) 84 | 2. When prompted, provide login credentials to sign in to the user account that is used in your CI and has permissions to publish the package 85 | 3. If successful, a line will be added to your `.npmrc` file (`$HOME/.npmrc` on Unix) which looks like: `//npm.cloudsmith.io/typedb/private/:_authToken=NpmToken.00000000-0000-0000-0000-000000000000`. The token is the value of `_authToken`, in this case `NpmToken.00000000-0000-0000-0000-000000000000`. 86 | 4. Save the auth token somewhere safe and then delete it from your `.npmrc` file 87 | 88 | ### Using a UI 89 | 90 | Some remote repository managers (e.g. the `npm` registry, https://npmjs.com) provide a UI to create auth tokens. 91 | 92 | #### `npm` registry (`npmjs.com`) 93 | 94 | 1. Sign in to the user account at https://npmjs.com that is used in your CI and has permissions to publish the package 95 | 2. Navigate to the account's "Access Tokens", generate a new one and store it somewhere safe 96 | """, 97 | ) 98 | -------------------------------------------------------------------------------- /npm/rules.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("//npm/assemble:rules.bzl", _assemble_npm = "assemble_npm") 21 | load("//npm/deploy:rules.bzl", _deploy_npm = "deploy_npm") 22 | 23 | assemble_npm = _assemble_npm 24 | deploy_npm = _deploy_npm 25 | -------------------------------------------------------------------------------- /nuget/BUILD: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | -------------------------------------------------------------------------------- /nuget/templates/BUILD: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | exports_files(["push.py"]) 19 | -------------------------------------------------------------------------------- /nuget/templates/push.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | 19 | import os 20 | import subprocess 21 | import sys 22 | 23 | def unpack_args(_, arg1): 24 | return arg1 25 | 26 | if len(sys.argv) < 2: 27 | raise ValueError("Should pass as arguments") 28 | 29 | repo_type = unpack_args(*sys.argv) 30 | 31 | nuget_repositories = { 32 | "snapshot": "{snapshot_url}", 33 | "release": "{release_url}", 34 | } 35 | target_repo_url = nuget_repositories[repo_type] 36 | 37 | api_key = os.getenv('DEPLOY_NUGET_API_KEY') 38 | 39 | if not api_key: 40 | raise ValueError('Error: API key should be passed via $DEPLOY_NUGET_API_KEY env variable') 41 | 42 | args = [ 43 | "{dotnet_runtime_path}", 44 | "nuget", 45 | "push", 46 | ] 47 | args += "{nupkg_paths}".split() 48 | args += [ 49 | "-k", 50 | f"{api_key}", 51 | "-s", 52 | f"{target_repo_url}", 53 | ] 54 | 55 | print(f"Executing nuget push for {nupkg_paths}...") 56 | 57 | subprocess.check_call(args) 58 | 59 | print("Done executing nuget push!") 60 | -------------------------------------------------------------------------------- /packer/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | exports_files(["rules.bzl"]) 21 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 22 | 23 | bzl_library( 24 | name = "lib", 25 | srcs = [ 26 | "rules.bzl", 27 | "@bazel_tools//tools:bzl_srcs", 28 | ], 29 | visibility = ["//visibility:public"] 30 | ) 31 | -------------------------------------------------------------------------------- /packer/deps.bzl: -------------------------------------------------------------------------------- 1 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one 5 | # or more contributor license agreements. See the NOTICE file 6 | # distributed with this work for additional information 7 | # regarding copyright ownership. The ASF licenses this file 8 | # to you under the Apache License, Version 2.0 (the 9 | # "License"); you may not use this file except in compliance 10 | # with the License. You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, 15 | # software distributed under the License is distributed on an 16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | # KIND, either express or implied. See the License for the 18 | # specific language governing permissions and limitations 19 | # under the License. 20 | # 21 | 22 | def packer_osx(): 23 | http_archive( 24 | name = "packer_osx", 25 | build_file_content = 'exports_files(["packer"])', 26 | url = "https://releases.hashicorp.com/packer/1.8.3/packer_1.8.3_darwin_amd64.zip", 27 | sha256 = "ef1ceaaafcdada65bdbb45793ad6eedbc7c368d415864776b9d3fa26fb30b896" 28 | ) 29 | 30 | def packer_linux(): 31 | http_archive( 32 | name = "packer_linux", 33 | build_file_content = 'exports_files(["packer"])', 34 | url = "https://releases.hashicorp.com/packer/1.8.3/packer_1.8.3_linux_amd64.zip", 35 | sha256 = "0587f7815ed79589cd9c2b754c82115731c8d0b8fd3b746fe40055d969facba5" 36 | ) 37 | -------------------------------------------------------------------------------- /packer/rules.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar") 21 | 22 | def assemble_packer(name, 23 | config, 24 | files = {}): 25 | """Assemble files for HashiCorp Packer deployment 26 | 27 | Args: 28 | name: A unique name for this target. 29 | config: Packer JSON config 30 | files: Files to include into deployment 31 | """ 32 | _files = { 33 | config: "config.json" 34 | } 35 | for k, v in files.items(): 36 | _files[k] = "files/" + v 37 | pkg_tar( 38 | name = name, 39 | extension = "packer.tar", 40 | files = _files 41 | ) 42 | 43 | def _deploy_packer_impl(ctx): 44 | deployment_script = ctx.actions.declare_file("{}_deploy_packer.py".format(ctx.attr.target.label.name)) 45 | 46 | ctx.actions.expand_template( 47 | template = ctx.file._deployment_script_template, 48 | output = deployment_script, 49 | substitutions = { 50 | "{packer_osx_binary}": ctx.files._packer[0].path, 51 | "{packer_linux_binary}": ctx.files._packer[1].path, 52 | "{target_tar}": ctx.file.target.short_path, 53 | "{force}": "-force" if ctx.attr.overwrite else "", 54 | }, 55 | is_executable = True 56 | ) 57 | 58 | return DefaultInfo( 59 | executable = deployment_script, 60 | runfiles = ctx.runfiles(files = [ctx.file.target] + ctx.files._packer) 61 | ) 62 | 63 | deploy_packer = rule( 64 | attrs = { 65 | "target": attr.label( 66 | mandatory = False, 67 | allow_single_file = [".packer.tar"], 68 | doc = "`assemble_packer` label to be deployed.", 69 | ), 70 | "overwrite": attr.bool( 71 | mandatory = False, 72 | default = False, 73 | doc = "Overwrite already-existing image", 74 | ), 75 | "_deployment_script_template": attr.label( 76 | allow_single_file = True, 77 | default = "@typedb_bazel_distribution//packer/templates:deploy_packer.py", 78 | ), 79 | "_packer": attr.label_list( 80 | allow_files = True, 81 | default = ["@packer_osx//:packer", "@packer_linux//:packer"] 82 | ), 83 | }, 84 | executable = True, 85 | implementation = _deploy_packer_impl, 86 | doc = "Execute Packer to perform deployment" 87 | ) 88 | -------------------------------------------------------------------------------- /packer/templates/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | exports_files(["deploy_packer.py"]) 21 | -------------------------------------------------------------------------------- /packer/templates/deploy_packer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one 5 | # or more contributor license agreements. See the NOTICE file 6 | # distributed with this work for additional information 7 | # regarding copyright ownership. The ASF licenses this file 8 | # to you under the Apache License, Version 2.0 (the 9 | # "License"); you may not use this file except in compliance 10 | # with the License. You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, 15 | # software distributed under the License is distributed on an 16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | # KIND, either express or implied. See the License for the 18 | # specific language governing permissions and limitations 19 | # under the License. 20 | # 21 | 22 | import os 23 | import tempfile 24 | import tarfile 25 | import platform 26 | import subprocess as sp 27 | import shutil 28 | 29 | PACKER_BINARIES = { 30 | "Darwin": os.path.abspath("{packer_osx_binary}"), 31 | "Linux": os.path.abspath("{packer_linux_binary}"), 32 | } 33 | 34 | system = platform.system() 35 | 36 | if system not in PACKER_BINARIES: 37 | raise ValueError('Packer does not have binary for {}'.format(system)) 38 | 39 | TARGET_TAR_LOCATION = "{target_tar}" 40 | 41 | target_temp_dir = tempfile.mkdtemp('deploy_packer') 42 | with tarfile.open(TARGET_TAR_LOCATION, 'r') as target_tar: 43 | target_tar.extractall(target_temp_dir) 44 | 45 | args = [ 46 | PACKER_BINARIES[system], 47 | 'build', 48 | ] 49 | if "{force}": 50 | args.append("-force") 51 | args.append('config.json') 52 | sp.check_call(args, cwd=target_temp_dir) 53 | 54 | shutil.rmtree(target_temp_dir) 55 | -------------------------------------------------------------------------------- /pip/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | exports_files(["replace_imports.py", "requirements.txt"]) 21 | 22 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 23 | load("@typedb_bazel_distribution_pip//:requirements.bzl", typedb_bazel_distribution_requirement = "requirement") 24 | 25 | 26 | bzl_library( 27 | name = "lib", 28 | srcs = [ 29 | "rules.bzl", 30 | ], 31 | deps = [ 32 | "@typedb_bazel_distribution_pip//:requirements.bzl", 33 | "@rules_python//python:pip_bzl", 34 | ], 35 | visibility = ["//visibility:public"] 36 | ) 37 | 38 | py_binary( 39 | name = "assemble", 40 | srcs = ["assemble.py"], 41 | deps = [ 42 | typedb_bazel_distribution_requirement("setuptools"), 43 | typedb_bazel_distribution_requirement("wheel") 44 | ], 45 | visibility = ["//visibility:public"] 46 | ) 47 | 48 | py_binary( 49 | name = "repackage", 50 | srcs = ["repackage.py"], 51 | visibility = ["//visibility:public"] 52 | ) 53 | -------------------------------------------------------------------------------- /pip/deps.bzl: -------------------------------------------------------------------------------- 1 | load("@rules_python//python:pip.bzl", "pip_parse") 2 | 3 | def typedb_bazel_distribution_pip(): 4 | pip_parse( 5 | name = "typedb_bazel_distribution_pip", 6 | requirements_lock = "@typedb_bazel_distribution//pip:requirements.txt", 7 | ) 8 | -------------------------------------------------------------------------------- /pip/repackage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one 5 | # or more contributor license agreements. See the NOTICE file 6 | # distributed with this work for additional information 7 | # regarding copyright ownership. The ASF licenses this file 8 | # to you under the Apache License, Version 2.0 (the 9 | # "License"); you may not use this file except in compliance 10 | # with the License. You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, 15 | # software distributed under the License is distributed on an 16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | # KIND, either express or implied. See the License for the 18 | # specific language governing permissions and limitations 19 | # under the License. 20 | # 21 | 22 | import argparse 23 | import re 24 | 25 | PACKAGE_PATTERN = re.compile("from (?P.*) import (?:.*) as (?:.*)") 26 | 27 | parser = argparse.ArgumentParser() 28 | parser.add_argument('--src', help='Source file') 29 | parser.add_argument('--dest', help='Destination file') 30 | parser.add_argument('--pkgs', help='Source packages') 31 | parser.add_argument('--prefix', help='Prefix to add to Python package') 32 | args = parser.parse_args() 33 | 34 | with open(args.src) as srcf, open(args.dest, 'w') as destf: 35 | lines = srcf.readlines() 36 | packages = args.pkgs.split(",") 37 | for i, line in enumerate(lines): 38 | match = PACKAGE_PATTERN.match(line) 39 | if match: 40 | original_package = match.group('original_package') 41 | if original_package in packages: 42 | package = '{}.{}'.format(args.prefix, original_package) 43 | lines[i] = line.replace( 44 | 'from {}'.format(original_package), 45 | 'from {}'.format(package) 46 | ) 47 | destf.writelines(lines) 48 | -------------------------------------------------------------------------------- /pip/replace_imports.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one 5 | # or more contributor license agreements. See the NOTICE file 6 | # distributed with this work for additional information 7 | # regarding copyright ownership. The ASF licenses this file 8 | # to you under the Apache License, Version 2.0 (the 9 | # "License"); you may not use this file except in compliance 10 | # with the License. You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, 15 | # software distributed under the License is distributed on an 16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | # KIND, either express or implied. See the License for the 18 | # specific language governing permissions and limitations 19 | # under the License. 20 | # 21 | 22 | import sys 23 | _, input_fn, output_fn, original_package, output_package = sys.argv 24 | 25 | with open(input_fn) as input_file: 26 | txt = input_file.read() 27 | with open(output_fn, 'w') as output_file: 28 | original_package = 'from ' + original_package 29 | output_package = 'from ' + output_package 30 | output_file.write(txt.replace(original_package, output_package)) 31 | -------------------------------------------------------------------------------- /pip/requirements.txt: -------------------------------------------------------------------------------- 1 | bleach==6.0.0 2 | certifi==2022.12.7 3 | cffi==1.15.1 4 | chardet==5.1.0 5 | charset-normalizer==3.0.1 6 | colorama==0.4.6 7 | cryptography==39.0.0 8 | docutils==0.19 9 | idna==3.4 10 | importlib-metadata==6.0.0 11 | importlib-resources==5.10.2 12 | jaraco-classes==3.2.3 13 | jeepney==0.8.0 14 | keyring==23.13.1 15 | markdown-it-py==2.1.0 16 | mdurl==0.1.2 17 | more-itertools==9.0.0 18 | packaging==23.0 19 | pkginfo==1.9.6 20 | pycparser==2.21 21 | pygments==2.14.0 22 | pyparsing==3.0.9 23 | pywin32-ctypes==0.2.2; sys_platform == 'win32' 24 | readme-renderer==37.3 25 | requests==2.28.2 26 | requests-toolbelt==0.10.1 27 | rfc3986==2.0.0 28 | rich==13.2.0 29 | secretstorage==3.3.3 30 | ### DO NOT UPGRADE - setuptools > 65.x.x removes flexible versioning ### 31 | setuptools==65.0.0 32 | six==1.16.0 33 | tqdm==4.64.1 34 | twine==4.0.2 35 | typing-extensions==4.4.0 36 | urllib3==1.26.14 37 | webencodings==0.5.1 38 | wheel==0.38.4 39 | zipp==3.11.0 40 | -------------------------------------------------------------------------------- /pip/templates/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | exports_files(["setup.py", "deploy.py"]) 21 | -------------------------------------------------------------------------------- /pip/templates/deploy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one 5 | # or more contributor license agreements. See the NOTICE file 6 | # distributed with this work for additional information 7 | # regarding copyright ownership. The ASF licenses this file 8 | # to you under the Apache License, Version 2.0 (the 9 | # "License"); you may not use this file except in compliance 10 | # with the License. You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, 15 | # software distributed under the License is distributed on an 16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | # KIND, either express or implied. See the License for the 18 | # specific language governing permissions and limitations 19 | # under the License. 20 | # 21 | import argparse 22 | import glob 23 | import os 24 | import shutil 25 | import sys 26 | 27 | # Prefer using the runfile dependency than system dependency 28 | runfile_deps = [path for path in map(os.path.abspath, glob.glob('external/*/*'))] 29 | sys.path = runfile_deps + sys.path 30 | # noinspection PyUnresolvedReferences 31 | import twine.commands.upload 32 | 33 | PYPIRC_KEY = 'pypirc' 34 | SNAPSHOT_KEY = 'snapshot' 35 | RELEASE_KEY = 'release' 36 | 37 | ENV_DEPLOY_PIP_USERNAME = 'DEPLOY_PIP_USERNAME' 38 | ENV_DEPLOY_PIP_PASSWORD = 'DEPLOY_PIP_PASSWORD' 39 | 40 | repositories = { 41 | PYPIRC_KEY: "{pypirc_repository}", 42 | SNAPSHOT_KEY: "{snapshot}", 43 | RELEASE_KEY: "{release}" 44 | } 45 | 46 | parser = argparse.ArgumentParser() 47 | parser.add_argument('repo_type') 48 | 49 | 50 | def upload_command(repo_type_key, packages): 51 | if repo_type_key not in repositories: 52 | raise Exception(f"Selected repository must be one of: {list(repositories.keys())}") 53 | 54 | if repo_type_key == PYPIRC_KEY: 55 | return packages + ['--repository', repositories[repo_type_key]] 56 | elif repo_type_key == SNAPSHOT_KEY or repo_type_key == RELEASE_KEY: 57 | pip_username, pip_password = (os.getenv(ENV_DEPLOY_PIP_USERNAME), os.getenv(ENV_DEPLOY_PIP_PASSWORD)) 58 | if not pip_username: 59 | raise Exception(f"username should be passed via the {ENV_DEPLOY_PIP_USERNAME} environment variable") 60 | if not pip_password: 61 | raise Exception(f"password should be passed via the {ENV_DEPLOY_PIP_PASSWORD} environment variable") 62 | return packages + ['-u', pip_username, '-p', pip_password, '--repository-url', repositories[repo_type_key]] 63 | else: 64 | raise Exception(f"Unrecognised repository selector: {repo_type_key}") 65 | 66 | 67 | if not os.path.exists("{source_package}"): 68 | raise Exception("Cannot find expected distribution .tar.gz to deploy at '{source_package}'") 69 | 70 | if not os.path.exists("{wheel_package}"): 71 | raise Exception("Cannot find expected distribution wheel to deploy at '{wheel_package}'") 72 | 73 | args = parser.parse_args() 74 | repo_type_key = args.repo_type 75 | 76 | dist_dir = "./dist" 77 | with open("{version_file}") as version_file: 78 | version = version_file.read().strip() 79 | try: 80 | source_package_name = dist_dir + "/{source_package}".replace("{suffix}", "").replace(".tar.gz", "-{}.tar.gz".format(version)) 81 | wheel_package_name = dist_dir + "/{wheel_package}".replace("{suffix}", "").replace("-", "_").replace(".whl", "-{}-{distribution_tag}.whl".format(version)) 82 | 83 | if not os.path.exists(os.path.dirname(source_package_name)): 84 | os.makedirs(os.path.dirname(source_package_name)) 85 | 86 | if not os.path.exists(os.path.dirname(wheel_package_name)): 87 | os.makedirs(os.path.dirname(wheel_package_name)) 88 | 89 | shutil.copy("{source_package}", source_package_name) 90 | shutil.copy("{wheel_package}", wheel_package_name) 91 | 92 | # Do not upload a package file if we build for specific platform, because we use a precompiled library 93 | if "{distribution_tag}".endswith("any"): 94 | packages = [source_package_name, wheel_package_name] 95 | else: 96 | packages = [wheel_package_name] 97 | twine.commands.upload.main(upload_command(repo_type_key, packages)) 98 | finally: 99 | try: 100 | shutil.rmtree(dist_dir) 101 | except PermissionError as err: 102 | sys.stderr.write(f"WARNING: unable to delete temporary distribution directory {dist_dir}: {str(err)}\n") 103 | -------------------------------------------------------------------------------- /pip/templates/setup.py: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | from setuptools import setup 21 | from setuptools import find_namespace_packages 22 | 23 | packages = find_namespace_packages() 24 | 25 | setup( 26 | name = "{name}", 27 | version = "{version}", 28 | description = "{description}", 29 | long_description = open('README.md').read(), 30 | long_description_content_type="text/markdown", 31 | classifiers = {classifiers}, 32 | keywords = "{keywords}", 33 | url = "{url}", 34 | author = "{author}", 35 | author_email = "{author_email}", 36 | license = "{license}", 37 | packages=packages, 38 | include_package_data = True, 39 | install_requires=INSTALL_REQUIRES_PLACEHOLDER, 40 | zip_safe=False, 41 | python_requires="{python_requires}", 42 | setup_requires=["wheel"] 43 | ) 44 | -------------------------------------------------------------------------------- /platform/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # This program is free software: you can redistribute it and/or modify 3 | # it under the terms of the GNU Affero General Public License as 4 | # published by the Free Software Foundation, either version 3 of the 5 | # License, or (at your option) any later version. 6 | # 7 | # This program is distributed in the hope that it will be useful, 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | # GNU Affero General Public License for more details. 11 | # 12 | # You should have received a copy of the GNU Affero General Public License 13 | # along with this program. If not, see . 14 | # 15 | 16 | load(":constraints.bzl", "constraint_arm64", "constraint_x86_64", "constraint_linux", "constraint_mac", "constraint_windows", 17 | "constraint_linux_arm64", "constraint_linux_x86_64", "constraint_mac_arm64", "constraint_mac_x86_64", "constraint_win_x86_64") 18 | 19 | config_setting( 20 | name = "is_linux", 21 | constraint_values = constraint_linux, 22 | ) 23 | 24 | config_setting( 25 | name = "is_mac", 26 | constraint_values = constraint_mac, 27 | ) 28 | 29 | config_setting( 30 | name = "is_windows", 31 | constraint_values = constraint_windows, 32 | ) 33 | 34 | config_setting( 35 | name = "is_arm64", 36 | constraint_values = constraint_arm64, 37 | ) 38 | 39 | config_setting( 40 | name = "is_x86_64", 41 | constraint_values = constraint_x86_64, 42 | ) 43 | 44 | config_setting( 45 | name = "is_linux_arm64", 46 | constraint_values = constraint_linux_arm64, 47 | ) 48 | 49 | config_setting( 50 | name = "is_linux_x86_64", 51 | constraint_values = constraint_linux_x86_64, 52 | ) 53 | 54 | config_setting( 55 | name = "is_mac_arm64", 56 | constraint_values = constraint_mac_arm64, 57 | ) 58 | 59 | config_setting( 60 | name = "is_mac_x86_64", 61 | constraint_values = constraint_mac_x86_64, 62 | ) 63 | 64 | config_setting( 65 | name = "is_windows_x86_64", 66 | constraint_values = constraint_win_x86_64, 67 | ) 68 | 69 | platform( 70 | name = "linux_arm64", 71 | constraint_values = constraint_linux_arm64, 72 | ) 73 | 74 | platform( 75 | name = "linux_x86_64", 76 | constraint_values = constraint_linux_x86_64, 77 | ) 78 | 79 | platform( 80 | name = "mac_arm64", 81 | constraint_values = constraint_mac_arm64, 82 | ) 83 | 84 | platform( 85 | name = "mac_x86_64", 86 | constraint_values = constraint_mac_x86_64, 87 | ) 88 | 89 | platform( 90 | name = "win_x86_64", 91 | constraint_values = constraint_win_x86_64, 92 | ) 93 | -------------------------------------------------------------------------------- /platform/constraints.bzl: -------------------------------------------------------------------------------- 1 | # 2 | # This program is free software: you can redistribute it and/or modify 3 | # it under the terms of the GNU Affero General Public License as 4 | # published by the Free Software Foundation, either version 3 of the 5 | # License, or (at your option) any later version. 6 | # 7 | # This program is distributed in the hope that it will be useful, 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | # GNU Affero General Public License for more details. 11 | # 12 | # You should have received a copy of the GNU Affero General Public License 13 | # along with this program. If not, see . 14 | # 15 | 16 | constraint_linux = [ 17 | "@platforms//os:linux", 18 | ] 19 | 20 | constraint_mac = [ 21 | "@platforms//os:osx", 22 | ] 23 | 24 | constraint_windows = [ 25 | "@platforms//os:windows", 26 | ] 27 | 28 | constraint_arm64 = [ 29 | "@platforms//cpu:arm64", 30 | ] 31 | 32 | constraint_x86_64 = [ 33 | "@platforms//cpu:x86_64", 34 | ] 35 | 36 | constraint_linux_x86_64 = constraint_linux + constraint_x86_64 37 | constraint_linux_arm64 = constraint_linux + constraint_arm64 38 | constraint_mac_x86_64 = constraint_mac + constraint_x86_64 39 | constraint_mac_arm64 = constraint_mac + constraint_arm64 40 | constraint_win_x86_64 = constraint_windows + constraint_x86_64 41 | -------------------------------------------------------------------------------- /platform/jvm/BUILD: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 21 | load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") 22 | 23 | bzl_library( 24 | name = "lib", 25 | srcs = [ 26 | "rules.bzl" 27 | ], 28 | visibility = ["//visibility:public"] 29 | ) 30 | 31 | kt_jvm_library( 32 | name = "assembler-lib", 33 | srcs = glob(["*.kt"]), 34 | deps = [ 35 | "@typedb_bazel_distribution//common", 36 | "@typedb_bazel_distribution//common/shell", 37 | "@typedb_bazel_distribution//common/util", 38 | 39 | "@maven//:info_picocli_picocli", 40 | "@maven//:org_zeroturnaround_zt_exec", 41 | ], 42 | ) 43 | 44 | java_binary( 45 | name = "assembler-bin", 46 | runtime_deps = [":assembler-lib"], 47 | main_class = "com.typedb.bazel.distribution.platform.jvm.MainKt", 48 | visibility = ["//visibility:public"], 49 | ) 50 | 51 | config_setting( 52 | name = "apple-code-sign", 53 | define_values = { 54 | "APPLE_CODE_SIGN": "yes" 55 | } 56 | ) 57 | -------------------------------------------------------------------------------- /platform/jvm/CommandLineParams.kt: -------------------------------------------------------------------------------- 1 | package com.typedb.bazel.distribution.platform.jvm 2 | 3 | import com.typedb.bazel.distribution.platform.jvm.CommandLineParams.Keys.APPLE_CODE_SIGNING_CERT_PASSWORD 4 | import com.typedb.bazel.distribution.platform.jvm.CommandLineParams.Keys.APPLE_ID 5 | import com.typedb.bazel.distribution.platform.jvm.CommandLineParams.Keys.APPLE_ID_PASSWORD 6 | import com.typedb.bazel.distribution.platform.jvm.CommandLineParams.Keys.APPLE_TEAM_ID 7 | import com.typedb.bazel.distribution.platform.jvm.CommandLineParams.Keys.CONFIG_PATH 8 | import picocli.CommandLine 9 | import java.io.File 10 | 11 | class CommandLineParams { 12 | 13 | @CommandLine.Option(names = [CONFIG_PATH], required = true) 14 | lateinit var configFile: File 15 | 16 | @CommandLine.Option(names = [APPLE_ID]) 17 | lateinit var appleID: String 18 | 19 | @CommandLine.Option(names = [APPLE_ID_PASSWORD]) 20 | lateinit var appleIDPassword: String 21 | 22 | @CommandLine.Option(names = [APPLE_TEAM_ID]) 23 | lateinit var appleTeamID: String 24 | 25 | @CommandLine.Option(names = [APPLE_CODE_SIGNING_CERT_PASSWORD]) 26 | lateinit var appleCodeSigningCertPassword: String 27 | 28 | object Keys { 29 | const val APPLE_CODE_SIGNING_CERT_PASSWORD = "--apple_code_signing_cert_password" 30 | const val APPLE_ID = "--apple_id" 31 | const val APPLE_ID_PASSWORD = "--apple_id_password" 32 | const val APPLE_TEAM_ID = "--apple_team_id" 33 | const val CONFIG_PATH = "--config_path" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /platform/jvm/MacAppNotarizer.kt: -------------------------------------------------------------------------------- 1 | package com.typedb.bazel.distribution.platform.jvm 2 | 3 | import com.typedb.bazel.distribution.common.Logging.LogLevel 4 | import com.typedb.bazel.distribution.common.Logging.LogLevel.DEBUG 5 | import com.typedb.bazel.distribution.common.Logging.LogLevel.ERROR 6 | import com.typedb.bazel.distribution.common.Logging.Logger 7 | import com.typedb.bazel.distribution.common.shell.Shell 8 | import com.typedb.bazel.distribution.common.shell.Shell.Command.Companion.arg 9 | import com.typedb.bazel.distribution.platform.jvm.JVMPlatformAssembler.shell 10 | import com.typedb.bazel.distribution.platform.jvm.MacAppNotarizer.Args.APPLE_ID 11 | import com.typedb.bazel.distribution.platform.jvm.MacAppNotarizer.Args.NOTARYTOOL 12 | import com.typedb.bazel.distribution.platform.jvm.MacAppNotarizer.Args.ONE_HOUR 13 | import com.typedb.bazel.distribution.platform.jvm.MacAppNotarizer.Args.PASSWORD 14 | import com.typedb.bazel.distribution.platform.jvm.MacAppNotarizer.Args.STAPLE 15 | import com.typedb.bazel.distribution.platform.jvm.MacAppNotarizer.Args.STAPLER 16 | import com.typedb.bazel.distribution.platform.jvm.MacAppNotarizer.Args.SUBMIT 17 | import com.typedb.bazel.distribution.platform.jvm.MacAppNotarizer.Args.TEAM_ID 18 | import com.typedb.bazel.distribution.platform.jvm.MacAppNotarizer.Args.TIMEOUT 19 | import com.typedb.bazel.distribution.platform.jvm.MacAppNotarizer.Args.VERBOSE 20 | import com.typedb.bazel.distribution.platform.jvm.MacAppNotarizer.Args.WAIT 21 | import com.typedb.bazel.distribution.platform.jvm.ShellArgs.Programs.XCRUN 22 | import java.nio.file.Path 23 | 24 | class MacAppNotarizer( 25 | private val dmgPath: Path, appleCodeSigning: Options.AppleCodeSigning, private val logging: Options.Logging 26 | ) { 27 | private val logger = Logger(logLevel = if (logging.verbose) DEBUG else ERROR) 28 | 29 | fun notarize() { 30 | shell.execute(notarizeCommand).outputString() 31 | logger.debug { "\nUse `xcrun notarytool log ` to view further information about this notarization\n" } 32 | markPackageAsApproved() 33 | } 34 | 35 | private val notarizeCommand = Shell.Command(listOfNotNull( 36 | arg(XCRUN), arg(NOTARYTOOL), arg(SUBMIT), 37 | if (logging.verbose) arg(VERBOSE) else null, 38 | arg(APPLE_ID), arg(appleCodeSigning.appleID), 39 | arg(PASSWORD), arg(appleCodeSigning.appleIDPassword, printable = false), 40 | arg(TEAM_ID), arg(appleCodeSigning.appleTeamID, printable = false), 41 | arg(WAIT), arg(TIMEOUT), arg(ONE_HOUR), 42 | arg(dmgPath.toString()), 43 | )) 44 | 45 | private fun markPackageAsApproved() { 46 | shell.execute(listOfNotNull(XCRUN, STAPLER, STAPLE, if (logging.verbose) VERBOSE else null, dmgPath.toString())) 47 | } 48 | 49 | private object Args { 50 | const val APPLE_ID = "--apple-id" 51 | const val NOTARYTOOL = "notarytool" 52 | const val ONE_HOUR = "1h" 53 | const val STAPLE = "staple" 54 | const val STAPLER = "stapler" 55 | const val PASSWORD = "--password" 56 | const val SUBMIT = "submit" 57 | const val TIMEOUT = "--timeout" 58 | const val TEAM_ID = "--team-id" 59 | const val VERBOSE = "-v" 60 | const val WAIT = "--wait" 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /platform/jvm/Main.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package com.typedb.bazel.distribution.platform.jvm 21 | 22 | import picocli.CommandLine 23 | 24 | fun parseCommandLine(args: Array): Options { 25 | val commandLine = CommandLine(CommandLineParams()) 26 | val parseResult: CommandLine.ParseResult = commandLine.parseArgs(*args) 27 | assert(parseResult.asCommandLineList().size == 1) 28 | val parameters: CommandLineParams = parseResult.asCommandLineList()[0].getCommand() 29 | return Options.of(parameters) 30 | } 31 | 32 | fun main(args: Array) { 33 | JVMPlatformAssembler.run { 34 | init(options = parseCommandLine(args)) 35 | assemble() 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /platform/jvm/ShellArgs.kt: -------------------------------------------------------------------------------- 1 | package com.typedb.bazel.distribution.platform.jvm 2 | 3 | object ShellArgs { 4 | object Programs { 5 | const val CODESIGN = "codesign" 6 | const val JAR = "jar" 7 | const val JPACKAGE = "jpackage" 8 | const val JPACKAGE_EXE = "jpackage.exe" 9 | const val SECURITY = "security" 10 | const val TAR = "tar" 11 | const val XCRUN = "xcrun" 12 | } 13 | 14 | object Extensions { 15 | const val DYLIB = "dylib" 16 | const val JAR = "jar" 17 | const val JNILIB = "jnilib" 18 | } 19 | } 20 | --------------------------------------------------------------------------------