diff --git a/.dockerignore b/.dockerignore index c328aed4f..91b84890d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -9,3 +9,31 @@ !.yarn/plugins !.yarn/sdks !.yarn/versions +.pnp.* + +**/node_modules +node_modules + +frontend/.next +**/dist + +.github +**/Dockerfile +.dockerignore + +frontend/cypress/downloads + +**/.env + +backend/public/uploads +backend/uploads +backend/test_uploads + +**/coverage +**/coverage-e2e +**/.nyc_output + +backend/hedgedoc.sqlite + +**/.turbo + diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml index 16cb3d069..2c4e98534 100644 --- a/.github/actions/setup-node/action.yml +++ b/.github/actions/setup-node/action.yml @@ -6,9 +6,9 @@ name: Setup Node description: "Setups node and configures the cache" inputs: - NODE_VERSION: + NODEJS_VERSION: required: true - type: string + description: "NodeJS version to install" runs: using: "composite" @@ -23,21 +23,16 @@ runs: id: yarn-cache with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-${{ inputs.NODE_VERSION }}-yarn-${{ hashFiles('frontend/yarn.lock') }} + key: ${{ runner.os }}-${{ inputs.NODEJS_VERSION }}-yarn-${{ hashFiles('yarn.lock') }} restore-keys: | - ${{ runner.os }}-yarn-${{ inputs.NODE_VERSION }} + ${{ runner.os }}-yarn-${{ inputs.NODEJS_VERSION }} - name: Set up NodeJS uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 with: - node-version: ${{ inputs.NODE_VERSION }} + node-version: ${{ inputs.NODEJS_VERSION }} - name: Install dependencies run: yarn install --immutable working-directory: . shell: bash - - - name: Build commons lib - run: yarn build - working-directory: commons - shell: bash diff --git a/.github/workflows/backend-docker-cleanup.yml b/.github/workflows/backend-docker-cleanup.yml deleted file mode 100644 index 07bb9b2b8..000000000 --- a/.github/workflows/backend-docker-cleanup.yml +++ /dev/null @@ -1,24 +0,0 @@ -# SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) -# -# SPDX-License-Identifier: AGPL-3.0-only - -name: Delete old container images - -on: - schedule: - - cron: '0 0 * * *' # every day at midnight - workflow_dispatch: - -jobs: - clean-ghcr: - name: Cleanup CI containers - runs-on: ubuntu-latest - steps: - - name: Cleanup CI containers - uses: snok/container-retention-policy@6601a342b42bf08909bbd5b48736d4176100365b # v1.5.1 - with: - image-names: hedgedoc-ci - cut-off: A day ago UTC - account-type: org - org-name: ${{ github.repository_owner }} - token: ${{ secrets.PAT_IMAGE_CLEANUP }} diff --git a/.github/workflows/backend-docker.yml b/.github/workflows/backend-docker.yml deleted file mode 100644 index b12aefb4b..000000000 --- a/.github/workflows/backend-docker.yml +++ /dev/null @@ -1,143 +0,0 @@ -# SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) -# -# SPDX-License-Identifier: AGPL-3.0-only - -name: Backend / Docker - -on: - push: - branches: [ develop ] - pull_request_target: - branches: [ develop ] - pull_request: - branches: [ develop ] - -permissions: - contents: read - packages: write - -concurrency: - group: ${{ github.workflow }}-${{ !!github.event.pull_request && github.event.pull_request.head.label || github.ref }}-${{ github.event_name }}-${{ github.job }} - cancel-in-progress: true - -jobs: - changes: - name: Check for backend changes - runs-on: ubuntu-latest - permissions: - pull-requests: read - outputs: - changed: ${{ github.event_name == 'push' || steps.changed.outputs.files }} - steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - if: github.event_name != 'push' - - - name: Check for backend file changes - if: github.event_name != 'push' - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 - id: changed - with: - filters: | - files: - - 'commons/**' - - 'backend/**' - - '.github/**' - - '.yarn/**' - - build-dev: - if: "(github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork" - needs: changes - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - if: needs.changes.outputs.changed == 'true' - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@15c905b16b06416d2086efa066dd8e3a35cc7f98 # v2.4.0 - if: needs.changes.outputs.changed == 'true' - - - name: Login to GHCR - if: needs.changes.outputs.changed == 'true' - uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build dev image - if: needs.changes.outputs.changed == 'true' - uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 # v4.0.0 - with: - push: true - file: backend/docker/Dockerfile - tags: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}-ci:${{ github.sha }} - target: development - cache-from: type=gha - cache-to: type=gha,mode=max - context: . - - sqlite-test: - runs-on: ubuntu-latest - if: needs.changes.outputs.changed == 'true' && (github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork - needs: [ build-dev, changes ] - container: - image: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}-ci:${{ github.sha }} - steps: - - run: cd /usr/src/app/backend && yarn run test - - sqlite-e2e: - runs-on: ubuntu-latest - if: needs.changes.outputs.changed == 'true' && (github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork - needs: [ build-dev, changes ] - container: - image: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}-ci:${{ github.sha }} - steps: - - run: cd /usr/src/app/backend && yarn run test:e2e - - build-prod: - runs-on: ubuntu-latest - if: (github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork - needs: [ sqlite-test, sqlite-e2e, changes ] - steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - if: needs.changes.outputs.changed == 'true' - - - name: Generate Docker metadata - if: needs.changes.outputs.changed == 'true' - id: meta - uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 # v4.3.0 - with: - images: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }} - tags: | - type=ref,event=branch - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - - - name: Set up QEMU - uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # v2.1.0 - if: needs.changes.outputs.changed == 'true' - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@15c905b16b06416d2086efa066dd8e3a35cc7f98 # v2.4.0 - if: needs.changes.outputs.changed == 'true' - - - name: Login to GHCR - if: github.event_name == 'push' && needs.changes.outputs.changed == 'true' - uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push - if: needs.changes.outputs.changed == 'true' - uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 # v4.0.0 - with: - push: ${{ github.event_name == 'push' }} - file: backend/docker/Dockerfile - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max - context: . diff --git a/.github/workflows/backend-e2e-tests.yml b/.github/workflows/backend-e2e-tests.yml deleted file mode 100644 index 3e833f3f6..000000000 --- a/.github/workflows/backend-e2e-tests.yml +++ /dev/null @@ -1,130 +0,0 @@ -# SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) -# -# SPDX-License-Identifier: AGPL-3.0-only - -name: Backend / E2E Tests - -on: - push: - branches: [ develop ] - pull_request: - branches: [ develop ] - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-${{ github.job }} - cancel-in-progress: true - -env: - NODEJS_VERSION: 18 - -defaults: - run: - working-directory: backend - -jobs: - changes: - name: Check for backend changes - runs-on: ubuntu-latest - permissions: - pull-requests: read - outputs: - changed: ${{ github.event_name == 'push' || steps.changed.outputs.files }} - steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - if: github.event_name != 'push' - - - name: Check for backend file changes - if: github.event_name != 'push' - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 - id: changed - with: - filters: | - files: - - 'commons/**' - - 'backend/**' - - '.github/**' - - '.yarn/**' - - sqlite: # This run also collects coverage - needs: changes - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - if: needs.changes.outputs.changed == 'true' - with: - fetch-depth: 0 - - - name: Setup node - if: needs.changes.outputs.changed == 'true' - uses: ./.github/actions/setup-node - with: - NODE_VERSION: ${{ env.NODEJS_VERSION }} - - - run: yarn run test:e2e:cov - if: needs.changes.outputs.changed == 'true' - - - uses: codecov/codecov-action@v3 - if: needs.changes.outputs.changed == 'true' - with: - directory: backend/coverage-e2e - flags: e2e-tests - - mariadb: - needs: changes - runs-on: ubuntu-latest - services: - mariadb: - image: mariadb - env: - MYSQL_USER: hedgedoc - MYSQL_PASSWORD: hedgedoc - MYSQL_DATABASE: hedgedoc - MYSQL_ROOT_PASSWORD: hedgedoc - options: --health-cmd "mysqladmin ping" --health-interval 5s --health-timeout 2s --health-retries 5 - ports: - - 3306:3306 - steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - if: needs.changes.outputs.changed == 'true' - with: - fetch-depth: 0 - - - name: Setup node - if: needs.changes.outputs.changed == 'true' - uses: ./.github/actions/setup-node - with: - NODE_VERSION: ${{ env.NODEJS_VERSION }} - - - run: yarn run test:e2e - if: needs.changes.outputs.changed == 'true' - env: - HEDGEDOC_TEST_DB_TYPE: mariadb - - postgres: - needs: changes - runs-on: ubuntu-latest - services: - postgres: - image: postgres - env: - POSTGRES_PASSWORD: hedgedoc - POSTGRES_USER: hedgedoc - options: --health-cmd pg_isready --health-interval 5s --health-timeout 2s --health-retries 5 - ports: - - 5432:5432 - steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - if: needs.changes.outputs.changed == 'true' - with: - fetch-depth: 0 - - - name: Setup node - if: needs.changes.outputs.changed == 'true' - uses: ./.github/actions/setup-node - with: - NODE_VERSION: ${{ env.NODEJS_VERSION }} - - - run: yarn run test:e2e - if: needs.changes.outputs.changed == 'true' - env: - HEDGEDOC_TEST_DB_TYPE: postgres diff --git a/.github/workflows/backend-tests.yml b/.github/workflows/backend-tests.yml deleted file mode 100644 index 970c83d61..000000000 --- a/.github/workflows/backend-tests.yml +++ /dev/null @@ -1,106 +0,0 @@ -# SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) -# -# SPDX-License-Identifier: AGPL-3.0-only - - -name: Backend / Lint and Test - -on: - push: - branches: [ develop ] - pull_request: - branches: [ develop ] - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-${{ github.job }} - cancel-in-progress: true - -env: - NODEJS_VERSION: 18 - -defaults: - run: - working-directory: backend - -jobs: - changes: - name: Check for backend changes - runs-on: ubuntu-latest - permissions: - pull-requests: read - outputs: - changed: ${{ github.event_name == 'push' || steps.changed.outputs.files }} - steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - if: github.event_name != 'push' - - - name: Check for backend file changes - if: github.event_name != 'push' - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 - id: changed - with: - filters: | - files: - - 'commons/**' - - 'backend/**' - - '.github/**' - - '.yarn/**' - - lint: - needs: changes - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - if: needs.changes.outputs.changed == 'true' - - - name: Setup node - if: needs.changes.outputs.changed == 'true' - uses: ./.github/actions/setup-node - with: - NODE_VERSION: ${{ env.NODEJS_VERSION }} - - - run: yarn run lint - if: needs.changes.outputs.changed == 'true' - - build: - needs: changes - runs-on: ubuntu-latest - strategy: - matrix: - node-version: [ 14.x, 16.x, 18.x ] - steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - if: needs.changes.outputs.changed == 'true' - - - name: Setup node - if: needs.changes.outputs.changed == 'true' - uses: ./.github/actions/setup-node - with: - NODE_VERSION: ${{ env.NODE_VERSION }} - - - run: yarn run build - if: needs.changes.outputs.changed == 'true' - - integration-tests: - needs: changes - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - if: needs.changes.outputs.changed == 'true' - with: - fetch-depth: 0 - - - name: Setup node - if: needs.changes.outputs.changed == 'true' - uses: ./.github/actions/setup-node - with: - NODE_VERSION: ${{ env.NODE_VERSION }} - - - run: yarn run test:cov - if: needs.changes.outputs.changed == 'true' - - - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 - if: needs.changes.outputs.changed == 'true' - with: - directory: backend/coverage - flags: integration-tests diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 3cc217d73..000000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,92 +0,0 @@ -# SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) -# -# SPDX-License-Identifier: AGPL-3.0-only - -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: [ develop ] - paths: - - 'backend/src/' - - 'backend/test/' - - 'frontend/src/' - - 'frontend/cypress/' - pull_request: - # The branches below must be a subset of the branches above - branches: [ develop ] - paths: - - 'backend/src/' - - 'backend/test/' - - 'frontend/src/' - - 'frontend/cypress/' - schedule: - - cron: '15 4 * * 3' - -permissions: - contents: read - security-events: write - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'javascript' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] - # Learn more: - # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed - - steps: - - name: Checkout repository - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@3ebbd71c74ef574dbc558c82f70e52732c8b44fe # v2.2.1 - with: - languages: ${{ matrix.language }} - queries: +security-and-quality - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@3ebbd71c74ef574dbc558c82f70e52732c8b44fe # v2.2.1 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@3ebbd71c74ef574dbc558c82f70e52732c8b44fe # v2.2.1 - with: - category: "/language:${{ matrix.language }}" diff --git a/.github/workflows/commons-lint.yml b/.github/workflows/commons-lint.yml deleted file mode 100644 index 50bcee7d3..000000000 --- a/.github/workflows/commons-lint.yml +++ /dev/null @@ -1,60 +0,0 @@ -# SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) -# -# SPDX-License-Identifier: AGPL-3.0-only - -name: Commons / Lint - -on: - push: - branches: [ develop ] - pull_request: - branches: [ develop ] - -env: - NODE_VERSION: 18 - -defaults: - run: - working-directory: commons - -jobs: - changes: - name: Check for commons changes - runs-on: ubuntu-latest - permissions: - pull-requests: read - outputs: - changed: ${{ github.event_name == 'push' || steps.changed.outputs.files }} - steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - if: github.event_name != 'push' - - - name: Check for frontend file changes - if: github.event_name != 'push' - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 - id: changed - with: - filters: | - files: - - 'commons/**' - - '.github/**' - - '.yarn/**' - - lint: - needs: changes - runs-on: ubuntu-latest - name: Lints all .ts and .tsx files - steps: - - name: Checkout repository - if: needs.changes.outputs.changed == 'true' - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - - - name: Setup node - if: needs.changes.outputs.changed == 'true' - uses: ./.github/actions/setup-node - with: - NODE_VERSION: ${{ env.NODE_VERSION }} - - - name: Lint code - if: needs.changes.outputs.changed == 'true' - run: yarn lint diff --git a/.github/workflows/commons-tests.yml b/.github/workflows/commons-tests.yml deleted file mode 100644 index bf54f589e..000000000 --- a/.github/workflows/commons-tests.yml +++ /dev/null @@ -1,68 +0,0 @@ -# SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) -# -# SPDX-License-Identifier: AGPL-3.0-only - -name: Commons / Run unit tests & build - -on: - push: - branches: [ develop ] - pull_request: - branches: [ develop ] - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-${{ github.job }} - cancel-in-progress: true - -defaults: - run: - working-directory: commons - -jobs: - changes: - name: Check for commons changes - runs-on: ubuntu-latest - permissions: - pull-requests: read - outputs: - changed: ${{ github.event_name == 'push' || steps.changed.outputs.files }} - steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - if: github.event_name != 'push' - - - name: Check for frontend file changes - if: github.event_name != 'push' - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 - id: changed - with: - filters: | - files: - - 'commons/**' - - '.github/**' - - '.yarn/**' - - build: - needs: changes - runs-on: ubuntu-latest - strategy: - matrix: - node: [ '14', '16', '18' ] - name: Test and build with NodeJS ${{ matrix.node }} - steps: - - name: Checkout repository - if: needs.changes.outputs.changed == 'true' - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - - - name: Setup node - if: needs.changes.outputs.changed == 'true' - uses: ./.github/actions/setup-node - with: - NODE_VERSION: ${{ matrix.node }} - - - name: Test Project - if: needs.changes.outputs.changed == 'true' - run: yarn test - - - name: Build project - if: needs.changes.outputs.changed == 'true' - run: yarn build diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 000000000..7fe9d15a2 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,89 @@ +# SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) +# +# SPDX-License-Identifier: AGPL-3.0-only + +name: Docker + +on: + push: + branches: [ develop ] + +permissions: + contents: read + packages: write + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.job }} + cancel-in-progress: true + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 + + - name: Generate Docker metadata for backend + id: meta-backend + uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 # v4.3.0 + with: + images: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/backend + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + + - name: Generate Docker metadata for frontend + id: meta-frontend + uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 # v4.3.0 + with: + images: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/frontend + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + + - name: Set up QEMU + uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # v2.1.0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@15c905b16b06416d2086efa066dd8e3a35cc7f98 # v2.4.0 + + - name: Login to GHCR + uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push backend + uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 # v4.0.0 + with: + push: true + file: backend/docker/Dockerfile + tags: ${{ steps.meta-backend.outputs.tags }} + labels: ${{ steps.meta-backend.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + context: . + build-args: + TURBO_TOKEN: "${{ secrets.TURBO_TOKEN }}" + TURBO_API: "${{ vars.TURBO_API }}" + TURBO_TEAM: "${{ vars.TURBO_TEAM }}" + + - name: Build and push frontend + uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 # v4.0.0 + with: + push: true + file: frontend/docker/Dockerfile + tags: ${{ steps.meta-frontend.outputs.tags }} + labels: ${{ steps.meta-frontend.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + context: . + build-args: + BUILD_VERSION: "${{ github.event.head_commit.id }}" + TURBO_TOKEN: "${{ secrets.TURBO_TOKEN }}" + TURBO_API: "${{ vars.TURBO_API }}" + TURBO_TEAM: "${{ vars.TURBO_TEAM }}" diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml new file mode 100644 index 000000000..965eef25c --- /dev/null +++ b/.github/workflows/e2e-tests.yml @@ -0,0 +1,193 @@ +# SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) +# +# SPDX-License-Identifier: AGPL-3.0-only + +name: E2E Tests + +on: + push: + branches: [ develop ] + pull_request_target: + branches: [ develop ] + pull_request: + branches: [ develop ] + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ !!github.event.pull_request && github.event.pull_request.head.label || github.ref }}-${{ github.event_name }}-${{ github.job }} + cancel-in-progress: true + +env: + NODEJS_VERSION: 18 + HEAD_COMMIT_HASH: "${{ !!github.event.pull_request && github.event.pull_request.head.sha || github.sha }}" + +jobs: + backend-sqlite: # This run also collects coverage + if: "(github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 + with: + fetch-depth: 0 + - name: Setup node + uses: ./.github/actions/setup-node + with: + NODEJS_VERSION: ${{ env.NODEJS_VERSION }} + + - name: Run e2e tests + run: yarn turbo run test:e2e:ci --filter=backend + shell: bash + env: + HEDGEDOC_TEST_DB_TYPE: sqlite + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_API: ${{ vars.TURBO_API }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} + + - name: Upload coverage + uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + directory: backend/coverage-e2e + flags: e2e-tests + + backend-mariadb: + if: "(github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork" + runs-on: ubuntu-latest + services: + mariadb: + image: mariadb + env: + MYSQL_USER: hedgedoc + MYSQL_PASSWORD: hedgedoc + MYSQL_DATABASE: hedgedoc + MYSQL_ROOT_PASSWORD: hedgedoc + options: --health-cmd "mysqladmin ping" --health-interval 5s --health-timeout 2s --health-retries 5 + ports: + - 3306:3306 + steps: + - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 + with: + fetch-depth: 0 + - name: Setup node + uses: ./.github/actions/setup-node + with: + NODEJS_VERSION: ${{ env.NODEJS_VERSION }} + + - name: Run e2e tests + run: yarn turbo run test:e2e:ci --filter=backend + shell: bash + env: + HEDGEDOC_TEST_DB_TYPE: mariadb + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_API: ${{ vars.TURBO_API }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} + + backend-postgres: + if: "(github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork" + runs-on: ubuntu-latest + services: + postgres: + image: postgres + env: + POSTGRES_PASSWORD: hedgedoc + POSTGRES_USER: hedgedoc + options: --health-cmd pg_isready --health-interval 5s --health-timeout 2s --health-retries 5 + ports: + - 5432:5432 + steps: + - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 + with: + fetch-depth: 0 + - name: Setup node + uses: ./.github/actions/setup-node + with: + NODEJS_VERSION: ${{ env.NODEJS_VERSION }} + + - name: Run e2e tests + run: yarn turbo run test:e2e:ci --filter=backend + shell: bash + env: + HEDGEDOC_TEST_DB_TYPE: postgres + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_API: ${{ vars.TURBO_API }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} + + frontend-build: + if: "(github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork" + runs-on: ubuntu-latest + name: Build test build of frontend + steps: + - name: Check out repo + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 + with: + ref: ${{ env.HEAD_COMMIT_HASH }} + + - name: Setup node + uses: ./.github/actions/setup-node + with: + NODEJS_VERSION: ${{ env.NODEJS_VERSION }} + + - name: Build test production build + run: yarn turbo run build:test --filter=frontend + shell: bash + env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_API: ${{ vars.TURBO_API }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} + + frontend-cypress: + if: "(github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork" + needs: frontend-build + runs-on: ubuntu-latest + container: + image: cypress/browsers:node18.12.0-chrome106-ff106 + options: --shm-size=2g + strategy: + fail-fast: false + matrix: + containers: [ 1, 2, 3 ] + steps: + - name: Check out repo + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 + + - name: Setup node + uses: ./.github/actions/setup-node + with: + NODEJS_VERSION: ${{ env.NODEJS_VERSION }} + + - name: Install jq + run: apt-get update && apt-get install -y jq + + - name: Build test production build + run: yarn turbo run build:test --filter=frontend + shell: bash + env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_API: ${{ vars.TURBO_API }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} + + - name: Run server + working-directory: frontend/ + run: yarn start:ci & + env: + NODE_ENV: test + + - name: Wait for server + run: "sleep 3 && curl --max-time 120 http://127.0.0.1:3001/" + + - name: Run cypress + run: yarn turbo run test:e2e:ci --filter=frontend + shell: bash + env: + CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_API: ${{ vars.TURBO_API }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} + CYPRESS_CONTAINER_ID: ${{ matrix.containers }} + + - uses: actions/upload-artifact@65d862660abb392b8c4a3d1195a2108db131dd05 # master + with: + name: screenshots + path: cypress/screenshots diff --git a/.github/workflows/frontend-docker.yml b/.github/workflows/frontend-docker.yml deleted file mode 100644 index 349277c13..000000000 --- a/.github/workflows/frontend-docker.yml +++ /dev/null @@ -1,94 +0,0 @@ -# SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) -# -# SPDX-License-Identifier: AGPL-3.0-only - -name: Frontend / build docker image - -on: - push: - branches: [ develop ] - -defaults: - run: - working-directory: frontend - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-${{ github.job }} - cancel-in-progress: true - -permissions: - contents: read - packages: write - -jobs: - changes: - name: Check for frontend changes - runs-on: ubuntu-latest - permissions: - pull-requests: read - outputs: - changed: ${{ github.event_name == 'push' || steps.changed.outputs.files }} - steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - if: github.event_name != 'push' - - - name: Check for frontend file changes - if: github.event_name != 'push' - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 - id: changed - with: - filters: | - files: - - 'commons/**' - - 'frontend/**' - - '.github/**' - - '.yarn/**' - - build: - needs: changes - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - if: needs.changes.outputs.changed == 'true' - - - name: Generate Docker metadata - if: needs.changes.outputs.changed == 'true' - id: meta - uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 # v4.3.0 - with: - images: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }} - tags: | - type=ref,event=branch - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - - - name: Set up QEMU - if: needs.changes.outputs.changed == 'true' - uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # v2.1.0 - - - name: Set up Docker Buildx - if: needs.changes.outputs.changed == 'true' - uses: docker/setup-buildx-action@15c905b16b06416d2086efa066dd8e3a35cc7f98 # v2.4.0 - - - name: Login to GHCR - if: github.event_name != 'pull_request' && needs.changes.outputs.changed == 'true' - uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push - if: needs.changes.outputs.changed == 'true' - uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 # v4.0.0 - with: - push: true - file: frontend/docker/Dockerfile - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max - context: . - build-args: | - BUILD_VERSION=${{ github.event.head_commit.id }} diff --git a/.github/workflows/frontend-e2e-tests.yml b/.github/workflows/frontend-e2e-tests.yml deleted file mode 100644 index d42fbd9b6..000000000 --- a/.github/workflows/frontend-e2e-tests.yml +++ /dev/null @@ -1,174 +0,0 @@ -# SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) -# -# SPDX-License-Identifier: AGPL-3.0-only - -name: Frontend / Run E2E Tests - -on: - push: - branches: [ develop ] - pull_request_target: - branches: [ develop ] - pull_request: - branches: [ develop ] - -permissions: - contents: read - -env: - NODE_VERSION: 18 - HEAD_COMMIT_HASH: "${{ !!github.event.pull_request && github.event.pull_request.head.sha || github.sha }}" - -defaults: - run: - working-directory: frontend - -concurrency: - group: ${{ github.workflow }}-${{ !!github.event.pull_request && github.event.pull_request.head.label || github.ref }}-${{ github.event_name }}-${{ github.job }} - cancel-in-progress: true - -jobs: - changes: - name: Check for frontend changes - runs-on: ubuntu-latest - permissions: - pull-requests: read - outputs: - changed: ${{ github.event_name == 'push' || steps.changed.outputs.files }} - steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - if: github.event_name != 'push' - - - name: Check for frontend file changes - if: github.event_name != 'push' - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 - id: changed - with: - filters: | - files: - - 'commons/**' - - 'frontend/**' - - '.github/**' - - '.yarn/**' - - build-frontend: - needs: changes - if: "(github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork" - runs-on: ubuntu-latest - name: Build test build of frontend - steps: - - name: Check out repo - if: needs.changes.outputs.changed == 'true' - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - with: - ref: ${{ env.HEAD_COMMIT_HASH }} - - - name: Cache build - if: needs.changes.outputs.changed == 'true' - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 # v3.2.4 - id: build-cache - with: - path: frontend/.next - key: ${{ env.HEAD_COMMIT_HASH }} - - - name: Setup node - if: steps.build-cache.outputs.cache-hit != 'true' && needs.changes.outputs.changed == 'true' - uses: ./.github/actions/setup-node - with: - NODE_VERSION: ${{ env.NODE_VERSION }} - - - name: Build test production build - if: steps.build-cache.outputs.cache-hit != 'true' && needs.changes.outputs.changed == 'true' - run: yarn build:test - - - uses: actions/upload-artifact@65d862660abb392b8c4a3d1195a2108db131dd05 # master - if: needs.changes.outputs.changed == 'true' - with: - retention-days: 1 - name: e2e-build - path: | - frontend/.next - !frontend/.next/cache - !frontend/.next/standalone - - end2end: - name: Perform E2E Test in ${{ matrix.browser }} - needs: - - build-frontend - - changes - runs-on: ubuntu-latest - container: - image: cypress/browsers:node18.12.0-chrome106-ff106 - options: --user 1001 --shm-size=2g - strategy: - fail-fast: false - matrix: - browser: [ 'chrome' ] - containers: [ 1, 2, 3, 4, 5 ] - steps: - - name: Check out repo - if: needs.changes.outputs.changed == 'true' - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - - - name: Cache build - if: needs.changes.outputs.changed == 'true' - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 # v3.2.4 - id: build-cache - with: - path: frontend/.next - key: ${{ env.HEAD_COMMIT_HASH }} - - - name: Get yarn cache directory path - if: needs.changes.outputs.changed == 'true' - id: yarn-cache-dir-path - run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT - - - name: Cache yarn cache - if: needs.changes.outputs.changed == 'true' - uses: actions/cache@627f0f41f6904a5b1efbaed9f96d9eb58e92e920 # v3.2.4 - id: yarn-cache - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-${{ env.NODE_VERSION }}-yarn-${{ hashFiles('frontend/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn-${{ env.NODE_VERSION }} - - - name: Set up NodeJS - if: steps.build-cache.outputs.cache-hit != 'true' && needs.changes.outputs.changed == 'true' - uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 - with: - node-version: ${{ env.NODE_VERSION }} - - - name: Install dependencies - if: needs.changes.outputs.changed == 'true' - run: yarn install --immutable - - - name: Download built frontend - if: needs.changes.outputs.changed == 'true' - uses: actions/download-artifact@e9ef242655d12993efdcda9058dee2db83a2cb9b # master - with: - name: e2e-build - path: frontend/.next - - - name: Run server - if: needs.changes.outputs.changed == 'true' - run: yarn start:ci & - env: - NODE_ENV: test - - - name: Wait for server - if: needs.changes.outputs.changed == 'true' - run: "sleep 3 && curl --max-time 120 http://127.0.0.1:3001/" - - - name: Run cypress - if: needs.changes.outputs.changed == 'true' - run: "yarn cy:run:${{ matrix.browser }} --record true --parallel --group \"UI - ${{ matrix.browser }}\"" - env: - CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - uses: actions/upload-artifact@65d862660abb392b8c4a3d1195a2108db131dd05 # master - if: needs.changes.outputs.changed == 'true' - with: - name: screenshots - path: cypress/screenshots diff --git a/.github/workflows/frontend-lint.yml b/.github/workflows/frontend-lint.yml deleted file mode 100644 index 7a7ed9919..000000000 --- a/.github/workflows/frontend-lint.yml +++ /dev/null @@ -1,61 +0,0 @@ -# SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) -# -# SPDX-License-Identifier: AGPL-3.0-only - -name: Frontend / Lint - -on: - push: - branches: [ develop ] - pull_request: - branches: [ develop ] - -env: - NODE_VERSION: 18 - -defaults: - run: - working-directory: frontend - -jobs: - changes: - name: Check for frontend changes - runs-on: ubuntu-latest - permissions: - pull-requests: read - outputs: - changed: ${{ github.event_name == 'push' || steps.changed.outputs.files }} - steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - if: github.event_name != 'push' - - - name: Check for frontend file changes - if: github.event_name != 'push' - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 - id: changed - with: - filters: | - files: - - 'commons/**' - - 'frontend/**' - - '.github/**' - - '.yarn/**' - - lint: - needs: changes - runs-on: ubuntu-latest - name: Lints all .ts and .tsx files - steps: - - name: Checkout repository - if: needs.changes.outputs.changed == 'true' - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - - - name: Setup node - if: needs.changes.outputs.changed == 'true' - uses: ./.github/actions/setup-node - with: - NODE_VERSION: ${{ env.NODE_VERSION }} - - - name: Lint code - if: needs.changes.outputs.changed == 'true' - run: yarn lint diff --git a/.github/workflows/frontend-netlify-deploy-main.yml b/.github/workflows/frontend-netlify-deploy-main.yml index 99a635a15..be461ea87 100644 --- a/.github/workflows/frontend-netlify-deploy-main.yml +++ b/.github/workflows/frontend-netlify-deploy-main.yml @@ -10,7 +10,7 @@ on: env: NETLIFY_VERSION: 12.0.11 - NODE_VERSION: 18 + NODEJS_VERSION: 18 defaults: run: @@ -21,74 +21,47 @@ concurrency: cancel-in-progress: true jobs: - changes: - name: Check for frontend changes - runs-on: ubuntu-latest - permissions: - pull-requests: read - outputs: - changed: ${{ github.event_name == 'push' || steps.changed.outputs.files }} - steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - if: github.event_name != 'push' - - - name: Check for frontend file changes - if: github.event_name != 'push' - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 - id: changed - with: - filters: | - files: - - 'commons/**' - - 'frontend/**' - - '.github/**' - - '.yarn/**' - deploy: - needs: changes runs-on: ubuntu-latest name: Deploys to netlify steps: - name: Checkout repository - if: needs.changes.outputs.changed == 'true' uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - name: Setup node - if: needs.changes.outputs.changed == 'true' uses: ./.github/actions/setup-node with: - NODE_VERSION: ${{ env.NODE_VERSION }} + NODEJS_VERSION: ${{ env.NODEJS_VERSION }} - name: Patch intro.md to include netlify banner. - if: needs.changes.outputs.changed == 'true' run: cp netlify/intro.md public/public/intro.md - name: Patch motd.md to include privacy policy. - if: needs.changes.outputs.changed == 'true' run: cp netlify/motd.md public/public/motd.md - name: Patch version.json to include git hash - if: needs.changes.outputs.changed == 'true' run: jq ".version = \"0.0.0+${GITHUB_SHA:0:8}\"" src/version.json > src/_version.json && mv src/_version.json src/version.json - name: Patch base URL - if: needs.changes.outputs.changed == 'true' run: echo "HD_BASE_URL=\"https://hedgedoc.dev/\"" >> .env.production - name: Build app - if: needs.changes.outputs.changed == 'true' - run: yarn build:mock + run: yarn turbo run build --filter=frontend + shell: bash + working-directory: . + env: + NEXT_PUBLIC_USE_MOCK_API: true + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_API: ${{ vars.TURBO_API }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} - name: Remove Next.js cache to avoid it being deployed - if: needs.changes.outputs.changed == 'true' run: rm -r .next/cache - name: Install netlify CLI - if: needs.changes.outputs.changed == 'true' run: "npm install -g netlify-cli@${{ env.NETLIFY_VERSION }}" - name: Run netlify CLI deployment - if: needs.changes.outputs.changed == 'true' env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} run: "netlify deploy --build --prod --message \"${{ github.event.head_commit.id }}: ${{ github.event.head_commit.message }}\"" diff --git a/.github/workflows/frontend-netlify-deploy-pr.yml b/.github/workflows/frontend-netlify-deploy-pr.yml index e83859eea..d43482506 100644 --- a/.github/workflows/frontend-netlify-deploy-pr.yml +++ b/.github/workflows/frontend-netlify-deploy-pr.yml @@ -28,7 +28,7 @@ permissions: env: NETLIFY_VERSION: 12.0.11 - NODE_VERSION: 18 + NODEJS_VERSION: 18 defaults: run: @@ -59,8 +59,8 @@ jobs: files: - 'commons/**' - 'frontend/**' - - '.github/**' - - '.yarn/**' + - 'yarn.lock' + - 'package.json' deploy: needs: changes @@ -80,7 +80,7 @@ jobs: if: needs.changes.outputs.changed == 'true' uses: ./.github/actions/setup-node with: - NODE_VERSION: ${{ env.NODE_VERSION }} + NODEJS_VERSION: ${{ env.NODEJS_VERSION }} - name: Patch intro.md to include netlify banner. if: needs.changes.outputs.changed == 'true' @@ -100,7 +100,14 @@ jobs: - name: Build app if: needs.changes.outputs.changed == 'true' - run: yarn build:mock + run: yarn turbo run build --filter=frontend + shell: bash + working-directory: . + env: + NEXT_PUBLIC_USE_MOCK_API: true + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_API: ${{ vars.TURBO_API }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} - name: Remove Next.js cache to avoid it being deployed if: needs.changes.outputs.changed == 'true' diff --git a/.github/workflows/frontend-test-and-build.yml b/.github/workflows/frontend-test-and-build.yml deleted file mode 100644 index 5c5ba3d76..000000000 --- a/.github/workflows/frontend-test-and-build.yml +++ /dev/null @@ -1,69 +0,0 @@ -# SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) -# -# SPDX-License-Identifier: AGPL-3.0-only - -name: Frontend / Run unit tests & build - -on: - push: - branches: [ develop ] - pull_request: - branches: [ develop ] - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-${{ github.job }} - cancel-in-progress: true - -defaults: - run: - working-directory: frontend - -jobs: - changes: - name: Check for frontend changes - runs-on: ubuntu-latest - permissions: - pull-requests: read - outputs: - changed: ${{ github.event_name == 'push' || steps.changed.outputs.files }} - steps: - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - if: github.event_name != 'push' - - - name: Check for frontend file changes - if: github.event_name != 'push' - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 - id: changed - with: - filters: | - files: - - 'commons/**' - - 'frontend/**' - - '.github/**' - - '.yarn/**' - - build: - needs: changes - runs-on: ubuntu-latest - strategy: - matrix: - node: [ '14', '16', '18' ] - name: Test and build with NodeJS ${{ matrix.node }} - steps: - - name: Checkout repository - if: needs.changes.outputs.changed == 'true' - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - - - name: Setup node - if: needs.changes.outputs.changed == 'true' - uses: ./.github/actions/setup-node - with: - NODE_VERSION: ${{ matrix.node }} - - - name: Test Project - if: needs.changes.outputs.changed == 'true' - run: yarn test:ci - - - name: Build project - if: needs.changes.outputs.changed == 'true' - run: yarn build:mock diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..f107104c2 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,36 @@ +# SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) +# +# SPDX-License-Identifier: AGPL-3.0-only + +name: Lint and check format + +on: + push: + branches: [ develop ] + pull_request: + branches: [ develop ] + +env: + NODEJS_VERSION: 18 + +jobs: + lint: + runs-on: ubuntu-latest + name: Lint files and check formatting + steps: + - name: Checkout repository + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 + + - name: Setup node + uses: ./.github/actions/setup-node + with: + NODEJS_VERSION: ${{ env.NODEJS_VERSION }} + + - name: Run ESLint + run: yarn turbo run lint + shell: bash + env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_API: ${{ vars.TURBO_API }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} + diff --git a/.github/workflows/njsscan-analysis.yml b/.github/workflows/njsscan-analysis.yml deleted file mode 100644 index dfcf75d30..000000000 --- a/.github/workflows/njsscan-analysis.yml +++ /dev/null @@ -1,31 +0,0 @@ -# SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) -# -# SPDX-License-Identifier: AGPL-3.0-only - -name: "Njsscan Analysis" - -on: - push: - branches: [ develop ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ develop ] - schedule: - - cron: '0 7 * * 6' - -jobs: - njsscan: - runs-on: ubuntu-latest - name: Njsscan code scanning - steps: - - name: Checkout the code - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 - - name: Scan with njsscan - id: njsscan - uses: ajinabraham/njsscan-action@d58d8b2f26322cd35a9efb8003baac517f226d81 # master - with: - args: '--sarif --output results.sarif src || true' - - name: Upload njsscan report - uses: github/codeql-action/upload-sarif@3ebbd71c74ef574dbc558c82f70e52732c8b44fe # v2.2.1 - with: - sarif_file: results.sarif diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 000000000..09bb20f73 --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,63 @@ +# SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) +# +# SPDX-License-Identifier: AGPL-3.0-only + +name: Static Analysis + +on: + push: + branches: [ develop ] + pull_request: + branches: [ develop ] + schedule: + - cron: '0 7 * * 6' + +permissions: + actions: read + contents: read + security-events: write + +jobs: + njsscan: + runs-on: ubuntu-latest + name: Njsscan code scanning + steps: + - name: Checkout the code + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 + - name: Scan with njsscan + id: njsscan + uses: ajinabraham/njsscan-action@d58d8b2f26322cd35a9efb8003baac517f226d81 # master + with: + args: '--sarif --output results.sarif src || true' + - name: Upload njsscan report + uses: github/codeql-action/upload-sarif@3ebbd71c74ef574dbc558c82f70e52732c8b44fe # v2.2.1 + with: + sarif_file: results.sarif + + codeql: + name: CodeQL analysis + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + language: [ 'javascript' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + + steps: + - name: Checkout repository + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 + + - name: Initialize CodeQL + uses: github/codeql-action/init@3ebbd71c74ef574dbc558c82f70e52732c8b44fe # v2.2.1 + with: + languages: ${{ matrix.language }} + queries: +security-and-quality + + - name: Autobuild + uses: github/codeql-action/autobuild@3ebbd71c74ef574dbc558c82f70e52732c8b44fe # v2.2.1 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@3ebbd71c74ef574dbc558c82f70e52732c8b44fe # v2.2.1 + with: + category: "/language:${{ matrix.language }}" diff --git a/.github/workflows/test-and-build.yml b/.github/workflows/test-and-build.yml new file mode 100644 index 000000000..da22b3f31 --- /dev/null +++ b/.github/workflows/test-and-build.yml @@ -0,0 +1,59 @@ +# SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) +# +# SPDX-License-Identifier: AGPL-3.0-only + +name: Run tests & build + +on: + push: + branches: [ develop ] + pull_request: + branches: [ develop ] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.job }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + node: [ '14', '16', '18' ] + include: + - node: '18' + coverage: true + name: Test and build with NodeJS ${{ matrix.node }} + steps: + - name: Checkout repository + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 + + - name: Setup node + uses: ./.github/actions/setup-node + with: + NODEJS_VERSION: ${{ matrix.node }} + + - name: Build project + run: yarn turbo run build + shell: bash + env: + NODEJS_VERSION: ${{ matrix.node }} + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_API: ${{ vars.TURBO_API }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} + + - name: Test Project + run: yarn turbo run test:ci + shell: bash + env: + NODEJS_VERSION: ${{ matrix.node }} + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_API: ${{ vars.TURBO_API }} + TURBO_TEAM: ${{ vars.TURBO_TEAM }} + + - name: Upload coverage + if: "${{ matrix.coverage == true }}" + uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + with: + directory: backend/coverage + flags: integration-tests diff --git a/.gitignore b/.gitignore index 4aea1742b..c61321176 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,8 @@ backups/ *.pid *.log *.sqlite +.turbo + # Yarn 2 without zero-installs .yarn/* diff --git a/.reuse/dep5 b/.reuse/dep5 index c3a90ac7a..9f213f084 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -91,6 +91,10 @@ Files: .yarnrc.yml Copyright: 2021 The HedgeDoc developers (see AUTHORS file) License: CC0-1.0 +Files: .turbo/config.json +Copyright: 2021 The HedgeDoc developers (see AUTHORS file) +License: CC0-1.0 + Files: frontend/.gitattributes Copyright: 2021 The HedgeDoc developers (see AUTHORS file) License: CC0-1.0 diff --git a/backend/.dockerignore b/backend/.dockerignore deleted file mode 100644 index 1e5cc4be3..000000000 --- a/backend/.dockerignore +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) -# -# SPDX-License-Identifier: CC0-1.0 - -dist -.pnp.* diff --git a/backend/docker/Dockerfile b/backend/docker/Dockerfile index 4406af56c..baaf328b4 100644 --- a/backend/docker/Dockerfile +++ b/backend/docker/Dockerfile @@ -14,58 +14,35 @@ FROM docker.io/node:19-alpine@sha256:72b0f918ad76b5ef68c6243869fab5800d7393c1dcc # Add tini to handle signals # https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#handling-kernel-signals RUN apk add --no-cache tini -ENTRYPOINT ["tini"] +ENTRYPOINT ["tini", "--"] ENV YARN_CACHE_FOLDER /tmp/.yarn -USER node -WORKDIR /usr/src/app ## Stage 1: Code with all dependencies FROM base as code-with-deps +RUN apk add --no-cache libc6-compat + USER node WORKDIR /usr/src/app -COPY --chown=node .yarn/plugins .yarn/plugins -COPY --chown=node .yarn/patches .yarn/patches -COPY --chown=node .yarn/releases .yarn/releases -COPY --chown=node .yarnrc.yml .yarnrc.yml -COPY --chown=node package.json package.json -COPY --chown=node yarn.lock yarn.lock -COPY --chown=node backend/package.json backend/ -COPY --chown=node commons/package.json commons/ -COPY --chown=node frontend/package.json frontend/ +COPY --chown=node . . # Install dependencies first to not invalidate the cache on every source change RUN --mount=type=cache,sharing=locked,uid=1000,gid=1000,target=/tmp/.yarn \ - yarn install --immutable && yarn workspaces focus @hedgedoc/backend + yarn install --immutable && yarn workspaces focus hedgedoc @hedgedoc/backend @hedgedoc/commons -COPY --chown=node commons/ commons/ -COPY --chown=node backend/nest-cli.json backend/tsconfig.json backend/tsconfig.build.json backend/ -COPY --chown=node backend/src backend/src - -WORKDIR /usr/src/app/commons - -RUN yarn build - -## Stage 2a: Dev config files and tests -FROM code-with-deps as development +## Stage 2a: Compile TypeScript +FROM code-with-deps as builder USER node WORKDIR /usr/src/app -COPY --chown=node eslint-local-rules.js eslint-local-rules.js -COPY --chown=node backend/.eslintrc.js backend/.prettierrc.json backend/jest-e2e.json backend/ -COPY --chown=node backend/test backend/test +ARG TURBO_TEAM +ARG TURBO_API +ARG TURBO_TOKEN -CMD ["node", "-r", "ts-node/register", "src/main.ts"] +RUN yarn turbo run build --filter=backend --no-cache --no-daemon -## Stage 2b: Compile TypeScript -FROM code-with-deps as builder -USER node -WORKDIR /usr/src/app/backend - -RUN yarn run build - -## Stage 3a: Install only prod dependencies +## Stage 2b: Install only prod dependencies FROM code-with-deps as prod-dependencies USER node WORKDIR /usr/src/app @@ -73,7 +50,7 @@ WORKDIR /usr/src/app RUN --mount=type=cache,sharing=locked,uid=1000,gid=1000,target=/tmp/.yarn \ yarn workspaces focus --production @hedgedoc/backend -## Stage 3a: Final image, only production dependencies +## Stage 3: Final image, only production dependencies FROM base as prod LABEL org.opencontainers.image.title='HedgeDoc production image' @@ -94,7 +71,7 @@ COPY --chown=node --from=builder /usr/src/app/backend/dist backend/dist COPY --chown=node backend/public backend/public COPY --chown=node commons/package.json /usr/src/app/commons/package.json -COPY --chown=node --from=prod-dependencies /usr/src/app/commons/dist commons/dist +COPY --chown=node --from=builder /usr/src/app/commons/dist commons/dist WORKDIR /usr/src/app/backend CMD ["node", "dist/main.js"] diff --git a/backend/package.json b/backend/package.json index 9ae018a73..3538b843d 100644 --- a/backend/package.json +++ b/backend/package.json @@ -17,10 +17,10 @@ "lint:fix": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "test": "jest", "test:watch": "jest --watch", - "test:cov": "jest --coverage", + "test:ci": "jest --coverage", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", "test:e2e": "jest --config jest-e2e.json && rimraf test_uploads*", - "test:e2e:cov": "jest --config jest-e2e.json --coverage && rimraf test_uploads*", + "test:e2e:ci": "jest --config jest-e2e.json --coverage && rimraf test_uploads*", "seed": "ts-node src/seed.ts" }, "dependencies": { diff --git a/commons/package.json b/commons/package.json index c5a38c261..e6d1a0dde 100644 --- a/commons/package.json +++ b/commons/package.json @@ -9,6 +9,7 @@ "build": "rm -rf dist && microbundle", "build:watch": "rm -rf dist && microbundle -w", "test": "jest", + "test:ci": "jest --ci", "prepublish": "rm -rf dist && yarn lint && yarn build && yarn test", "lint": "eslint src --ext .ts", "lint:fix": "eslint --fix --ext .ts src" diff --git a/dev-reverse-proxy/Caddyfile b/dev-reverse-proxy/Caddyfile index 7771ff52f..57f78361f 100644 --- a/dev-reverse-proxy/Caddyfile +++ b/dev-reverse-proxy/Caddyfile @@ -8,6 +8,8 @@ log { output stdout + level WARN + format console } reverse_proxy /realtime http://127.0.0.1:3000 diff --git a/dev-reverse-proxy/package.json b/dev-reverse-proxy/package.json new file mode 100644 index 000000000..4b555811a --- /dev/null +++ b/dev-reverse-proxy/package.json @@ -0,0 +1,9 @@ +{ + "name": "@hedgedoc/dev-reverse-proxy", + "version": "0.0.0", + "private": true, + "license": "AGPL-3.0", + "scripts": { + "start:dev": "./caddy run" + } +} diff --git a/frontend/.dockerignore.license b/dev-reverse-proxy/package.json.license similarity index 100% rename from frontend/.dockerignore.license rename to dev-reverse-proxy/package.json.license diff --git a/docs/content/dev/getting-started.md b/docs/content/dev/getting-started.md index dde939666..8b06a74af 100644 --- a/docs/content/dev/getting-started.md +++ b/docs/content/dev/getting-started.md @@ -14,32 +14,31 @@ To run HedgeDoc 2.0 you need three components: the backend, the frontend and the Backend and Frontend are included in the [HegdeDoc repo](https://github.com/hedgedoc/hedgedoc). The reverse proxy can be chosen by preference. For development, we recommend caddy and the provided configuration. -1. Install Node.js (at least Node 14, we recommend Node 18) and [Yarn](https://yarnpkg.com/getting-started/install) -2. Install Caddy (select one of the two options) +1. Clone [our repository](https://github.com/hedgedoc/hedgedoc.git) and go into its directory + ```shell + git clone https://github.com/hedgedoc/hedgedoc.git + cd hedgedoc + ``` +2. Install Node.js (at least Node 14, we recommend Node 18) and [Yarn](https://yarnpkg.com/getting-started/install) +3. Install Caddy (select one of the two options) - [Download](https://caddyserver.com/) and place the `caddy` binary in `hedgedoc/dev-reverse-proxy`. Ensure it is executable with `chmod +x caddy`. Users of macOS may need to run `xattr -d com.apple.quarantine ./caddy` to lift the quarantine for executables from the internet. - Install Caddy using your package manager -3. Clone [our repository](https://github.com/hedgedoc/hedgedoc.git) and go into its directory - ```shell - git clone https://github.com/hedgedoc/hedgedoc.git - cd hedgedoc - ``` 4. Install the dependencies in repo root directory with `yarn install` -5. Go to `hedgedoc/commons` directory with `cd ../commons` -6. Build the commons package with `yarn build` -7. Goto `hedgedoc/backend` directory with `cd ../backend` -8. Create the `.env` config file by copying the example: `cp .env.example .env` -9. Add a value to `HD_SESSION_SECRET` in the .env file. This can be any string, which has to be a secure password for production but can be set to simple string for debug purpose. -10. Execute the following lines - ```shell - echo "HD_AUTH_LOCAL_ENABLE_LOGIN=true" >> .env - echo "HD_AUTH_LOCAL_ENABLE_REGISTER=true" >> .env - ``` -11. Start the backend using `yarn start:dev` -12. Go to `hedgedoc/frontend` directory with `cd ../frontend` -13. Start the frontend using `yarn run dev:with-local-backend` -14. Go to `hedgedoc/dev-reverse-proxy` with `cd ../dev-reverse-proxy` -15. Start Caddy using `./caddy run` (if you've downloaded the binary manually) or `caddy run` (if you've installed Caddy using a package manager) -16. Use your browser to go to +5. Goto `hedgedoc/backend` directory with `cd backend` +6. Create the `.env` config file by copying the example: `cp .env.example .env` +7. Add a value to `HD_SESSION_SECRET` in the .env file. This can be any string, which has to be a secure password for production but can be set to simple string for debug purpose. +8. Execute the following lines + ```shell + echo "HD_AUTH_LOCAL_ENABLE_LOGIN=true" >> .env + echo "HD_AUTH_LOCAL_ENABLE_REGISTER=true" >> .env + ``` +9. Go back into the root directory with `cd ..` +10. Run `yarn start:dev` + > This will execute the backend, frontend and reverse proxy at once +11. Use your browser to go to + +## More detailed development setup +The following sections describe a more detailed setup of all components. ## Preconditions @@ -87,18 +86,19 @@ This only needs to be done once, except if you've changed code in the commons pa The frontend can be run in four different ways. The development mode compiles everything on demand. So the first time you open a page in the browser it may take some time. See [here](setup/frontend.md) for a more detailed description of the environment variables for the frontend. +A special configuration isn't necessary but keep in mind that you execute all commands from within the `frontend` directory. ### Mocked backend -To start the development mode, run `yarn run dev`. -By default, this will run in mock-mode, meaning instead of running a real backend the frontend mocks the backend. +To start the development mode, run `yarn start:dev:mock` . +This task will run the frontend in mock-mode, meaning instead of running a real backend, the frontend mocks the backend. This way you can work on frontend functionality without starting up the full development environment. The app should run now and be available under [http://localhost:3001](http://localhost:3001) in your browser. In development mode the app will autoload changes you make to the code. ### With local backend -To start the development mode with an actual HedgeDoc backend use `yarn run dev:with-local-backend` instead. +To start the development mode with an actual HedgeDoc backend use `yarn start:dev` instead. This task will automatically set `HD_BASE_URL` to `http://localhost:8080`. ### Production mode diff --git a/docs/content/dev/setup/frontend.md b/docs/content/dev/setup/frontend.md index 902c7e68c..6ed9cbb6a 100644 --- a/docs/content/dev/setup/frontend.md +++ b/docs/content/dev/setup/frontend.md @@ -39,7 +39,7 @@ Unit testing is done via jest. We use [cypress](https://cypress.io) for e2e tests. -1. Start the frontend with `yarn dev:test` (or use a test build using `yarn build:test` which you can start +1. Start the frontend with `yarn start:dev:test` (or use a test build using `yarn build:test` which you can start using `yarn start`). The usage of `:test` is mandatory! 2. Run `yarn cy:open` to open the cypress test loader 3. Choose your browser and start a test suite diff --git a/frontend/.dockerignore b/frontend/.dockerignore deleted file mode 100644 index c5500558b..000000000 --- a/frontend/.dockerignore +++ /dev/null @@ -1,7 +0,0 @@ -Dockerfile -.dockerignore -node_modules -npm-debug.log -README.md -.next -.git diff --git a/frontend/.env.development b/frontend/.env.development index 86efdca8a..bbf018688 100644 --- a/frontend/.env.development +++ b/frontend/.env.development @@ -1,3 +1,2 @@ -NEXT_PUBLIC_USE_MOCK_API=true -HD_BASE_URL="http://localhost:3001/" -HD_RENDERER_BASE_URL="http://127.0.0.1:3001/" +HD_BASE_URL="http://localhost:8080/" +HD_RENDERER_BASE_URL="http://127.0.0.1:8080/" diff --git a/frontend/docker/Dockerfile b/frontend/docker/Dockerfile index 2010b4a7b..1a6f0dc7f 100644 --- a/frontend/docker/Dockerfile +++ b/frontend/docker/Dockerfile @@ -2,8 +2,15 @@ # # SPDX-License-Identifier: CC-BY-SA-4.0 +# BASE +FROM docker.io/node:18-alpine@sha256:bc329c7332cffc30c2d4801e38df03cbfa8dcbae2a7a52a449db104794f168a3 AS base +RUN apk add --no-cache tini +ENTRYPOINT ["tini", "--"] + # BUILD -FROM docker.io/node:18-alpine@sha256:bc329c7332cffc30c2d4801e38df03cbfa8dcbae2a7a52a449db104794f168a3 AS builder +FROM base AS builder + +RUN apk add --no-cache libc6-compat ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 ARG BUILD_VERSION=CLIENT_VERSION_MISSING @@ -12,31 +19,21 @@ ENV YARN_CACHE_FOLDER /tmp/.yarn USER node WORKDIR /usr/src/app -COPY --chown=node .yarn/plugins .yarn/plugins -COPY --chown=node .yarn/patches .yarn/patches -COPY --chown=node .yarn/releases .yarn/releases -COPY --chown=node .yarnrc.yml .yarnrc.yml -COPY --chown=node package.json package.json -COPY --chown=node yarn.lock yarn.lock -COPY --chown=node backend/package.json backend/ -COPY --chown=node commons commons -COPY --chown=node frontend frontend +COPY --chown=node . . RUN --mount=type=cache,sharing=locked,uid=1000,gid=1000,target=/tmp/.yarn \ - yarn install --immutable && yarn workspaces focus @hedgedoc/frontend + yarn install --immutable && yarn workspaces focus hedgedoc @hedgedoc/backend @hedgedoc/commons -WORKDIR /usr/src/app/commons +ARG TURBO_TEAM +ARG TURBO_API +ARG TURBO_TOKEN -RUN yarn build - -WORKDIR /usr/src/app/frontend - -RUN rm -rf public/public && \ - rm -rf src/pages/api && \ - sed -i "s/CLIENT_VERSION_MISSING/${BUILD_VERSION}/" src/version.json -RUN yarn build +RUN rm -rf frontend/public/public +RUN rm -rf frontend/src/pages/api +RUN sed -i "s/CLIENT_VERSION_MISSING/${BUILD_VERSION}/" frontend/src/version.json +RUN yarn turbo run build --filter=frontend --no-cache --no-daemon # RUNNER -FROM docker.io/node:18-alpine@sha256:bc329c7332cffc30c2d4801e38df03cbfa8dcbae2a7a52a449db104794f168a3 +FROM base ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 diff --git a/frontend/package.json b/frontend/package.json index ddabde8d2..a6f87351c 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -8,20 +8,21 @@ "build:mock": "cross-env NEXT_PUBLIC_USE_MOCK_API=true next build", "build:test": "cross-env NODE_ENV=test NEXT_PUBLIC_TEST_MODE=true next build", "analyze": "cross-env ANALYZE=true yarn build", - "dev": "cross-env PORT=3001 next dev", - "dev:test": "cross-env PORT=3001 NODE_ENV=test NEXT_PUBLIC_TEST_MODE=true next dev", - "dev:with-local-backend": "cross-env PORT=3001 NEXT_PUBLIC_USE_MOCK_API=false HD_BASE_URL=http://localhost:8080/ HD_RENDERER_BASE_URL=http://localhost:8080/ next dev", "format": "prettier -c \"src/**/*.{ts,tsx,js}\" \"cypress/**/*.{ts,tsx}\"", "format:fix": "prettier -w \"src/**/*.{ts,tsx,js}\" \"cypress/**/*.{ts,tsx}\"", "lint": "eslint --max-warnings=0 --ext .ts,.tsx src", "lint:fix": "eslint --fix --ext .ts,.tsx src", "start": "cross-env PORT=3001 next start", - "start:ci": "cross-env NODE_ENV=test PORT=3001 next start", - "cy:open": "cypress open", - "cy:run:chrome": "cypress run --browser chrome", - "cy:run:firefox": "cypress run --browser firefox", - "test": "cross-env NODE_ENV=test jest --watch", - "test:ci": "cross-env NODE_ENV=test jest --ci" + "start:ci": "cross-env PORT=3001 NODE_ENV=test next start", + "start:dev": "cross-env PORT=3001 next dev", + "start:dev:mock": "cross-env PORT=3001 NEXT_PUBLIC_USE_MOCK_API=true HD_BASE_URL=\"http://localhost:3001/\" HD_RENDERER_BASE_URL=\"http://127.0.0.1:3001/\" next dev", + "start:dev:test": "cross-env PORT=3001 NODE_ENV=test NEXT_PUBLIC_TEST_MODE=true next dev", + "test:e2e:open": "cypress open", + "test:e2e": "cypress run --browser chrome", + "test:e2e:ci": "cypress run --browser chrome --record true --parallel --group \"chrome\"", + "test:watch": "cross-env NODE_ENV=test jest --watch", + "test:ci": "cross-env NODE_ENV=test jest --ci", + "test": "cross-env NODE_ENV=test jest" }, "browserslist": { "production": [ diff --git a/package.json b/package.json index 711fcebfe..1f0d0f831 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,15 @@ "workspaces": [ "backend", "frontend", - "commons" + "commons", + "dev-reverse-proxy" ], + "scripts": { + "build": "turbo run build", + "lint": "turbo run lint", + "format": "turbo run format", + "start:dev": "turbo run start:dev" + }, "packageManager": "yarn@3.4.1", "resolutions": { "domhandler": "5.0.3", @@ -22,5 +29,8 @@ "@types/react": "18.0.27", "y-protocols@^1.0.0": "patch:y-protocols@npm%3A1.0.5#./.yarn/patches/y-protocols-npm-1.0.5-af6f64b4df.patch", "y-protocols@1.0.5": "patch:y-protocols@npm%3A1.0.5#./.yarn/patches/y-protocols-npm-1.0.5-af6f64b4df.patch" + }, + "devDependencies": { + "turbo": "1.6.3" } } diff --git a/renovate.json b/renovate.json index c7e39b3c6..aad33b4c3 100644 --- a/renovate.json +++ b/renovate.json @@ -95,7 +95,7 @@ ".github/workflows/deploy-pr.yml$" ], "matchStrings": [ - "NODE_VERSION=(?.*?)\\n" + "NODEJS_VERSION=(?.*?)\\n" ], "datasourceTemplate": "node", "depNameTemplate": "node version in workflows" diff --git a/turbo.json b/turbo.json new file mode 100644 index 000000000..5ac9c8425 --- /dev/null +++ b/turbo.json @@ -0,0 +1,108 @@ +{ + "$schema": "https://turbo.build/schema.json", + "pipeline": { + "build": {}, + "@hedgedoc/commons#build": { + "dependsOn": [ + "^build" + ], + "outputs": [ + "dist/**" + ] + }, + "@hedgedoc/frontend#build": { + "dependsOn": [ + "^build" + ], + "outputs": [ + ".next/**" + ], + "env": [ + "NODEJS_VERSION" + ] + }, + "@hedgedoc/backend#build": { + "dependsOn": [ + "^build" + ], + "outputs": [ + "dist/**" + ], + "env": [ + "NODEJS_VERSION" + ] + }, + + "build:test": {}, + "@hedgedoc/frontend#build:test": { + "dependsOn": [ + "^build" + ], + "outputs": [ + ".next/**" + ], + "env": [ + "NODEJS_VERSION" + ] + }, + + "lint": { + "dependsOn": [ + "^build" + ] + }, + + "format": {}, + + "test:ci": {}, + "@hedgedoc/backend#test:ci": { + "dependsOn": [ + "^build" + ], + "env": [ + "NODEJS_VERSION" + ], + "outputs": [ + "coverage/**" + ] + }, + "@hedgedoc/frontend#test:ci": { + "dependsOn": [ + "^build" + ], + "env": [ + "NODEJS_VERSION" + ] + }, + + "test:e2e:ci": {}, + "@hedgedoc/frontend#test:e2e:ci": { + "dependsOn": [ + "^build" + ], + "env": [ + "CYPRESS_CONTAINER_ID" + ] + }, + "@hedgedoc/backend#test:e2e:ci": { + "dependsOn": [ + "^build" + ], + "env": [ + "HEDGEDOC_TEST_DB_TYPE" + ], + "outputs": [ + "coverage-e2e/**" + ] + }, + + "start:dev": { + "dependsOn": [ + "^build" + ], + "cache": false, + "persistent": true + } + } +} + diff --git a/frontend/renovate.json.license b/turbo.json.license similarity index 100% rename from frontend/renovate.json.license rename to turbo.json.license diff --git a/yarn.lock b/yarn.lock index ee69ec009..dbe7199bb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2310,6 +2310,12 @@ __metadata: languageName: unknown linkType: soft +"@hedgedoc/dev-reverse-proxy@workspace:dev-reverse-proxy": + version: 0.0.0-use.local + resolution: "@hedgedoc/dev-reverse-proxy@workspace:dev-reverse-proxy" + languageName: unknown + linkType: soft + "@hedgedoc/frontend@workspace:frontend": version: 0.0.0-use.local resolution: "@hedgedoc/frontend@workspace:frontend" @@ -10429,6 +10435,8 @@ __metadata: "hedgedoc@workspace:.": version: 0.0.0-use.local resolution: "hedgedoc@workspace:." + dependencies: + turbo: 1.6.3 languageName: unknown linkType: soft @@ -17334,6 +17342,77 @@ __metadata: languageName: node linkType: hard +"turbo-darwin-64@npm:1.6.3": + version: 1.6.3 + resolution: "turbo-darwin-64@npm:1.6.3" + conditions: os=darwin & cpu=x64 + languageName: node + linkType: hard + +"turbo-darwin-arm64@npm:1.6.3": + version: 1.6.3 + resolution: "turbo-darwin-arm64@npm:1.6.3" + conditions: os=darwin & cpu=arm64 + languageName: node + linkType: hard + +"turbo-linux-64@npm:1.6.3": + version: 1.6.3 + resolution: "turbo-linux-64@npm:1.6.3" + conditions: os=linux & cpu=x64 + languageName: node + linkType: hard + +"turbo-linux-arm64@npm:1.6.3": + version: 1.6.3 + resolution: "turbo-linux-arm64@npm:1.6.3" + conditions: os=linux & cpu=arm64 + languageName: node + linkType: hard + +"turbo-windows-64@npm:1.6.3": + version: 1.6.3 + resolution: "turbo-windows-64@npm:1.6.3" + conditions: os=win32 & cpu=x64 + languageName: node + linkType: hard + +"turbo-windows-arm64@npm:1.6.3": + version: 1.6.3 + resolution: "turbo-windows-arm64@npm:1.6.3" + conditions: os=win32 & cpu=arm64 + languageName: node + linkType: hard + +"turbo@npm:1.6.3": + version: 1.6.3 + resolution: "turbo@npm:1.6.3" + dependencies: + turbo-darwin-64: 1.6.3 + turbo-darwin-arm64: 1.6.3 + turbo-linux-64: 1.6.3 + turbo-linux-arm64: 1.6.3 + turbo-windows-64: 1.6.3 + turbo-windows-arm64: 1.6.3 + dependenciesMeta: + turbo-darwin-64: + optional: true + turbo-darwin-arm64: + optional: true + turbo-linux-64: + optional: true + turbo-linux-arm64: + optional: true + turbo-windows-64: + optional: true + turbo-windows-arm64: + optional: true + bin: + turbo: bin/turbo + checksum: 35195f4b7623014c25ba152c11a8cb23e51cbd75dc9266d0656692665f85b28faf3496dea8cecacf52795a917410668124186ffbdcf276325ccc3e11df9e9623 + languageName: node + linkType: hard + "tweetnacl@npm:^0.14.3, tweetnacl@npm:~0.14.0": version: 0.14.5 resolution: "tweetnacl@npm:0.14.5"