fix(frontend): adjust workflows

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2022-11-11 10:55:08 +01:00
parent 31e4ab5e37
commit 9db45b74b8
No known key found for this signature in database
GPG key ID: B97799103358209B
6 changed files with 267 additions and 41 deletions

View file

@ -2,17 +2,45 @@
# #
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
name: Build Docker Image name: Frontend / build docker image
on: on:
push: push:
branches: [ main ] branches: [ develop ]
defaults:
run:
working-directory: frontend
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs: 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: build:
needs: changes
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Generate Docker metadata - name: Generate Docker metadata
if: needs.changes.outputs.changed == 'true'
id: meta id: meta
uses: docker/metadata-action@v4 uses: docker/metadata-action@v4
with: with:
@ -24,13 +52,15 @@ jobs:
type=semver,pattern={{major}} type=semver,pattern={{major}}
- name: Set up QEMU - name: Set up QEMU
if: needs.changes.outputs.changed == 'true'
uses: docker/setup-qemu-action@v2 uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx - name: Set up Docker Buildx
if: needs.changes.outputs.changed == 'true'
uses: docker/setup-buildx-action@v2 uses: docker/setup-buildx-action@v2
- name: Login to GHCR - 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 uses: docker/login-action@v2
with: with:
registry: ghcr.io registry: ghcr.io
@ -38,13 +68,15 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push - name: Build and push
if: needs.changes.outputs.changed == 'true'
uses: docker/build-push-action@v3 uses: docker/build-push-action@v3
with: with:
push: true push: true
file: Dockerfile file: frontend/Dockerfile
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha cache-from: type=gha
cache-to: type=gha,mode=max cache-to: type=gha,mode=max
context: .
build-args: | build-args: |
BUILD_VERSION=${{ github.event.head_commit.id }} BUILD_VERSION=${{ github.event.head_commit.id }}

View file

@ -2,15 +2,15 @@
# #
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
name: e2e name: Frontend / Run E2E Tests
on: on:
push: push:
branches: [ main ] branches: [ develop ]
pull_request_target: pull_request_target:
branches: [ main ] branches: [ develop ]
pull_request: pull_request:
branches: [ main ] branches: [ develop ]
permissions: permissions:
contents: read contents: read
@ -19,64 +19,99 @@ env:
NODE_VERSION: 18 NODE_VERSION: 18
HEAD_COMMIT_HASH: "${{ !!github.event.pull_request && github.event.pull_request.head.sha || github.sha }}" 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: 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: build-frontend:
needs: changes
if: "${{ (github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork }}" if: "${{ (github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork }}"
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: Build test build of frontend name: Build test build of frontend
steps: steps:
- name: Check out repo - name: Check out repo
if: needs.changes.outputs.changed == 'true'
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
ref: ${{ env.HEAD_COMMIT_HASH }} ref: ${{ env.HEAD_COMMIT_HASH }}
- name: Cache build - name: Cache build
if: needs.changes.outputs.changed == 'true'
uses: actions/cache@v3.0.11 uses: actions/cache@v3.0.11
id: build-cache id: build-cache
with: with:
path: .next path: frontend/.next
key: ${{ env.HEAD_COMMIT_HASH }} key: ${{ env.HEAD_COMMIT_HASH }}
- name: Get yarn cache directory path - name: Get yarn cache directory path
id: yarn-cache-dir-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 run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Cache yarn cache - name: Cache yarn cache
uses: actions/cache@v3 uses: actions/cache@v3
id: yarn-cache 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: with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} 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: | restore-keys: |
${{ runner.os }}-yarn-${{ env.NODE_VERSION }} ${{ runner.os }}-yarn-${{ env.NODE_VERSION }}
- name: Set up NodeJS - 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 uses: actions/setup-node@v3
with: with:
node-version: ${{ env.NODE_VERSION }} node-version: ${{ env.NODE_VERSION }}
cache-dependency-path: frontend/yarn.lock
cache: 'yarn'
- name: Install dependencies - 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 run: yarn install --immutable
- name: Build test production build - 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 run: yarn build:test
- uses: actions/upload-artifact@master - uses: actions/upload-artifact@master
if: needs.changes.outputs.changed == 'true'
with: with:
retention-days: 1
name: e2e-build name: e2e-build
path: | path: |
.next frontend/.next
!.next/cache !frontend/.next/cache
!.next/standalone !frontend/.next/standalone
end2end: end2end:
name: Perform E2E Test in ${{ matrix.browser }} name: Perform E2E Test in ${{ matrix.browser }}
needs: build-frontend needs:
- build-frontend
- changes
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: container:
image: cypress/browsers:node18.12.0-chrome106-ff106 image: cypress/browsers:node18.12.0-chrome106-ff106
@ -88,59 +123,70 @@ jobs:
containers: [ 1, 2, 3, 4, 5 ] containers: [ 1, 2, 3, 4, 5 ]
steps: steps:
- name: Check out repo - name: Check out repo
if: needs.changes.outputs.changed == 'true'
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Cache build - name: Cache build
if: needs.changes.outputs.changed == 'true'
uses: actions/cache@v3.0.11 uses: actions/cache@v3.0.11
id: build-cache id: build-cache
with: with:
path: .next path: frontend/.next
key: ${{ env.HEAD_COMMIT_HASH }} key: ${{ env.HEAD_COMMIT_HASH }}
- name: Get yarn cache directory path - name: Get yarn cache directory path
if: needs.changes.outputs.changed == 'true'
id: yarn-cache-dir-path id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Cache yarn cache - name: Cache yarn cache
if: needs.changes.outputs.changed == 'true'
uses: actions/cache@v3 uses: actions/cache@v3
id: yarn-cache id: yarn-cache
with: with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} 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: | restore-keys: |
${{ runner.os }}-yarn-${{ env.NODE_VERSION }} ${{ runner.os }}-yarn-${{ env.NODE_VERSION }}
- name: Set up NodeJS - 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 uses: actions/setup-node@v3
with: with:
node-version: ${{ env.NODE_VERSION }} node-version: ${{ env.NODE_VERSION }}
cache-dependency-path: frontend/yarn.lock
cache: 'yarn'
- name: Install dependencies - name: Install dependencies
if: needs.changes.outputs.changed == 'true'
run: yarn install --immutable run: yarn install --immutable
- name: Download built frontend - name: Download built frontend
if: needs.changes.outputs.changed == 'true'
uses: actions/download-artifact@master uses: actions/download-artifact@master
with: with:
name: e2e-build name: e2e-build
path: .next path: frontend/.next
- name: Run server - name: Run server
if: needs.changes.outputs.changed == 'true'
run: yarn start:ci & run: yarn start:ci &
env: env:
NODE_ENV: test NODE_ENV: test
- name: Wait for server - name: Wait for server
if: needs.changes.outputs.changed == 'true'
run: "sleep 3 && curl --max-time 120 http://127.0.0.1:3001/" run: "sleep 3 && curl --max-time 120 http://127.0.0.1:3001/"
- name: Run cypress - name: Run cypress
if: needs.changes.outputs.changed == 'true'
run: "yarn cy:run:${{ matrix.browser }} --record true --parallel --group \"UI - ${{ matrix.browser }}\"" run: "yarn cy:run:${{ matrix.browser }} --record true --parallel --group \"UI - ${{ matrix.browser }}\""
env: env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/upload-artifact@master - uses: actions/upload-artifact@master
if: always() if: needs.changes.outputs.changed == 'true'
with: with:
name: screenshots name: screenshots
path: cypress/screenshots path: cypress/screenshots

View file

@ -2,45 +2,76 @@
# #
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
name: lint name: Frontend / Lint
on: on:
push: push:
branches: [ main ] branches: [ develop ]
pull_request: pull_request:
branches: [ main ] branches: [ develop ]
env: env:
NODE_VERSION: 18 NODE_VERSION: 18
defaults:
run:
working-directory: frontend
jobs: 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: lint:
needs: changes
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: Lints all .ts and .tsx files name: Lints all .ts and .tsx files
steps: steps:
- name: Checkout repository - name: Checkout repository
if: needs.changes.outputs.changed == 'true'
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Get yarn cache directory path - name: Get yarn cache directory path
if: needs.changes.outputs.changed == 'true'
id: yarn-cache-dir-path id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Cache yarn cache - name: Cache yarn cache
if: needs.changes.outputs.changed == 'true'
uses: actions/cache@v3 uses: actions/cache@v3
id: yarn-cache id: yarn-cache
with: with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} 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: | restore-keys: |
${{ runner.os }}-yarn-${{ env.NODE_VERSION }} ${{ runner.os }}-yarn-${{ env.NODE_VERSION }}
- name: Set up NodeJS - name: Set up NodeJS
if: needs.changes.outputs.changed == 'true'
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:
node-version: ${{ env.NODE_VERSION }} node-version: ${{ env.NODE_VERSION }}
cache-dependency-path: frontend/yarn.lock
cache: 'yarn'
- name: Install dependencies - name: Install dependencies
if: needs.changes.outputs.changed == 'true'
run: yarn install --immutable run: yarn install --immutable
- name: Lint code - name: Lint code
if: needs.changes.outputs.changed == 'true'
run: yarn lint run: yarn lint

View file

@ -2,67 +2,109 @@
# #
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
name: deploy name: Frontend / Deploy develop branch to Netlify
on: on:
push: push:
branches: [ main ] branches: [ develop ]
env: env:
NETLIFY_VERSION: 12.0.11 NETLIFY_VERSION: 12.0.11
NODE_VERSION: 18 NODE_VERSION: 18
defaults:
run:
working-directory: frontend
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs: 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: deploy:
needs: changes
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: Deploys to netlify name: Deploys to netlify
steps: steps:
- name: Checkout repository - name: Checkout repository
if: needs.changes.outputs.changed == 'true'
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Get yarn cache directory path - name: Get yarn cache directory path
if: needs.changes.outputs.changed == 'true'
id: yarn-cache-dir-path id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Cache yarn cache - name: Cache yarn cache
if: needs.changes.outputs.changed == 'true'
uses: actions/cache@v3 uses: actions/cache@v3
id: yarn-cache id: yarn-cache
with: with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} 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: | restore-keys: |
${{ runner.os }}-yarn-${{ env.NODE_VERSION }} ${{ runner.os }}-yarn-${{ env.NODE_VERSION }}
- name: Set up NodeJS - name: Set up NodeJS
if: needs.changes.outputs.changed == 'true'
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:
node-version: ${{ env.NODE_VERSION }} node-version: ${{ env.NODE_VERSION }}
cache-dependency-path: frontend/yarn.lock
cache: 'yarn'
- name: Patch intro.md to include netlify banner. - name: Patch intro.md to include netlify banner.
if: needs.changes.outputs.changed == 'true'
run: cp netlify/intro.md public/public/intro.md run: cp netlify/intro.md public/public/intro.md
- name: Patch motd.md to include privacy policy. - name: Patch motd.md to include privacy policy.
if: needs.changes.outputs.changed == 'true'
run: cp netlify/motd.md public/public/motd.md run: cp netlify/motd.md public/public/motd.md
- name: Patch version.json to include git hash - 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 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 - name: Patch base URL
if: needs.changes.outputs.changed == 'true'
run: echo "HD_EDITOR_BASE_URL=\"https://hedgedoc.dev/\"" >> .env.production run: echo "HD_EDITOR_BASE_URL=\"https://hedgedoc.dev/\"" >> .env.production
- name: Install dependencies - name: Install dependencies
if: needs.changes.outputs.changed == 'true'
run: yarn install --immutable run: yarn install --immutable
- name: Build app - name: Build app
if: needs.changes.outputs.changed == 'true'
run: yarn build:mock run: yarn build:mock
- name: Remove Next.js cache to avoid it being deployed - name: Remove Next.js cache to avoid it being deployed
if: needs.changes.outputs.changed == 'true'
run: rm -r .next/cache run: rm -r .next/cache
- name: Install netlify CLI - name: Install netlify CLI
if: needs.changes.outputs.changed == 'true'
run: "npm install -g netlify-cli@${{ env.NETLIFY_VERSION }}" run: "npm install -g netlify-cli@${{ env.NETLIFY_VERSION }}"
- name: Run netlify CLI deployment - name: Run netlify CLI deployment
if: needs.changes.outputs.changed == 'true'
env: env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
run: "netlify deploy --build --prod --message \"${{ github.event.head_commit.id }}: ${{ github.event.head_commit.message }}\"" run: "netlify deploy --build --prod --message \"${{ github.event.head_commit.id }}: ${{ github.event.head_commit.message }}\""

View file

@ -2,11 +2,11 @@
# #
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
name: deploy name: Frontend / Deploy PR to Netlify
on: on:
pull_request: pull_request:
branches: [ main ] branches: [ develop ]
types: types:
- labeled - labeled
- opened - opened
@ -14,7 +14,7 @@ on:
- reopened - reopened
- ready_for_review - ready_for_review
pull_request_target: pull_request_target:
branches: [ main ] branches: [ develop ]
types: types:
- labeled - labeled
- opened - opened
@ -30,59 +30,100 @@ env:
NETLIFY_VERSION: 12.0.11 NETLIFY_VERSION: 12.0.11
NODE_VERSION: 18 NODE_VERSION: 18
defaults:
run:
working-directory: frontend
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs: 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: 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 runs-on: ubuntu-latest
name: Deploys to netlify name: Deploys to netlify
env: env:
DEPLOY_URL: "https://${{ github.event.number }}--hedgedoc-ui-test.netlify.app/" DEPLOY_URL: "https://${{ github.event.number }}--hedgedoc-ui-test.netlify.app/"
steps: steps:
- name: Checkout repository - name: Checkout repository
if: needs.changes.outputs.changed == 'true'
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
ref: ${{ github.event.pull_request.head.sha }} ref: ${{ github.event.pull_request.head.sha }}
- name: Get yarn cache directory path - name: Get yarn cache directory path
if: needs.changes.outputs.changed == 'true'
id: yarn-cache-dir-path id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Cache yarn cache - name: Cache yarn cache
if: needs.changes.outputs.changed == 'true'
uses: actions/cache@v3 uses: actions/cache@v3
id: yarn-cache id: yarn-cache
with: with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} 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: | restore-keys: |
${{ runner.os }}-yarn-${{ env.NODE_VERSION }} ${{ runner.os }}-yarn-${{ env.NODE_VERSION }}
- name: Set up NodeJS - name: Set up NodeJS
if: needs.changes.outputs.changed == 'true'
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:
node-version: ${{ env.NODE_VERSION }} node-version: ${{ env.NODE_VERSION }}
cache-dependency-path: frontend/yarn.lock
cache: 'yarn'
- name: Patch intro.md to include netlify banner. - name: Patch intro.md to include netlify banner.
if: needs.changes.outputs.changed == 'true'
run: cp netlify/intro.md public/public/intro.md run: cp netlify/intro.md public/public/intro.md
- name: Patch motd.md to include privacy policy. - name: Patch motd.md to include privacy policy.
if: needs.changes.outputs.changed == 'true'
run: cp netlify/motd.md public/public/motd.md run: cp netlify/motd.md public/public/motd.md
- name: Patch version.json to include git hash - 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 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 - name: Patch base URL
if: needs.changes.outputs.changed == 'true'
run: echo "HD_EDITOR_BASE_URL=\"${{ env.DEPLOY_URL }}\"" >> .env.production run: echo "HD_EDITOR_BASE_URL=\"${{ env.DEPLOY_URL }}\"" >> .env.production
- name: Install dependencies - name: Install dependencies
if: needs.changes.outputs.changed == 'true'
run: yarn install --immutable run: yarn install --immutable
- name: Build app - name: Build app
if: needs.changes.outputs.changed == 'true'
run: yarn build:mock run: yarn build:mock
- name: Remove Next.js cache to avoid it being deployed - name: Remove Next.js cache to avoid it being deployed
if: needs.changes.outputs.changed == 'true'
run: rm -r .next/cache run: rm -r .next/cache
- name: Mark GitHub deployment as started - name: Mark GitHub deployment as started
if: needs.changes.outputs.changed == 'true'
uses: bobheadxi/deployments@v1.3.0 uses: bobheadxi/deployments@v1.3.0
id: github-deployment id: github-deployment
with: with:
@ -93,15 +134,17 @@ jobs:
ref: ${{ github.head_ref }} ref: ${{ github.head_ref }}
- name: Install netlify CLI - name: Install netlify CLI
if: needs.changes.outputs.changed == 'true'
run: "npm install -g netlify-cli@${{ env.NETLIFY_VERSION }}" run: "npm install -g netlify-cli@${{ env.NETLIFY_VERSION }}"
- name: Run netlify CLI - name: Run netlify CLI
if: needs.changes.outputs.changed == 'true'
env: env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
run: "netlify deploy --build --context deploy-preview --alias \"${{ github.event.number }}\" --json --message \"PR #${{ github.event.number }}\"" run: "netlify deploy --build --context deploy-preview --alias \"${{ github.event.number }}\" --json --message \"PR #${{ github.event.number }}\""
- name: Mark GitHub deployment as finished - name: Mark GitHub deployment as finished
if: always() if: needs.changes.outputs.changed == 'true'
uses: bobheadxi/deployments@v1.3.0 uses: bobheadxi/deployments@v1.3.0
with: with:
step: finish step: finish

View file

@ -2,16 +2,39 @@
# #
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
name: test, build name: Frontend / Run unit tests & build
on: on:
push: push:
branches: [ main ] branches: [ develop ]
pull_request: pull_request:
branches: [ main ] branches: [ develop ]
defaults:
run:
working-directory: frontend
jobs: 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: build:
needs: changes
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
@ -19,31 +42,40 @@ jobs:
name: Test and build with NodeJS ${{ matrix.node }} name: Test and build with NodeJS ${{ matrix.node }}
steps: steps:
- name: Checkout repository - name: Checkout repository
if: needs.changes.outputs.changed == 'true'
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Get yarn cache directory path - name: Get yarn cache directory path
if: needs.changes.outputs.changed == 'true'
id: yarn-cache-dir-path id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Cache yarn cache - name: Cache yarn cache
if: needs.changes.outputs.changed == 'true'
uses: actions/cache@v3 uses: actions/cache@v3
id: yarn-cache id: yarn-cache
with: with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} 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: | restore-keys: |
${{ runner.os }}-yarn-${{ matrix.node }} ${{ runner.os }}-yarn-${{ matrix.node }}
- name: Set up NodeJS - name: Set up NodeJS
if: needs.changes.outputs.changed == 'true'
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:
node-version: ${{ matrix.node }} node-version: ${{ matrix.node }}
cache-dependency-path: frontend/yarn.lock
cache: 'yarn'
- name: Install dependencies - name: Install dependencies
if: needs.changes.outputs.changed == 'true'
run: yarn install --immutable run: yarn install --immutable
- name: Test Project - name: Test Project
if: needs.changes.outputs.changed == 'true'
run: yarn test:ci run: yarn test:ci
- name: Build project - name: Build project
if: needs.changes.outputs.changed == 'true'
run: yarn build:mock run: yarn build:mock