From 9db45b74b86b7fe9d3d48196df7e03289460714e Mon Sep 17 00:00:00 2001 From: Tilman Vatteroth Date: Fri, 11 Nov 2022 10:55:08 +0100 Subject: [PATCH] fix(frontend): adjust workflows Signed-off-by: Tilman Vatteroth --- .github/workflows/frontend-docker.yml | 40 ++++++++- .github/workflows/frontend-e2e-tests.yml | 86 ++++++++++++++----- .github/workflows/frontend-lint.yml | 39 ++++++++- .../frontend-netlify-deploy-main.yml | 48 ++++++++++- .../workflows/frontend-netlify-deploy-pr.yml | 55 ++++++++++-- .github/workflows/frontend-test-and-build.yml | 40 ++++++++- 6 files changed, 267 insertions(+), 41 deletions(-) diff --git a/.github/workflows/frontend-docker.yml b/.github/workflows/frontend-docker.yml index 4124e0eff..f9cebd0d2 100644 --- a/.github/workflows/frontend-docker.yml +++ b/.github/workflows/frontend-docker.yml @@ -2,17 +2,45 @@ # # SPDX-License-Identifier: AGPL-3.0-only -name: Build Docker Image +name: Frontend / build docker image on: push: - branches: [ main ] + branches: [ develop ] + +defaults: + run: + working-directory: frontend + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: + changes: + name: Check for frontend changes + runs-on: ubuntu-latest + permissions: + pull-requests: read + outputs: + changed: ${{ steps.changed.outputs.files }} + steps: + - name: Check for frontend file changes + uses: dorny/paths-filter@v2 + id: changed + with: + filters: | + files: + - 'frontend/**' + - '.github/**' + - '.yarn/**' + build: + needs: changes runs-on: ubuntu-latest steps: - name: Generate Docker metadata + if: needs.changes.outputs.changed == 'true' id: meta uses: docker/metadata-action@v4 with: @@ -24,13 +52,15 @@ jobs: type=semver,pattern={{major}} - name: Set up QEMU + if: needs.changes.outputs.changed == 'true' uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx + if: needs.changes.outputs.changed == 'true' uses: docker/setup-buildx-action@v2 - name: Login to GHCR - if: github.event_name != 'pull_request' + if: github.event_name != 'pull_request' && needs.changes.outputs.changed == 'true' uses: docker/login-action@v2 with: registry: ghcr.io @@ -38,13 +68,15 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push + if: needs.changes.outputs.changed == 'true' uses: docker/build-push-action@v3 with: push: true - file: Dockerfile + file: frontend/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 index e743a8d8a..bcb85ac0b 100644 --- a/.github/workflows/frontend-e2e-tests.yml +++ b/.github/workflows/frontend-e2e-tests.yml @@ -2,15 +2,15 @@ # # SPDX-License-Identifier: AGPL-3.0-only -name: e2e +name: Frontend / Run E2E Tests on: push: - branches: [ main ] + branches: [ develop ] pull_request_target: - branches: [ main ] + branches: [ develop ] pull_request: - branches: [ main ] + branches: [ develop ] permissions: contents: read @@ -19,64 +19,99 @@ 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.ref }} + cancel-in-progress: true + jobs: + changes: + name: Check for frontend changes + runs-on: ubuntu-latest + permissions: + pull-requests: read + outputs: + changed: ${{ steps.changed.outputs.files }} + steps: + - name: Check for frontend file changes + uses: dorny/paths-filter@v2 + id: changed + with: + filters: | + files: + - '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@v3 with: ref: ${{ env.HEAD_COMMIT_HASH }} - name: Cache build + if: needs.changes.outputs.changed == 'true' uses: actions/cache@v3.0.11 id: build-cache with: - path: .next + path: frontend/.next key: ${{ env.HEAD_COMMIT_HASH }} - name: Get yarn cache directory path id: yarn-cache-dir-path - if: steps.build-cache.outputs.cache-hit != 'true' + if: steps.build-cache.outputs.cache-hit != 'true' && needs.changes.outputs.changed == 'true' run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT - name: Cache yarn cache uses: actions/cache@v3 id: yarn-cache - if: steps.build-cache.outputs.cache-hit != 'true' + if: steps.build-cache.outputs.cache-hit != 'true' && needs.changes.outputs.changed == 'true' with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-${{ env.NODE_VERSION }}-yarn-${{ hashFiles('**/yarn.lock') }} + 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' + if: steps.build-cache.outputs.cache-hit != 'true' && needs.changes.outputs.changed == 'true' uses: actions/setup-node@v3 with: node-version: ${{ env.NODE_VERSION }} + cache-dependency-path: frontend/yarn.lock + cache: 'yarn' - name: Install dependencies - if: steps.build-cache.outputs.cache-hit != 'true' + if: steps.build-cache.outputs.cache-hit != 'true' && needs.changes.outputs.changed == 'true' run: yarn install --immutable - name: Build test production build - if: steps.build-cache.outputs.cache-hit != 'true' + if: steps.build-cache.outputs.cache-hit != 'true' && needs.changes.outputs.changed == 'true' run: yarn build:test - uses: actions/upload-artifact@master + if: needs.changes.outputs.changed == 'true' with: + retention-days: 1 name: e2e-build path: | - .next - !.next/cache - !.next/standalone + frontend/.next + !frontend/.next/cache + !frontend/.next/standalone end2end: name: Perform E2E Test in ${{ matrix.browser }} - needs: build-frontend + needs: + - build-frontend + - changes runs-on: ubuntu-latest container: image: cypress/browsers:node18.12.0-chrome106-ff106 @@ -88,59 +123,70 @@ jobs: containers: [ 1, 2, 3, 4, 5 ] steps: - name: Check out repo + if: needs.changes.outputs.changed == 'true' uses: actions/checkout@v3 - name: Cache build + if: needs.changes.outputs.changed == 'true' uses: actions/cache@v3.0.11 id: build-cache with: - path: .next + 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@v3 id: yarn-cache with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-${{ env.NODE_VERSION }}-yarn-${{ hashFiles('**/yarn.lock') }} + 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' + if: steps.build-cache.outputs.cache-hit != 'true' && needs.changes.outputs.changed == 'true' uses: actions/setup-node@v3 with: node-version: ${{ env.NODE_VERSION }} + cache-dependency-path: frontend/yarn.lock + cache: 'yarn' - 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@master with: name: e2e-build - path: .next + 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@master - if: always() + 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 index 7621269bc..41e4dee95 100644 --- a/.github/workflows/frontend-lint.yml +++ b/.github/workflows/frontend-lint.yml @@ -2,45 +2,76 @@ # # SPDX-License-Identifier: AGPL-3.0-only -name: lint +name: Frontend / Lint on: push: - branches: [ main ] + branches: [ develop ] pull_request: - branches: [ main ] + 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: ${{ steps.changed.outputs.files }} + steps: + - name: Check for frontend file changes + uses: dorny/paths-filter@v2 + id: changed + with: + filters: | + files: + - '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@v3 - 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@v3 id: yarn-cache with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-${{ env.NODE_VERSION }}-yarn-${{ hashFiles('**/yarn.lock') }} + key: ${{ runner.os }}-${{ env.NODE_VERSION }}-yarn-${{ hashFiles('frontend/yarn.lock') }} restore-keys: | ${{ runner.os }}-yarn-${{ env.NODE_VERSION }} - name: Set up NodeJS + if: needs.changes.outputs.changed == 'true' uses: actions/setup-node@v3 with: node-version: ${{ env.NODE_VERSION }} + cache-dependency-path: frontend/yarn.lock + cache: 'yarn' - name: Install dependencies + if: needs.changes.outputs.changed == 'true' run: yarn install --immutable - 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 d782d0173..8af843cc9 100644 --- a/.github/workflows/frontend-netlify-deploy-main.yml +++ b/.github/workflows/frontend-netlify-deploy-main.yml @@ -2,67 +2,109 @@ # # SPDX-License-Identifier: AGPL-3.0-only -name: deploy +name: Frontend / Deploy develop branch to Netlify on: push: - branches: [ main ] + branches: [ develop ] env: NETLIFY_VERSION: 12.0.11 NODE_VERSION: 18 +defaults: + run: + working-directory: frontend + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: + changes: + name: Check for frontend changes + runs-on: ubuntu-latest + permissions: + pull-requests: read + outputs: + changed: ${{ steps.changed.outputs.files }} + steps: + - name: Check for frontend file changes + uses: dorny/paths-filter@v2 + id: changed + with: + filters: | + files: + - '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@v3 - 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@v3 id: yarn-cache with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-${{ env.NODE_VERSION }}-yarn-${{ hashFiles('**/yarn.lock') }} + key: ${{ runner.os }}-${{ env.NODE_VERSION }}-yarn-${{ hashFiles('frontend/yarn.lock') }} restore-keys: | ${{ runner.os }}-yarn-${{ env.NODE_VERSION }} - name: Set up NodeJS + if: needs.changes.outputs.changed == 'true' uses: actions/setup-node@v3 with: node-version: ${{ env.NODE_VERSION }} + cache-dependency-path: frontend/yarn.lock + cache: 'yarn' - 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_EDITOR_BASE_URL=\"https://hedgedoc.dev/\"" >> .env.production - name: Install dependencies + if: needs.changes.outputs.changed == 'true' run: yarn install --immutable - name: Build app + if: needs.changes.outputs.changed == 'true' run: yarn build:mock - 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 e74fa9018..d88cc1635 100644 --- a/.github/workflows/frontend-netlify-deploy-pr.yml +++ b/.github/workflows/frontend-netlify-deploy-pr.yml @@ -2,11 +2,11 @@ # # SPDX-License-Identifier: AGPL-3.0-only -name: deploy +name: Frontend / Deploy PR to Netlify on: pull_request: - branches: [ main ] + branches: [ develop ] types: - labeled - opened @@ -14,7 +14,7 @@ on: - reopened - ready_for_review pull_request_target: - branches: [ main ] + branches: [ develop ] types: - labeled - opened @@ -30,59 +30,100 @@ env: NETLIFY_VERSION: 12.0.11 NODE_VERSION: 18 +defaults: + run: + working-directory: frontend + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: + changes: + name: Check for frontend changes + runs-on: ubuntu-latest + permissions: + pull-requests: read + outputs: + changed: ${{ steps.changed.outputs.files }} + steps: + - name: Check for frontend file changes + uses: dorny/paths-filter@v2 + id: changed + with: + filters: | + files: + - 'frontend/**' + - '.github/**' + - '.yarn/**' + deploy: - if: (github.event.pull_request.draft == false || contains( github.event.pull_request.labels.*.name, 'FORCE DEPLOY')) && (github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork + needs: changes + if: "github.event.pull_request.draft == false || contains( github.event.pull_request.labels.*.name, 'ci: force deployment') && (github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork" runs-on: ubuntu-latest name: Deploys to netlify env: DEPLOY_URL: "https://${{ github.event.number }}--hedgedoc-ui-test.netlify.app/" steps: - name: Checkout repository + if: needs.changes.outputs.changed == 'true' uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.sha }} - 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@v3 id: yarn-cache with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-${{ env.NODE_VERSION }}-yarn-${{ hashFiles('**/yarn.lock') }} + key: ${{ runner.os }}-${{ env.NODE_VERSION }}-yarn-${{ hashFiles('frontend/yarn.lock') }} restore-keys: | ${{ runner.os }}-yarn-${{ env.NODE_VERSION }} - name: Set up NodeJS + if: needs.changes.outputs.changed == 'true' uses: actions/setup-node@v3 with: node-version: ${{ env.NODE_VERSION }} + cache-dependency-path: frontend/yarn.lock + cache: 'yarn' - 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_EDITOR_BASE_URL=\"${{ env.DEPLOY_URL }}\"" >> .env.production - name: Install dependencies + if: needs.changes.outputs.changed == 'true' run: yarn install --immutable - name: Build app + if: needs.changes.outputs.changed == 'true' run: yarn build:mock - name: Remove Next.js cache to avoid it being deployed + if: needs.changes.outputs.changed == 'true' run: rm -r .next/cache - name: Mark GitHub deployment as started + if: needs.changes.outputs.changed == 'true' uses: bobheadxi/deployments@v1.3.0 id: github-deployment with: @@ -93,15 +134,17 @@ jobs: ref: ${{ github.head_ref }} - name: Install netlify CLI + if: needs.changes.outputs.changed == 'true' run: "npm install -g netlify-cli@${{ env.NETLIFY_VERSION }}" - name: Run netlify CLI + if: needs.changes.outputs.changed == 'true' env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} run: "netlify deploy --build --context deploy-preview --alias \"${{ github.event.number }}\" --json --message \"PR #${{ github.event.number }}\"" - name: Mark GitHub deployment as finished - if: always() + if: needs.changes.outputs.changed == 'true' uses: bobheadxi/deployments@v1.3.0 with: step: finish diff --git a/.github/workflows/frontend-test-and-build.yml b/.github/workflows/frontend-test-and-build.yml index b207b9a28..82134302a 100644 --- a/.github/workflows/frontend-test-and-build.yml +++ b/.github/workflows/frontend-test-and-build.yml @@ -2,16 +2,39 @@ # # SPDX-License-Identifier: AGPL-3.0-only -name: test, build +name: Frontend / Run unit tests & build on: push: - branches: [ main ] + branches: [ develop ] pull_request: - branches: [ main ] + branches: [ develop ] + +defaults: + run: + working-directory: frontend jobs: + changes: + name: Check for frontend changes + runs-on: ubuntu-latest + permissions: + pull-requests: read + outputs: + changed: ${{ steps.changed.outputs.files }} + steps: + - name: Check for frontend file changes + uses: dorny/paths-filter@v2 + id: changed + with: + filters: | + files: + - 'frontend/**' + - '.github/**' + - '.yarn/**' + build: + needs: changes runs-on: ubuntu-latest strategy: matrix: @@ -19,31 +42,40 @@ jobs: name: Test and build with NodeJS ${{ matrix.node }} steps: - name: Checkout repository + if: needs.changes.outputs.changed == 'true' uses: actions/checkout@v3 - 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@v3 id: yarn-cache with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-${{ matrix.node }}-yarn-${{ hashFiles('**/yarn.lock') }} + key: ${{ runner.os }}-${{ matrix.node }}-yarn-${{ hashFiles('frontend/yarn.lock') }} restore-keys: | ${{ runner.os }}-yarn-${{ matrix.node }} - name: Set up NodeJS + if: needs.changes.outputs.changed == 'true' uses: actions/setup-node@v3 with: node-version: ${{ matrix.node }} + cache-dependency-path: frontend/yarn.lock + cache: 'yarn' - name: Install dependencies + if: needs.changes.outputs.changed == 'true' run: yarn install --immutable - 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