hedgedoc/.github/workflows/frontend-netlify-deploy-pr.yml
Tilman Vatteroth 534540855c feat(ci): deduplicate and fix node setup
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2022-12-04 20:59:46 +01:00

139 lines
4.3 KiB
YAML

# SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
#
# SPDX-License-Identifier: AGPL-3.0-only
name: Frontend / Deploy PR to Netlify
on:
pull_request:
branches: [ develop ]
types:
- labeled
- opened
- synchronize
- reopened
- ready_for_review
pull_request_target:
branches: [ develop ]
types:
- labeled
- opened
- synchronize
- reopened
- ready_for_review
permissions:
contents: read
deployments: write
env:
NETLIFY_VERSION: 12.0.11
NODE_VERSION: 18
defaults:
run:
working-directory: frontend
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.head.label }}-${{ github.event_name }}
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@v3
if: github.event_name != 'push'
- name: Check for frontend file changes
if: github.event_name != 'push'
uses: dorny/paths-filter@v2
id: changed
with:
filters: |
files:
- 'frontend/**'
- '.github/**'
- '.yarn/**'
deploy:
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: Setup node
if: needs.changes.outputs.changed == 'true'
uses: ./.github/actions/setup-node
with:
NODE_VERSION: ${{ env.NODE_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_EDITOR_BASE_URL=\"${{ env.DEPLOY_URL }}\"" >> .env.production
- 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:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: "PR #${{ github.event.number }}"
override: true
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: needs.changes.outputs.changed == 'true'
uses: bobheadxi/deployments@v1.3.0
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
env_url: ${{ env.DEPLOY_URL }}
env: ${{ steps.github-deployment.outputs.env }}
status: ${{ job.status }}
deployment_id: ${{ steps.github-deployment.outputs.deployment_id }}
override: true