diff --git a/.env b/.env index 75e3693693f..1388c7595e3 100644 --- a/.env +++ b/.env @@ -65,3 +65,11 @@ ORY_KRATOS_PUBLIC_URL=http://127.0.0.1:4433 ORY_KRATOS_ADMIN_URL=HTTP://127.0.0.1:4434 KRATOS_API_KEY=secret + + +########################################### +## Aliases for dockerized external services +########################################### +## +## These variables are consumed in packages/hash/external-services/docker-compose.yml → env_file. +## Using `env` → POSTGRES_USER=${HASH_PG_USER} does not give access to values in this file. diff --git a/.eslintrc.json b/.eslintrc.json index 1135f2e4277..fbee0f93fde 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -52,11 +52,11 @@ "message": "Please replace `any` with a specific type" }, { - "selector": "CallExpression[callee.object.name=/^(EditorState|NodeSelection|TextSelection|DecorationSet|ProsemirrorNode|MarkType)$/][callee.property.name=create]:not([typeParameters])", + "selector": "CallExpression[callee.object.name=/^(EditorState|NodeSelection|TextSelection|ProsemirrorNode|MarkType)$/][callee.property.name=create]:not([typeParameters])", "message": "Please provide a generic to avoid implicit `any`" }, { - "selector": "CallExpression[callee.object.name=/^(EditorState|NodeSelection|TextSelection|DecorationSet|ProsemirrorNode|MarkType)$/][callee.property.name=create][typeParameters.params.0.type=TSAnyKeyword]", + "selector": "CallExpression[callee.object.name=/^(EditorState|NodeSelection|TextSelection|ProsemirrorNode|MarkType)$/][callee.property.name=create][typeParameters.params.0.type=TSAnyKeyword]", "message": "Please replace `any` with a specific type" }, { diff --git a/.github/ISSUE_TEMPLATE/bug-report-block.md b/.github/ISSUE_TEMPLATE/bug-report-block.md new file mode 100644 index 00000000000..f4c9c8b4e67 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report-block.md @@ -0,0 +1,44 @@ +--- +name: Bug report (block) +about: Create a report to help us improve our blocks +title: "[BUG]" +labels: + - A-blocks + - C-bug +--- + +**Block impacted** +The name of the block impacted. + +**Describe the bug** +A clear and concise description of what the bug is. + +**To reproduce** +Steps to reproduce the behavior: + +1. Go to '...' +1. Click on '...' +1. Scroll down to '...' +1. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + +- OS: [e.g. iOS] +- Browser [e.g. chrome, safari] +- Version [e.g. 22] + +**Smartphone (please complete the following information):** + +- Device: [e.g. iPhone6] +- OS: [e.g. iOS8.1] +- Browser [e.g. stock browser, safari] +- Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/bug-report-error-stack.md b/.github/ISSUE_TEMPLATE/bug-report-error-stack.md new file mode 100644 index 00000000000..272edb9b61c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report-error-stack.md @@ -0,0 +1,40 @@ +--- +name: Bug report (`error-stack`) +about: Create a report to help us improve `error-stack` +title: "[BUG]" +labels: + - A-error-stack + - C-bug +assignees: + - Alfred-Mountfield + - TimDiekmann +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To reproduce** +Steps to reproduce the behavior: + +```rust +fn main() { + // How to reproduce the issue +} +``` + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + +- OS: [e.g. macOS] +- rustc: [e.g. nightly-2020-08-08] +- target: [e.g. x86_64-unknown-linux-gnu] +- Version: [e.g. 0.1.1] +- Features: [e.g. default, spantrace] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/bug-report-hash-app.md b/.github/ISSUE_TEMPLATE/bug-report-hash-app.md new file mode 100644 index 00000000000..4771c0b1053 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report-hash-app.md @@ -0,0 +1,41 @@ +--- +name: Bug report (HASH App) +about: Create a report to help us improve HASH +title: "[BUG]" +labels: + - A-hash + - C-bug +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To reproduce** +Steps to reproduce the behavior: + +1. Go to '...' +1. Click on '...' +1. Scroll down to '...' +1. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + +- OS: [e.g. iOS] +- Browser [e.g. chrome, safari] +- Version [e.g. 22] + +**Smartphone (please complete the following information):** + +- Device: [e.g. iPhone6] +- OS: [e.g. iOS8.1] +- Browser [e.g. stock browser, safari] +- Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/bug-report-hash-engine.md b/.github/ISSUE_TEMPLATE/bug-report-hash-engine.md new file mode 100644 index 00000000000..5a93c5348db --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report-hash-engine.md @@ -0,0 +1,37 @@ +--- +name: Bug report (HASH Engine) +about: Create a report to help us improve HASH Engine +title: "[BUG]" +labels: + - A-engine + - C-bug +assignees: + - Alfred-Mountfield + - TimDiekmann +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To reproduce** +Where possible, please link us to your simulation project on HASH to help us debug. Steps to reproduce the behavior: + +1. Go to '...' +1. Click on '...' +1. Scroll down to '...' +1. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + +- OS: [e.g. macOS] +- rustc: [e.g. nightly-2020-08-08] +- target: [e.g. x86_64-unknown-linux-gnu] + +**Additional context** +Add any other context about the problem here, e.g. the log output. diff --git a/.github/ISSUE_TEMPLATE/bug-report-website.md b/.github/ISSUE_TEMPLATE/bug-report-website.md new file mode 100644 index 00000000000..658b749b6a3 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report-website.md @@ -0,0 +1,43 @@ +--- +name: Bug report (website) +about: Create a report to help us improve our websites +title: "[BUG]" +labels: + - C-bug +--- + +**Website URL** +The full URL of the page on which you experienced the bug. + +**Describe the bug** +A clear and concise description of what the bug is. + +**To reproduce** +Steps to reproduce the behavior: + +1. Go to '...' +1. Click on '...' +1. Scroll down to '...' +1. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + +- OS: [e.g. iOS] +- Browser [e.g. chrome, safari] +- Version [e.g. 22] + +**Smartphone (please complete the following information):** + +- Device: [e.g. iPhone6] +- OS: [e.g. iOS8.1] +- Browser [e.g. stock browser, safari] +- Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md new file mode 100644 index 00000000000..153ee6c7f6c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: "" +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To reproduce** +Steps to reproduce the behavior: + +1. Go to '...' +1. Click on '...' +1. Scroll down to '...' +1. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + +- OS: [e.g. iOS] +- Browser [e.g. chrome, safari] +- Version [e.g. 22] + +**Smartphone (please complete the following information):** + +- Device: [e.g. iPhone6] +- OS: [e.g. iOS8.1] +- Browser [e.g. stock browser, safari] +- Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature-request-error-stack.md b/.github/ISSUE_TEMPLATE/feature-request-error-stack.md new file mode 100644 index 00000000000..7478c5ca856 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature-request-error-stack.md @@ -0,0 +1,23 @@ +--- +name: Feature request (`error-stack`) +about: Suggest an idea, feature or enhancement to help us improve `error-stack` +title: "" +labels: + - A-error-stack + - C-enhancement +assignees: + - Alfred-Mountfield + - TimDiekmann +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/feature-request.md b/.github/ISSUE_TEMPLATE/feature-request.md new file mode 100644 index 00000000000..80bfbfb853f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature-request.md @@ -0,0 +1,19 @@ +--- +name: Feature request +about: Suggest an idea, feature or enhancement +title: "" +labels: + - C-enhancement +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/actions/warm-up-repo/action.yml b/.github/actions/warm-up-repo/action.yml index 22210031c5c..e9a3267b49e 100644 --- a/.github/actions/warm-up-repo/action.yml +++ b/.github/actions/warm-up-repo/action.yml @@ -1,13 +1,25 @@ name: Warm-up repo description: Prepares Node and Yarn dependencies +inputs: + playwright-deps: + default: "" + description: "List of browsers separated by space, e.g. 'chrome firefox'" + required: false + runs: using: composite steps: - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 with: node-version: 18 cache: yarn - run: yarn install shell: bash + env: + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: ${{ inputs.playwright-deps == '' }} + + - run: yarn playwright install-deps ${{ inputs.playwright-deps }} + if: ${{ inputs.playwright-deps != '' }} + shell: bash diff --git a/.github/labeler.yml b/.github/labeler.yml index 7c7cb004b0a..cf77d270952 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -26,16 +26,16 @@ A-engine: - "packages/engine/**/.*" A-learn: - - "resources/*" - - "resources/.*" - - "resources/**/*" - - "resources/**/.*" + - "sites/hashai/resources/*" + - "sites/hashai/resources/.*" + - "sites/hashai/resources/**/*" + - "sites/hashai/resources/**/.*" -A-libs: - - "packages/libs/*" - - "packages/libs/.*" - - "packages/libs/**/*" - - "packages/libs/**/.*" +A-error-stack: + - "packages/libs/error-stack/*" + - "packages/libs/error-stack/.*" + - "packages/libs/error-stack/**/*" + - "packages/libs/error-stack/**/.*" A-backend: - "packages/graph/*" diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index adc9e9f95e4..a434124e663 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -6,7 +6,7 @@ ## 🔗 Related links - + - [Asana task](link) _(internal)_ diff --git a/.github/scripts/rust/requirements.txt b/.github/scripts/rust/requirements.txt index a8f739bc61c..dd81db12e9e 100644 --- a/.github/scripts/rust/requirements.txt +++ b/.github/scripts/rust/requirements.txt @@ -1 +1,2 @@ pygit2 == 1.9.2 +toml == 0.10.2 diff --git a/.github/scripts/rust/setup.py b/.github/scripts/rust/setup.py index 37e2185b763..03999d589db 100644 --- a/.github/scripts/rust/setup.py +++ b/.github/scripts/rust/setup.py @@ -1,18 +1,33 @@ -from fnmatch import fnmatch -from pathlib import Path +""" +Setup script for the Rust GitHub Actions. + +The output of this will be used as arguments for the GitHub Actions matrix. + +see: https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs +""" + import re import json +import itertools +import toml + +from fnmatch import fnmatch +from pathlib import Path +from pygit2 import Repository, Commit CWD = Path.cwd() # All jobs for all crates will run if any of these paths change -ALWAYS_RUN_PATTERNS = ["**/rust-toolchain.toml", ".github/**"] +ALWAYS_RUN_PATTERNS = [".github/**"] -# Exclude the stable channel for these crates -DISABLE_STABLE_PATTERNS = ["packages/engine**", "packages/graph/hash_graph**"] +# Toolchains used for the specified crates in addition to the toolchain which is defined in +# rust-toolchain.toml +TOOLCHAINS = { + "packages/libs/error-stack": ["1.63"], +} # Try and publish these crates when their version is changed in Cargo.toml -PUBLISH_PATTERNS = ["packages/libs/error-stack"] +PUBLISH_PATTERNS = ["packages/libs/error-stack**"] # Build a docker container for these crates DOCKER_PATTERNS = ["packages/graph/hash_graph"] @@ -22,7 +37,6 @@ def generate_diffs(): """ Generates a diff between `HEAD^` and `HEAD` """ - from pygit2 import Repository, Commit repository = Repository(CWD) head = repository.head.peel(Commit) @@ -33,14 +47,22 @@ def find_local_crates(): """ Returns all available crates in the workspace. - If a crate is in a sub-crate of another crate, only the super-crate will be returned because `cargo-make` will run - the sub-crate automatically. + If a crate is in a sub-crate of another crate, only the super-crate will be returned because + `cargo-make` will run the sub-crate automatically. :return: a list of crate paths """ all_crates = [path.relative_to(CWD).parent for path in CWD.rglob("Cargo.toml")] checked_crates = [] for crate in all_crates: - if not any([path in crate.parents for path in all_crates]): + if not any(path in crate.parents for path in all_crates): + checked_crates.append(crate) + return checked_crates + + +def filter_parent_crates(crates): + checked_crates = [] + for crate in crates: + if not any(path in crate.parents for path in crates): checked_crates.append(crate) return checked_crates @@ -55,14 +77,22 @@ def filter_for_changed_crates(diffs, crates): :return: a list of crate paths """ # Check if any changed file matches `ALWAYS_RUN_PATTERNS` - if any([fnmatch(diff.delta.new_file.path, pattern) for diff in diffs for pattern in ALWAYS_RUN_PATTERNS]): + if any( + fnmatch(diff.delta.new_file.path, pattern) + for diff in diffs + for pattern in ALWAYS_RUN_PATTERNS + ): return crates # Get the unique crate paths which have changed files - return list(set([crate - for crate in crates - for diff in diffs - if fnmatch(diff.delta.new_file.path, f"{crate}/**")])) + return list( + { + crate + for crate in crates + for diff in diffs + if fnmatch(diff.delta.new_file.path, f"{crate}/**") + } + ) def filter_crates_by_changed_version(diffs, crates): @@ -72,6 +102,7 @@ def filter_crates_by_changed_version(diffs, crates): :param crates: a list of paths to crates :return: a list of crate paths """ + def crate_version_changed(crate, diff): if crate / "Cargo.toml" != Path(diff.delta.new_file.path): return False @@ -79,20 +110,16 @@ def crate_version_changed(crate, diff): for hunk in diff.hunks: for line in hunk.lines: for content in line.content.splitlines(): - if re.fullmatch("version\\s*=\\s*\".*\"", content): + if re.fullmatch('version\\s*=\\s*".*"', content): return True return False - return [crate for diff in diffs for crate in crates if crate_version_changed(crate, diff)] - - -def filter_for_nightly_only_crates(crates): - """ - Returns the crates which only supports the nightly compiler - :param crates: a list of paths to crates - :return: a list of crate paths - """ - return [crate for crate in crates for pattern in DISABLE_STABLE_PATTERNS if fnmatch(crate, pattern)] + return [ + crate + for diff in diffs + for crate in crates + if crate_version_changed(crate, diff) + ] def filter_for_publishable_crates(crates): @@ -101,7 +128,12 @@ def filter_for_publishable_crates(crates): :param crates: a list of paths to crates :return: a list of crate paths which are allowed to be published """ - return [crate for crate in crates for pattern in PUBLISH_PATTERNS if fnmatch(crate, pattern)] + return [ + crate + for crate in crates + for pattern in PUBLISH_PATTERNS + if fnmatch(crate, pattern) + ] def filter_for_docker_crates(crates): @@ -110,44 +142,88 @@ def filter_for_docker_crates(crates): :param crates: a list of paths to crates :return: a list of crate paths for which docker containers are built """ - return [crate for crate in crates for pattern in DOCKER_PATTERNS if fnmatch(crate, pattern)] - - -def output_exclude(crates): - """ - Prints a exclude statements for a GitHub Action matrix. - - Currently, this only excludes nightly-only crates from running on stable by default - :param crates: a list of paths to crates - """ + return [ + crate + for crate in crates + for pattern in DOCKER_PATTERNS + if fnmatch(crate, pattern) + ] - output = json.dumps([dict(toolchain="stable", directory=str(crate)) for crate in filter_for_nightly_only_crates(crates)]) - print(f"::set-output name=exclude::{output}") - print(f"exclude = {output}") - -def output(name, crates): +def output_matrix(name, crates, **kwargs): """ - Prints crates in a GitHub understandable way defined by name + Outputs the job matrix for the given crates :param name: The name where the list of crates will be stored to be read by GitHub Actions - :param crates: a list of crate paths to be outputted + :param crates: a list of paths to crates """ - output = json.dumps([str(crate) for crate in crates]) - print(f"::set-output name={name}::{output}") - print(f"{name} = {output}") + available_toolchains = set() + for crate in crates: + with open( + crate / "rust-toolchain.toml", "r", encoding="UTF-8" + ) as toolchain_toml: + available_toolchains.add( + toml.loads(toolchain_toml.read())["toolchain"]["channel"] + ) + for pattern, additional_toolchains in TOOLCHAINS.items(): + for additional_toolchain in additional_toolchains: + available_toolchains.add(additional_toolchain) + + used_toolchain_combinations = [] + for crate in crates: + toolchains = [] + with open( + crate / "rust-toolchain.toml", "r", encoding="UTF-8" + ) as toolchain_toml: + toolchains.append(toml.loads(toolchain_toml.read())["toolchain"]["channel"]) + + # We only run the default toolchain on lint/publish (rust-toolchain.toml) + if name not in ("lint", "publish"): + for pattern, additional_toolchains in TOOLCHAINS.items(): + if fnmatch(crate, pattern): + toolchains += additional_toolchains + used_toolchain_combinations.append( + itertools.product([crate], toolchains, repeat=1) + ) + + available_toolchain_combinations = itertools.product(crates, available_toolchains) + excluded_toolchain_combinations = set(available_toolchain_combinations).difference( + *used_toolchain_combinations + ) + + matrix = dict( + directory=[str(crate) for crate in crates], + toolchain=list(available_toolchains), + **kwargs, + exclude=[ + dict(directory=str(elem[0]), toolchain=elem[1]) + for elem in excluded_toolchain_combinations + ], + ) + if len(matrix["directory"]) == 0: + matrix = {} + + print(f"::set-output name={name}::{json.dumps(matrix)}") + print(f"Job matrix for {name}: {json.dumps(matrix, indent=4)}") def main(): diffs = generate_diffs() available_crates = find_local_crates() - changed_crates = list(set(filter_for_changed_crates(diffs, available_crates))) - - output("lint", changed_crates) - output("test", changed_crates) - output("publish", filter_crates_by_changed_version(diffs, filter_for_publishable_crates(changed_crates))) - output("docker", filter_for_docker_crates(changed_crates)) - output_exclude(changed_crates) + changed_crates = filter_for_changed_crates(diffs, available_crates) + changed_parent_crates = filter_parent_crates(changed_crates) + changed_docker_crates = filter_for_docker_crates(changed_parent_crates) + + output_matrix("lint", changed_parent_crates) + output_matrix("test", changed_parent_crates, profile=["development", "production"]) + output_matrix("docker", changed_docker_crates, profile=["production"]) + output_matrix( + "publish", + filter_crates_by_changed_version( + diffs, filter_for_publishable_crates(changed_crates) + ), + profile=["release"], + ) if __name__ == "__main__": diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 62880f48da1..7dee06573d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ jobs: name: Linting runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ./.github/actions/warm-up-repo @@ -126,7 +126,7 @@ jobs: if: ${{ github.base_ref != 'dev/graph' }} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ./.github/actions/warm-up-repo @@ -182,9 +182,19 @@ jobs: if: ${{ github.base_ref != 'dev/graph' }} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + + - uses: actions/cache@v3 + with: + path: packages/hash/frontend/.next/cache + key: ${{ runner.os }}-frontend-next-cache-${{ hashFiles('yarn.lock') }}-${{ hashFiles('packages/hash/frontend/**') }} + restore-keys: | + ${{ runner.os }}-frontend-next-cache-${{ hashFiles('yarn.lock') }}- + ${{ runner.os }}-frontend-next-cache - uses: ./.github/actions/warm-up-repo + with: + playwright-deps: chrome firefox - name: Create temp files and folders run: | @@ -215,9 +225,6 @@ jobs: yarn workspace @hashintel/hash-frontend start 2>&1 | tee var/logs/frontend.log & ## ampersand enables background mode yarn wait-on --timeout 30000 http://0.0.0.0:3000 - - run: yarn playwright install-deps chrome firefox - if: ${{ success() || failure() }} - - name: Run Playwright tests if: ${{ success() || failure() }} run: | @@ -259,7 +266,7 @@ jobs: name: Unit tests runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ./.github/actions/warm-up-repo diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 64c058c0298..d7e9f44e176 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -30,7 +30,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/hash-backend-cd.yml b/.github/workflows/hash-backend-cd.yml index a45aa0d4584..75727912bb9 100644 --- a/.github/workflows/hash-backend-cd.yml +++ b/.github/workflows/hash-backend-cd.yml @@ -33,7 +33,7 @@ jobs: name: Build and push HASH api image runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Docker image build through docker-build-push uses: ./.github/actions/docker-build-push @@ -52,7 +52,7 @@ jobs: name: Build and push HASH realtime image runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Docker image build through docker-build-push uses: ./.github/actions/docker-build-push @@ -71,7 +71,7 @@ jobs: name: Build and push HASH searchloader image runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Docker image build through docker-build-push uses: ./.github/actions/docker-build-push @@ -94,7 +94,7 @@ jobs: - build-realtime - build-searchloader steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ./.github/actions/docker-ecr-login with: @@ -103,7 +103,7 @@ jobs: AWS_REGION: ${{ env.AWS_REGION }} # Node is used for migrating the DB - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 with: node-version: 16 cache: yarn diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index 27719aa1602..c401d32ee4b 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -6,6 +6,6 @@ jobs: triage: runs-on: ubuntu-latest steps: - - uses: actions/labeler@v3 + - uses: actions/labeler@v4 with: repo-token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index b23e429397d..0033347d365 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -27,9 +27,7 @@ jobs: test: ${{ steps.crates.outputs.test }} docker: ${{ steps.crates.outputs.docker }} publish: ${{ steps.crates.outputs.publish }} - exclude: ${{ steps.crates.outputs.exclude }} samples: ${{ steps.samples.outputs.samples }} - nightly: ${{ steps.toolchains.outputs.nightly }} steps: - name: Checkout source code uses: actions/checkout@v3 @@ -43,13 +41,6 @@ jobs: id: crates run: python .github/scripts/rust/setup.py - - name: Find toolchain - id: toolchains - run: | - nightly=$(cat $(find . -name rust-toolchain.toml) | grep channel | cut -d\" -f2) - echo "::set-output name=nightly::$nightly" - echo "use toolchains: $(echo $nightly)" - - name: Determine samples id: samples run: | @@ -62,17 +53,11 @@ jobs: lint: name: lint needs: setup - if: needs.setup.outputs.lint != '[]' + if: needs.setup.outputs.lint != '{}' runs-on: ubuntu-latest strategy: fail-fast: false - matrix: - directory: ${{ fromJSON(needs.setup.outputs.lint) }} - toolchain: - - ${{ needs.setup.outputs.nightly }} - profile: - - development - exclude: ${{ fromJSON(needs.setup.outputs.exclude) }} + matrix: ${{ fromJSON(needs.setup.outputs.lint) }} steps: - name: Checkout source code uses: actions/checkout@v3 @@ -85,9 +70,9 @@ jobs: override: true - name: Cache Rust dependencies - uses: Swatinem/rust-cache@v1 + uses: Swatinem/rust-cache@v2 with: - working-directory: ${{ matrix.directory }} + workspaces: ${{ matrix.directory }} - name: Install tools shell: bash @@ -98,36 +83,31 @@ jobs: - name: Check formatting working-directory: ${{ matrix.directory }} - run: cargo make format -- --check + run: cargo +${{ matrix.toolchain }} make format -- --check - name: Check clippy working-directory: ${{ matrix.directory }} - run: cargo make clippy -- -D warnings + if: always() + run: cargo +${{ matrix.toolchain }} make clippy -- -D warnings - name: Check public documentation working-directory: ${{ matrix.directory }} - run: cargo make rustdoc --check -D warnings + if: always() + run: cargo +${{ matrix.toolchain }} make rustdoc --check -D warnings - name: Check private documentation working-directory: ${{ matrix.directory }} - run: cargo make rustdoc --check -D warnings --document-private-items + if: always() + run: cargo +${{ matrix.toolchain }} make rustdoc --check -D warnings --document-private-items test: name: test needs: setup - if: needs.setup.outputs.test != '[]' + if: needs.setup.outputs.test != '{}' runs-on: ubuntu-latest strategy: fail-fast: false - matrix: - directory: ${{ fromJSON(needs.setup.outputs.test) }} - toolchain: - - stable - - ${{ needs.setup.outputs.nightly }} - profile: - - development - - production - exclude: ${{ fromJSON(needs.setup.outputs.exclude) }} + matrix: ${{ fromJSON(needs.setup.outputs.test) }} env: OUTPUT_DIRECTORY: test-results RUST_BACKTRACE: 1 @@ -150,9 +130,9 @@ jobs: key: ${{ hashFiles('**/yarn.lock') }} - name: Cache Rust dependencies - uses: Swatinem/rust-cache@v1 + uses: Swatinem/rust-cache@v2 with: - working-directory: ${{ matrix.directory }} + workspaces: ${{ matrix.directory }} key: ${{ matrix.profile }} - name: Install tools @@ -167,16 +147,16 @@ jobs: if: matrix.directory == 'packages/engine' uses: actions/setup-python@v2 with: - python-version: "3.7" + python-version: "3.10" - name: Run tests working-directory: ${{ matrix.directory }} - run: cargo make --profile ${{ matrix.profile }} test --no-fail-fast + run: cargo +${{ matrix.toolchain }} make --profile ${{ matrix.profile }} test --no-fail-fast - name: Run miri - if: matrix.toolchain != 'stable' + if: ${{ startsWith(matrix.toolchain, 'nightly') }} working-directory: ${{ matrix.directory }} - run: cargo make --profile ${{ matrix.profile }} miri --no-fail-fast + run: cargo +${{ matrix.toolchain }} make --profile ${{ matrix.profile }} miri --no-fail-fast - name: Ensure empty git diff run: git --no-pager diff --exit-code --color @@ -203,14 +183,11 @@ jobs: docker: name: docker needs: setup - if: needs.setup.outputs.docker != '[]' + if: needs.setup.outputs.docker != '{}' runs-on: ubuntu-latest strategy: fail-fast: false - matrix: - directory: ${{ fromJSON(needs.setup.outputs.docker) }} - profile: - - production + matrix: ${{ fromJSON(needs.setup.outputs.docker) }} defaults: run: working-directory: ${{ matrix.directory }} @@ -239,14 +216,11 @@ jobs: publish: name: publish needs: setup - if: needs.setup.outputs.publish != '[]' + if: needs.setup.outputs.publish != '{}' runs-on: ubuntu-latest strategy: fail-fast: false - matrix: - directory: ${{ fromJSON(needs.setup.outputs.publish) }} - toolchain: - - ${{ needs.setup.outputs.nightly }} + matrix: ${{ fromJSON(needs.setup.outputs.publish) }} steps: - name: Checkout source code uses: actions/checkout@v3 @@ -259,6 +233,25 @@ jobs: toolchain: ${{ matrix.toolchain }} override: true + - name: Install tools + if: github.event_name == 'pull_request' + shell: bash + run: | + cargo install cargo-quickinstall + cargo quickinstall cargo-make --version 0.35.15 + cargo quickinstall cargo-hack --version 0.5.15 + cargo quickinstall cargo-nextest --version 0.9.28 + + - name: Run lints + if: github.event_name == 'pull_request' + working-directory: ${{ matrix.directory }} + run: cargo +${{ matrix.toolchain }} make --profile ${{ matrix.profile }} lint + + - name: Run tests + if: github.event_name == 'pull_request' + working-directory: ${{ matrix.directory }} + run: cargo +${{ matrix.toolchain }} make --profile ${{ matrix.profile }} test --no-fail-fast + - name: Login run: | [[ -n "${{ secrets.CARGO_REGISTRY_TOKEN }}" ]] @@ -267,12 +260,12 @@ jobs: - name: Publish (dry run) if: github.event_name == 'pull_request' working-directory: ${{ matrix.directory }} - run: cargo publish --all-features --dry-run + run: cargo +${{ matrix.toolchain }} publish --all-features --dry-run - name: Publish - if: github.event_name == 'push' && github.ref == 'ref/head/main' + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} working-directory: ${{ matrix.directory }} - run: cargo publish --all-features + run: cargo +${{ matrix.toolchain }} publish --all-features merging-enabled: name: merging enabled diff --git a/.github/workflows/algolia-upload-index.yml b/.github/workflows/sync-algolia-index.yml similarity index 52% rename from .github/workflows/algolia-upload-index.yml rename to .github/workflows/sync-algolia-index.yml index 10eea464f5b..a0b000305d6 100644 --- a/.github/workflows/algolia-upload-index.yml +++ b/.github/workflows/sync-algolia-index.yml @@ -1,4 +1,4 @@ -name: Algolia Upload Index +name: Sync Algolia Index env: ALGOLIA_PROJECT: ${{ secrets.ALGOLIA_PROJECT }} @@ -9,18 +9,19 @@ on: branches: [main] jobs: - build: + sync_algolia_index: + name: Sync Algolia Index runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: node-version: 18 cache: yarn - name: Install dependencies - run: yarn install --frozen-lockfile + run: yarn workspace @hashintel/hashai install --frozen-lockfile - name: Sync Algolia Index - run: yarn exe scripts/sync-algolia-index.ts + run: yarn workspace @hashintel/hashai exe scripts/sync-algolia-index.ts diff --git a/.gitignore b/.gitignore index 5195290226e..f6fdc1fcf2e 100644 --- a/.gitignore +++ b/.gitignore @@ -73,7 +73,7 @@ dist build # vscode config -.vscode/settings.json +**/.vscode/settings.json # intellij IDEs config /.idea/ diff --git a/.hashconfig.json b/.hashconfig.json deleted file mode 100644 index 4372e215eba..00000000000 --- a/.hashconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "redirects": {} -} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3fc2452b60f..9c4150b17bc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,7 +25,7 @@ These apply across all projects: ## How can I find interesting PRs to work on? -Issue tags can provide a good source of inspiration for would-be contributors. See: “help wanted” and “good for first-time contributors”. You should also feel free to join our [HASH Discord](https://hash.ai/discord) and reach out directly to us for more inspiration. If you're willing to contribute, we'd love to have you! +Existing issues can provide a good source of inspiration for potential contributions. The issue tags `E-help-wanted` and `E-good-first-issue` flag some of the lower-hanging fruit that are available for people (including first-time contributors) to work on, without necessarily requiring prior discussion. You should also feel free to join our [HASH Discord](https://hash.ai/discord) and reach out directly to us for more inspiration. If you're willing to contribute, we'd love to have you! ## Why might contributions be rejected? diff --git a/LICENSE.md b/LICENSE.md index 3b467a3fac2..4e7d0ad58bd 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -The HASH public monorepo relies upon multiple different licenses. +The HASH monorepo relies upon multiple different licenses. # License Guide @@ -9,24 +9,22 @@ The license for a particular work is defined with following prioritized rules: 1. Defaults to the MIT License Source code in this repository is variously licensed under the _MIT License_, -the _GNU Affero General Public License 3.0_, the _Elastic License 2.0_, or -_all rights are reserved_. +the _GNU Affero General Public License 3.0_, or the _Elastic License 2.0_. -Written content, illustrations and graphics published under the `resources` -folder within this repository may also be made available under the [Creative -Commons Attribution-ShareAlike 4.0 International](resources/LICENSE.md) -license. +Written content, illustrations and graphics published under the `sites/hashai/resources` +folder within this repository are made available under the [Creative Commons +Attribution-ShareAlike 4.0 International](sites/hashai/resources/LICENSE.md) license. # Quick Reference -* Within the `/packages/engine` directory, source code is licensed under the +* Within the `/packages/engine` folder, source code is licensed under the Elastic License 2.0, unless otherwise noted. -* Within the `/packages/hash` and `/packages/graph` directories, source code - in a given file is licensed under version 3 of the GNU Affero General - Public License, unless otherwise noted. +* Within the `/packages/hash` folder, source code in a given file is + licensed under version 3 of the GNU Affero General Public License, unless + otherwise noted. -* Within the `/packages/blocks` directory, all source code is made +* Within the `/packages/blocks` folder, all source code is made available under the MIT License. # Questions diff --git a/README.md b/README.md index a5d80474c1f..005bf500f4f 100644 --- a/README.md +++ b/README.md @@ -10,14 +10,13 @@ This is HASH's _public monorepo_ which contains our open-source, fair-source and - [`packages/blocks`](packages/blocks): The source code for all of HASH's open-source [Block Protocol](https://github.com/blockprotocol/blockprotocol) blocks - [`packages/hash`](packages/hash): The codebase for [HASH](https://hash.ai/platform/hash) - a data-driven, entity-centric, all-in-one workspace based on the Block Protocol -- [`packages/engine`](packages/engine): The codebase for our next-gen version of [hEngine](https://hash.ai/platform/engine) - a versatile agent-based simulation engine written in Rust +- [`packages/engine`](packages/engine): The codebase for our next-gen version of [HASH Engine](https://hash.ai/platform/engine) - a versatile agent-based simulation engine written in Rust - [`packages/libs`](packages/libs): The source code for our open-source developer libraries ### Site code and content -- [`resources/docs`](resources/docs): A user guide to the whole HASH platform ([hash.ai/docs](https://hash.ai/docs)) -- [`resources/glossary`](resources/glossary): A glossary of terms explaining common concepts relevant to the use of HASH ([hash.ai/glossary](https://hash.ai/glossary)) -- [`sites/hashdev`](sites/hashdev): The [hash.dev](https://hash.dev/) developer-education website +- [`sites/hashai`](sites/hashai): contains the [HASH user guide](https://hash.ai/docs) and [glossary of terms](https://hash.ai/glossary) content +- [`sites/hashdev`](sites/hashdev): contains the [hash.dev](https://hash.dev/) developer-education website content and code ## Contributing diff --git a/packages/blocks/callout/README.md b/packages/blocks/callout/README.md index a3e18599e14..33bc37dd291 100644 --- a/packages/blocks/callout/README.md +++ b/packages/blocks/callout/README.md @@ -1,3 +1,3 @@ # Callout block -https://blockprotocol.org/@hash/callout +A block to call attention to text. diff --git a/packages/blocks/callout/package.json b/packages/blocks/callout/package.json index 1e5faa17518..f64a7fcbf53 100644 --- a/packages/blocks/callout/package.json +++ b/packages/blocks/callout/package.json @@ -19,7 +19,8 @@ "serve": "block-scripts serve" }, "dependencies": { - "@blockprotocol/graph": "0.0.12" + "@blockprotocol/graph": "0.0.12", + "@blockprotocol/hook": "0.0.1" }, "devDependencies": { "block-scripts": "0.0.14", diff --git a/packages/blocks/callout/src/app.tsx b/packages/blocks/callout/src/app.tsx index 619d0a76a64..eafd70d77d6 100644 --- a/packages/blocks/callout/src/app.tsx +++ b/packages/blocks/callout/src/app.tsx @@ -2,29 +2,37 @@ import { BlockComponent, useGraphBlockService, } from "@blockprotocol/graph/react"; -import { RefCallback, useRef } from "react"; +import { useHookBlockService, useHook } from "@blockprotocol/hook/react"; +import { useRef } from "react"; import { EmojiIcon } from "./emoji-icon"; type BlockEntityProperties = { icon?: string; text?: string; - editableRef?: RefCallback; }; export const App: BlockComponent = ({ graph: { blockEntity: { entityId, properties }, }, - ...others }) => { - const editableRef = (others as any).editableRef as - | RefCallback - | undefined; + const editableRef = useRef(null); const { icon = "📢", text } = properties; const blockRef = useRef(null); const { graphService } = useGraphBlockService(blockRef); + const { hookService } = useHookBlockService(blockRef); + + useHook(hookService, editableRef, "text", "$.text", (node) => { + // eslint-disable-next-line no-param-reassign + node.innerText = text ?? ""; + + return () => { + // eslint-disable-next-line no-param-reassign + node.innerText = ""; + }; + }); const handleIconChange = (newIcon: string | undefined): void => { if (!entityId) { @@ -65,9 +73,7 @@ export const App: BlockComponent = ({ paddingLeft: "1.5em", }} ref={editableRef} - > - {editableRef ? undefined : text} - + /> ); }; diff --git a/packages/blocks/embed/README.md b/packages/blocks/embed/README.md index 22625071381..fb51c2dc8f0 100644 --- a/packages/blocks/embed/README.md +++ b/packages/blocks/embed/README.md @@ -1,3 +1,3 @@ # Embed block -https://blockprotocol.org/@hash/embed +A block to embed content from third-party sites. diff --git a/packages/blocks/header/README.md b/packages/blocks/header/README.md index 791f871f4b4..dabec38e456 100644 --- a/packages/blocks/header/README.md +++ b/packages/blocks/header/README.md @@ -1,3 +1,3 @@ # Header block -https://blockprotocol.org/@hash/header +A block to display heading text. diff --git a/packages/blocks/paragraph/README.md b/packages/blocks/paragraph/README.md index 0969c8aa7ae..a6bdc000ae2 100644 --- a/packages/blocks/paragraph/README.md +++ b/packages/blocks/paragraph/README.md @@ -1,3 +1,3 @@ # Paragraph block -https://blockprotocol.org/@hash/paragraph +A block to display a paragraph of text. diff --git a/packages/blocks/paragraph/package.json b/packages/blocks/paragraph/package.json index 1025764712b..803db519461 100644 --- a/packages/blocks/paragraph/package.json +++ b/packages/blocks/paragraph/package.json @@ -19,12 +19,13 @@ "serve": "block-scripts serve" }, "dependencies": { - "blockprotocol": "0.0.12" + "@blockprotocol/graph": "0.0.12", + "@blockprotocol/hook": "0.0.1" }, "devDependencies": { "block-scripts": "0.0.14", "eslint": "8.20.0", - "mock-block-dock": "0.0.10", + "mock-block-dock": "0.0.20", "react": "^18.2.0", "react-dom": "^18.2.0", "typescript": "4.7.4", @@ -39,6 +40,9 @@ "servePort": 62682 }, "blockprotocol": { + "blockType": { + "entryPoint": "react" + }, "displayName": "Paragraph", "icon": "public/paragraph.svg", "image": "public/preview.svg", @@ -47,6 +51,6 @@ "text": "William Shakespeare was an English playwright, poet and actor, widely regarded as the greatest writer in the English language and the world's greatest dramatist. He is often called England's national poet and the \"Bard of Avon\"." } ], - "protocol": "0.1" + "protocol": "0.2" } } diff --git a/packages/blocks/paragraph/src/app.tsx b/packages/blocks/paragraph/src/app.tsx index e4e65224491..d5e3ceb1e6c 100644 --- a/packages/blocks/paragraph/src/app.tsx +++ b/packages/blocks/paragraph/src/app.tsx @@ -1,15 +1,30 @@ -import { RefCallback } from "react"; - -import { BlockComponent } from "blockprotocol/react"; +import { useRef } from "react"; +import { BlockComponent } from "@blockprotocol/graph/react"; +import { useHook, useHookBlockService } from "@blockprotocol/hook/react"; type BlockEntityProperties = { - editableRef?: RefCallback; text?: string; }; export const App: BlockComponent = ({ - editableRef, - text, + graph: { + blockEntity: { + properties: { text }, + }, + }, }) => { - return editableRef ?

:

{text}

; + const ref = useRef(null); + const { hookService } = useHookBlockService(ref); + + useHook(hookService, ref, "text", "$.text", (node) => { + // eslint-disable-next-line no-param-reassign + node.innerText = text ?? ""; + + return () => { + // eslint-disable-next-line no-param-reassign + node.innerText = ""; + }; + }); + + return

; }; diff --git a/packages/blocks/paragraph/src/dev.tsx b/packages/blocks/paragraph/src/dev.tsx index af916089e6b..920b41c601a 100644 --- a/packages/blocks/paragraph/src/dev.tsx +++ b/packages/blocks/paragraph/src/dev.tsx @@ -9,10 +9,18 @@ import Component from "./index"; const node = document.getElementById("app"); +const paragraphProperties = { + text: "Hello World!", +}; + const App = () => ( - - - + ); render(, node); diff --git a/packages/blocks/toggle-item/src/app.tsx b/packages/blocks/toggle-item/src/app.tsx index aeeae201351..422ba658606 100644 --- a/packages/blocks/toggle-item/src/app.tsx +++ b/packages/blocks/toggle-item/src/app.tsx @@ -62,7 +62,7 @@ export const App: BlockComponent = ({ >

= ({