2022-03-07 15:08:17 +00:00
|
|
|
# SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-10-02 18:10:32 +00:00
|
|
|
name: Backend / Docker
|
2022-03-07 15:08:17 +00:00
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches: [ develop ]
|
2022-12-06 11:26:39 +00:00
|
|
|
pull_request_target:
|
|
|
|
branches: [ develop ]
|
2022-03-07 15:08:17 +00:00
|
|
|
pull_request:
|
|
|
|
branches: [ develop ]
|
|
|
|
|
2022-12-06 11:26:39 +00:00
|
|
|
permissions:
|
|
|
|
contents: read
|
|
|
|
packages: write
|
|
|
|
|
2022-12-04 21:14:59 +00:00
|
|
|
concurrency:
|
2022-12-06 11:26:39 +00:00
|
|
|
group: ${{ github.workflow }}-${{ !!github.event.pull_request && github.event.pull_request.head.label || github.ref }}-${{ github.event_name }}-${{ github.job }}
|
2022-12-04 21:14:59 +00:00
|
|
|
cancel-in-progress: true
|
|
|
|
|
2022-03-07 15:08:17 +00:00
|
|
|
jobs:
|
2022-11-11 11:00:45 +00:00
|
|
|
changes:
|
|
|
|
name: Check for backend changes
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
permissions:
|
|
|
|
pull-requests: read
|
|
|
|
outputs:
|
2022-11-21 16:24:36 +00:00
|
|
|
changed: ${{ github.event_name == 'push' || steps.changed.outputs.files }}
|
2022-11-11 11:00:45 +00:00
|
|
|
steps:
|
2022-11-20 21:16:54 +00:00
|
|
|
- uses: actions/checkout@v3
|
2022-11-21 16:24:36 +00:00
|
|
|
if: github.event_name != 'push'
|
|
|
|
|
2022-11-11 11:00:45 +00:00
|
|
|
- name: Check for backend file changes
|
2022-11-21 16:24:36 +00:00
|
|
|
if: github.event_name != 'push'
|
2022-11-11 11:00:45 +00:00
|
|
|
uses: dorny/paths-filter@v2
|
|
|
|
id: changed
|
|
|
|
with:
|
|
|
|
filters: |
|
|
|
|
files:
|
|
|
|
- 'backend/**'
|
|
|
|
- '.github/**'
|
|
|
|
- '.yarn/**'
|
|
|
|
|
2022-03-07 15:08:17 +00:00
|
|
|
build-dev:
|
2022-12-06 11:26:39 +00:00
|
|
|
if: "(github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork"
|
2022-11-11 11:00:45 +00:00
|
|
|
needs: changes
|
2022-03-07 15:08:17 +00:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2022-10-02 18:10:32 +00:00
|
|
|
- uses: actions/checkout@v3
|
2022-11-11 11:00:45 +00:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-10-02 18:10:32 +00:00
|
|
|
|
2022-03-07 15:08:17 +00:00
|
|
|
- name: Set up Docker Buildx
|
2022-05-07 12:21:51 +00:00
|
|
|
uses: docker/setup-buildx-action@v2
|
2022-11-11 11:00:45 +00:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-03-07 15:08:17 +00:00
|
|
|
|
|
|
|
- name: Login to GHCR
|
2022-11-11 11:00:45 +00:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-05-07 06:19:57 +00:00
|
|
|
uses: docker/login-action@v2
|
2022-03-07 15:08:17 +00:00
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ github.repository_owner }}
|
|
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
|
|
|
- name: Build dev image
|
2022-11-11 11:00:45 +00:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-05-07 06:19:55 +00:00
|
|
|
uses: docker/build-push-action@v3
|
2022-03-07 15:08:17 +00:00
|
|
|
with:
|
|
|
|
push: true
|
2022-10-02 18:10:32 +00:00
|
|
|
file: backend/docker/Dockerfile
|
2022-03-07 15:08:17 +00:00
|
|
|
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
|
2022-10-02 18:10:32 +00:00
|
|
|
context: .
|
2022-03-07 15:08:17 +00:00
|
|
|
|
|
|
|
sqlite-test:
|
|
|
|
runs-on: ubuntu-latest
|
2022-12-06 11:26:39 +00:00
|
|
|
if: needs.changes.outputs.changed == 'true' && (github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork
|
2022-11-11 11:00:45 +00:00
|
|
|
needs: [ build-dev, changes ]
|
2022-03-07 15:08:17 +00:00
|
|
|
container:
|
|
|
|
image: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}-ci:${{ github.sha }}
|
|
|
|
steps:
|
2022-11-02 15:24:45 +00:00
|
|
|
- run: cd /usr/src/app/backend && yarn run test
|
2022-03-07 15:08:17 +00:00
|
|
|
|
|
|
|
sqlite-e2e:
|
|
|
|
runs-on: ubuntu-latest
|
2022-12-06 11:26:39 +00:00
|
|
|
if: needs.changes.outputs.changed == 'true' && (github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork
|
2022-11-11 11:00:45 +00:00
|
|
|
needs: [ build-dev, changes ]
|
2022-03-07 15:08:17 +00:00
|
|
|
container:
|
|
|
|
image: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}-ci:${{ github.sha }}
|
|
|
|
steps:
|
2022-11-02 15:24:45 +00:00
|
|
|
- run: cd /usr/src/app/backend && yarn run test:e2e
|
2022-03-07 15:08:17 +00:00
|
|
|
|
|
|
|
build-prod:
|
|
|
|
runs-on: ubuntu-latest
|
2022-12-06 11:26:39 +00:00
|
|
|
if: (github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork
|
2022-11-11 11:00:45 +00:00
|
|
|
needs: [ sqlite-test, sqlite-e2e, changes ]
|
2022-03-07 15:08:17 +00:00
|
|
|
steps:
|
2022-10-02 18:10:32 +00:00
|
|
|
- uses: actions/checkout@v3
|
2022-11-11 11:00:45 +00:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-10-02 18:10:32 +00:00
|
|
|
|
2022-03-07 15:08:17 +00:00
|
|
|
- name: Generate Docker metadata
|
2022-11-11 11:00:45 +00:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-03-07 15:08:17 +00:00
|
|
|
id: meta
|
2022-05-07 12:21:48 +00:00
|
|
|
uses: docker/metadata-action@v4
|
2022-03-07 15:08:17 +00:00
|
|
|
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
|
2022-05-07 12:21:53 +00:00
|
|
|
uses: docker/setup-qemu-action@v2
|
2022-11-11 11:00:45 +00:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-03-07 15:08:17 +00:00
|
|
|
|
|
|
|
- name: Set up Docker Buildx
|
2022-05-07 12:21:51 +00:00
|
|
|
uses: docker/setup-buildx-action@v2
|
2022-11-11 11:00:45 +00:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-03-07 15:08:17 +00:00
|
|
|
|
|
|
|
- name: Login to GHCR
|
2022-12-06 11:26:39 +00:00
|
|
|
if: github.event_name == 'push' && needs.changes.outputs.changed == 'true'
|
2022-05-07 06:19:57 +00:00
|
|
|
uses: docker/login-action@v2
|
2022-03-07 15:08:17 +00:00
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ github.repository_owner }}
|
|
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
|
|
|
- name: Build and push
|
2022-11-11 11:00:45 +00:00
|
|
|
if: needs.changes.outputs.changed == 'true'
|
2022-05-07 06:19:55 +00:00
|
|
|
uses: docker/build-push-action@v3
|
2022-03-07 15:08:17 +00:00
|
|
|
with:
|
2022-12-06 11:26:39 +00:00
|
|
|
push: ${{ github.event_name == 'push' }}
|
2022-10-02 18:10:32 +00:00
|
|
|
file: backend/docker/Dockerfile
|
2022-03-07 15:08:17 +00:00
|
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
|
|
cache-from: type=gha
|
|
|
|
cache-to: type=gha,mode=max
|
2022-10-02 18:10:32 +00:00
|
|
|
context: .
|