mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 09:46:30 -05:00
8588cbbf21
This is recommended by the OpenSSF scorecard tool Signed-off-by: Erik Michelson <github@erik.michelson.eu>
143 lines
5.2 KiB
YAML
143 lines
5.2 KiB
YAML
# SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
|
#
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
name: Backend / Docker
|
|
|
|
on:
|
|
push:
|
|
branches: [ develop ]
|
|
pull_request_target:
|
|
branches: [ develop ]
|
|
pull_request:
|
|
branches: [ develop ]
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ !!github.event.pull_request && github.event.pull_request.head.label || github.ref }}-${{ github.event_name }}-${{ github.job }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
changes:
|
|
name: Check for backend changes
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
pull-requests: read
|
|
outputs:
|
|
changed: ${{ github.event_name == 'push' || steps.changed.outputs.files }}
|
|
steps:
|
|
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
|
|
if: github.event_name != 'push'
|
|
|
|
- name: Check for backend file changes
|
|
if: github.event_name != 'push'
|
|
uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1
|
|
id: changed
|
|
with:
|
|
filters: |
|
|
files:
|
|
- 'commons/**'
|
|
- 'backend/**'
|
|
- '.github/**'
|
|
- '.yarn/**'
|
|
|
|
build-dev:
|
|
if: "(github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork"
|
|
needs: changes
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
|
|
if: needs.changes.outputs.changed == 'true'
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@8c0edbc76e98fa90f69d9a2c020dcb50019dc325 # v2.2.1
|
|
if: needs.changes.outputs.changed == 'true'
|
|
|
|
- name: Login to GHCR
|
|
if: needs.changes.outputs.changed == 'true'
|
|
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.repository_owner }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Build dev image
|
|
if: needs.changes.outputs.changed == 'true'
|
|
uses: docker/build-push-action@c56af957549030174b10d6867f20e78cfd7debc5 # v3.2.0
|
|
with:
|
|
push: true
|
|
file: backend/docker/Dockerfile
|
|
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
|
|
context: .
|
|
|
|
sqlite-test:
|
|
runs-on: ubuntu-latest
|
|
if: needs.changes.outputs.changed == 'true' && (github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork
|
|
needs: [ build-dev, changes ]
|
|
container:
|
|
image: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}-ci:${{ github.sha }}
|
|
steps:
|
|
- run: cd /usr/src/app/backend && yarn run test
|
|
|
|
sqlite-e2e:
|
|
runs-on: ubuntu-latest
|
|
if: needs.changes.outputs.changed == 'true' && (github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork
|
|
needs: [ build-dev, changes ]
|
|
container:
|
|
image: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}-ci:${{ github.sha }}
|
|
steps:
|
|
- run: cd /usr/src/app/backend && yarn run test:e2e
|
|
|
|
build-prod:
|
|
runs-on: ubuntu-latest
|
|
if: (github.event_name == 'pull_request_target') == github.event.pull_request.head.repo.fork
|
|
needs: [ sqlite-test, sqlite-e2e, changes ]
|
|
steps:
|
|
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
|
|
if: needs.changes.outputs.changed == 'true'
|
|
|
|
- name: Generate Docker metadata
|
|
if: needs.changes.outputs.changed == 'true'
|
|
id: meta
|
|
uses: docker/metadata-action@57396166ad8aefe6098280995947635806a0e6ea # v4.1.1
|
|
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
|
|
uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # v2.1.0
|
|
if: needs.changes.outputs.changed == 'true'
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@8c0edbc76e98fa90f69d9a2c020dcb50019dc325 # v2.2.1
|
|
if: needs.changes.outputs.changed == 'true'
|
|
|
|
- name: Login to GHCR
|
|
if: github.event_name == 'push' && needs.changes.outputs.changed == 'true'
|
|
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.repository_owner }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Build and push
|
|
if: needs.changes.outputs.changed == 'true'
|
|
uses: docker/build-push-action@c56af957549030174b10d6867f20e78cfd7debc5 # v3.2.0
|
|
with:
|
|
push: ${{ github.event_name == 'push' }}
|
|
file: backend/docker/Dockerfile
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
context: .
|