2022-01-25 10:10:34 -05:00
|
|
|
# SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-11-11 04:55:08 -05:00
|
|
|
name: Frontend / Deploy PR to Netlify
|
2022-01-25 10:10:34 -05:00
|
|
|
|
|
|
|
on:
|
2022-11-06 14:07:44 -05:00
|
|
|
pull_request:
|
2022-11-11 04:55:08 -05:00
|
|
|
branches: [ develop ]
|
2022-11-06 14:07:44 -05:00
|
|
|
types:
|
|
|
|
- labeled
|
|
|
|
- opened
|
|
|
|
- synchronize
|
|
|
|
- reopened
|
|
|
|
- ready_for_review
|
2022-10-21 12:57:29 -04:00
|
|
|
pull_request_target:
|
2022-11-11 04:55:08 -05:00
|
|
|
branches: [ develop ]
|
2022-10-21 12:57:29 -04:00
|
|
|
types:
|
|
|
|
- labeled
|
|
|
|
- opened
|
|
|
|
- synchronize
|
|
|
|
- reopened
|
|
|
|
- ready_for_review
|
|
|
|
|
|
|
|
permissions:
|
|
|
|
contents: read
|
|
|
|
deployments: write
|
|
|
|
|
|
|
|
env:
|
|
|
|
NETLIFY_VERSION: 12.0.11
|
|
|
|
NODE_VERSION: 18
|
2022-01-25 10:10:34 -05:00
|
|
|
|
2022-11-11 04:55:08 -05:00
|
|
|
defaults:
|
|
|
|
run:
|
|
|
|
working-directory: frontend
|
|
|
|
|
|
|
|
concurrency:
|
2022-11-20 16:29:35 -05:00
|
|
|
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
|
2022-11-11 04:55:08 -05:00
|
|
|
cancel-in-progress: true
|
|
|
|
|
2022-01-25 10:10:34 -05:00
|
|
|
jobs:
|
2022-11-11 04:55:08 -05:00
|
|
|
changes:
|
|
|
|
name: Check for frontend changes
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
permissions:
|
|
|
|
pull-requests: read
|
|
|
|
outputs:
|
|
|
|
changed: ${{ steps.changed.outputs.files }}
|
|
|
|
steps:
|
2022-11-20 16:16:54 -05:00
|
|
|
- uses: actions/checkout@v3
|
2022-11-11 04:55:08 -05:00
|
|
|
- name: Check for frontend file changes
|
|
|
|
uses: dorny/paths-filter@v2
|
|
|
|
id: changed
|
|
|
|
with:
|
|
|
|
filters: |
|
|
|
|
files:
|
|
|
|
- 'frontend/**'
|
|
|
|
- '.github/**'
|
|
|
|
- '.yarn/**'
|
|
|
|
|
2022-01-25 10:10:34 -05:00
|
|
|
deploy:
|
2022-11-11 04:55:08 -05:00
|
|
|
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"
|
2022-01-25 10:10:34 -05:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
name: Deploys to netlify
|
2022-10-21 12:57:29 -04:00
|
|
|
env:
|
|
|
|
DEPLOY_URL: "https://${{ github.event.number }}--hedgedoc-ui-test.netlify.app/"
|
2022-01-25 10:10:34 -05:00
|
|
|
steps:
|
|
|
|
- name: Checkout repository
|
2022-11-11 04:55:08 -05:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-03-05 10:27:37 -05:00
|
|
|
uses: actions/checkout@v3
|
2022-11-06 16:04:23 -05:00
|
|
|
with:
|
|
|
|
ref: ${{ github.event.pull_request.head.sha }}
|
2022-01-25 10:10:34 -05:00
|
|
|
|
|
|
|
- name: Get yarn cache directory path
|
2022-11-11 04:55:08 -05:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-01-25 10:10:34 -05:00
|
|
|
id: yarn-cache-dir-path
|
2022-10-19 16:47:03 -04:00
|
|
|
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
|
2022-01-25 10:10:34 -05:00
|
|
|
|
|
|
|
- name: Cache yarn cache
|
2022-11-11 04:55:08 -05:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-04-02 05:07:13 -04:00
|
|
|
uses: actions/cache@v3
|
2022-01-25 10:10:34 -05:00
|
|
|
id: yarn-cache
|
|
|
|
with:
|
|
|
|
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
2022-11-11 04:55:08 -05:00
|
|
|
key: ${{ runner.os }}-${{ env.NODE_VERSION }}-yarn-${{ hashFiles('frontend/yarn.lock') }}
|
2022-01-25 10:10:34 -05:00
|
|
|
restore-keys: |
|
2022-10-21 12:57:29 -04:00
|
|
|
${{ runner.os }}-yarn-${{ env.NODE_VERSION }}
|
2022-01-25 10:10:34 -05:00
|
|
|
|
|
|
|
- name: Set up NodeJS
|
2022-11-11 04:55:08 -05:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-02-25 19:36:32 -05:00
|
|
|
uses: actions/setup-node@v3
|
2022-01-25 10:10:34 -05:00
|
|
|
with:
|
2022-10-21 12:57:29 -04:00
|
|
|
node-version: ${{ env.NODE_VERSION }}
|
2022-11-11 04:55:08 -05:00
|
|
|
cache-dependency-path: frontend/yarn.lock
|
|
|
|
cache: 'yarn'
|
2022-10-21 12:57:29 -04:00
|
|
|
|
|
|
|
- name: Patch intro.md to include netlify banner.
|
2022-11-11 04:55:08 -05:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-10-21 12:57:29 -04:00
|
|
|
run: cp netlify/intro.md public/public/intro.md
|
2022-01-25 10:10:34 -05:00
|
|
|
|
2022-10-21 12:57:29 -04:00
|
|
|
- name: Patch motd.md to include privacy policy.
|
2022-11-11 04:55:08 -05:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-10-21 12:57:29 -04:00
|
|
|
run: cp netlify/motd.md public/public/motd.md
|
|
|
|
|
|
|
|
- name: Patch version.json to include git hash
|
2022-11-11 04:55:08 -05:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-10-21 12:57:29 -04:00
|
|
|
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
|
2022-11-11 04:55:08 -05:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-10-21 12:57:29 -04:00
|
|
|
run: echo "HD_EDITOR_BASE_URL=\"${{ env.DEPLOY_URL }}\"" >> .env.production
|
2022-07-30 18:39:49 -04:00
|
|
|
|
2022-01-25 10:10:34 -05:00
|
|
|
- name: Install dependencies
|
2022-11-11 04:55:08 -05:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-01-25 10:10:34 -05:00
|
|
|
run: yarn install --immutable
|
|
|
|
|
2022-09-18 14:12:51 -04:00
|
|
|
- name: Build app
|
2022-11-11 04:55:08 -05:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-09-16 05:03:29 -04:00
|
|
|
run: yarn build:mock
|
2022-01-25 10:10:34 -05:00
|
|
|
|
|
|
|
- name: Remove Next.js cache to avoid it being deployed
|
2022-11-11 04:55:08 -05:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-01-25 10:10:34 -05:00
|
|
|
run: rm -r .next/cache
|
|
|
|
|
|
|
|
- name: Mark GitHub deployment as started
|
2022-11-11 04:55:08 -05:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-06-25 02:50:01 -04:00
|
|
|
uses: bobheadxi/deployments@v1.3.0
|
2022-01-25 10:10:34 -05:00
|
|
|
id: github-deployment
|
|
|
|
with:
|
|
|
|
step: start
|
|
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
2022-01-27 11:55:01 -05:00
|
|
|
env: "PR #${{ github.event.number }}"
|
2022-02-27 12:26:59 -05:00
|
|
|
override: true
|
2022-01-25 10:10:34 -05:00
|
|
|
ref: ${{ github.head_ref }}
|
|
|
|
|
2022-10-21 12:57:29 -04:00
|
|
|
- name: Install netlify CLI
|
2022-11-11 04:55:08 -05:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-10-21 12:57:29 -04:00
|
|
|
run: "npm install -g netlify-cli@${{ env.NETLIFY_VERSION }}"
|
|
|
|
|
|
|
|
- name: Run netlify CLI
|
2022-11-11 04:55:08 -05:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-01-25 10:10:34 -05:00
|
|
|
env:
|
|
|
|
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
2022-10-21 12:57:29 -04:00
|
|
|
run: "netlify deploy --build --context deploy-preview --alias \"${{ github.event.number }}\" --json --message \"PR #${{ github.event.number }}\""
|
2022-01-25 10:10:34 -05:00
|
|
|
|
|
|
|
- name: Mark GitHub deployment as finished
|
2022-11-11 04:55:08 -05:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-06-25 02:50:01 -04:00
|
|
|
uses: bobheadxi/deployments@v1.3.0
|
2022-01-25 10:10:34 -05:00
|
|
|
with:
|
|
|
|
step: finish
|
|
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
2022-10-21 12:57:29 -04:00
|
|
|
env_url: ${{ env.DEPLOY_URL }}
|
2022-02-27 13:08:35 -05:00
|
|
|
env: ${{ steps.github-deployment.outputs.env }}
|
2022-01-25 10:10:34 -05:00
|
|
|
status: ${{ job.status }}
|
|
|
|
deployment_id: ${{ steps.github-deployment.outputs.deployment_id }}
|
2022-02-27 12:26:59 -05:00
|
|
|
override: true
|