Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# code: language=shellscript insertSpaces=true tabSize=2
# shellcheck disable=SC2148
export VIRTUAL_ENV=.venv
layout python3

echo '*' > "$PWD/.venv/.gitignore"

if test -f "$PWD/requirements.txt" && test "$PWD/.venv/.requirements.txt" -ot "$PWD/requirements.txt"; then
watch_file "$PWD/requirements.txt"
touch "$PWD/.venv/.requirements.txt"
fi

if ! test -f "$PWD/.venv/.pre-commit-installed"; then
pip install -U pre-commit
pre-commit install
touch "$PWD/.venv/.pre-commit-installed"
fi

dotenv_if_exists .env
31 changes: 31 additions & 0 deletions .github/actions/maven-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Build Java project
description: |-
This action build a Java Maven project

inputs:
run-tests:
description: |-
Run defined tests
default: 'true'

runs:
using: "composite"
steps:
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
cache: maven

- name: Build with Maven
id: maven-build
shell: bash
run: mvn -B clean package

- name: Run tests
id: maven-test
if: ${{ inputs.run-tests == 'true' }}
shell: bash
run: mvn test
18 changes: 18 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: Pull Request

on:
pull_request:
branches:
- "master"

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- id: build-project
name: Build
uses: ./.github/actions/maven-build
57 changes: 57 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
name: Release

on:
push:
tags:
- "v*"

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4

- id: build-project
name: Build
uses: ./.github/actions/maven-build
with:
run-tests: 'false'

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
type=raw,value=latest,enable={{is_default_branch}}
labels: |
org.opencontainers.image.vendor=Ophios GmbH

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: docker/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar

# Eclipse m2e generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath

*generator
**/log*.txt
**/*.log
**/*.env
!.envrc
36 changes: 36 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
repos:
- repo: 'https://github.com/pre-commit/pre-commit-hooks'
rev: 'v5.0.0'
hooks:
- id: 'check-added-large-files'
- id: 'fix-byte-order-marker'
- id: 'check-case-conflict'
- id: 'check-json'
- id: 'end-of-file-fixer'
exclude: '.*\.mustache$'
- id: 'trailing-whitespace'
exclude: '.*\.mustache$'
- id: 'mixed-line-ending'
- id: 'check-merge-conflict'
- id: 'no-commit-to-branch'
args:
- '--branch'
- 'master'

- repo: https://github.com/adrienverge/yamllint.git
rev: v1.35.1
hooks:
- id: yamllint
args:
- --strict

- repo: https://github.com/rhysd/actionlint
rev: v1.7.4
hooks:
- id: actionlint-docker

- repo: https://github.com/hadolint/hadolint
rev: v2.12.0
hooks:
- id: hadolint-docker
11 changes: 11 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
extends: default

rules:
truthy:
allowed-values:
- 'on'
- 'yes'
- 'true'
- 'false'
check-keys: true
1 change: 1 addition & 0 deletions docker/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scripts/* text eol=lf
14 changes: 14 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG BASE_VERSION=v7.10.0
FROM openapitools/openapi-generator-cli:${BASE_VERSION}

ARG GENERATOR_DIR=/opt/openapi-generator/modules/openapi-generator-cli/target
ARG GENERATOR_VERSION=1.0.0

COPY --chmod=555 docker/scripts/docker-entrypoint.sh /usr/local/bin/
RUN ln -s /usr/local/bin/docker-entrypoint.sh /usr/local/bin/openapi-generator

COPY target/openapi-generator-di-${GENERATOR_VERSION}.jar ${GENERATOR_DIR}/openapi-generator-di.jar

ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]

CMD ["help"]
49 changes: 49 additions & 0 deletions docker/scripts/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

set -euo pipefail

# GEN_DIR allows to share the entrypoint between Dockerfile and run-in-docker.sh (backward compatible)
GEN_DIR=${GEN_DIR:-/opt/openapi-generator}
JAVA_OPTS=${JAVA_OPTS:-"-Xmx1024M -DloggerPath=conf/log4j.properties"}

cli="${GEN_DIR}/modules/openapi-generator-cli"
codegen="${cli}/target/openapi-generator-cli.jar"
extrajars=$(find "${cli}/target/" -name '*.jar' | grep -v 'openapi-generator-cli.jar' | xargs | sed 's/ /:/g')

# We code in a list of commands here as source processing is potentially buggy (requires undocumented conventional use of annotations).
# A list of known commands helps us determine if we should compile CLI. There's an edge-case where a new command not added to this
# list won't be considered a "real" command. We can get around that a bit by checking CLI completions beforehand if it exists.
commands="config-help,generate,batch,help,list,meta,validate,version"

if [ $# == 0 ]; then
echo "No command specified. Available commands:"
for i in $(echo $commands | sed "s/,/ /g")
do
echo " $i"
done
exit
fi

# if CLI jar exists, check $1 against completions available in the CLI
if [[ -f "${codegen}" && -n "$(java ${JAVA_OPTS} -jar "${codegen}" completion | grep "^$1\$" )" ]]; then
command=$1
shift
if [[ "${extrajars}" != "" ]]; then
codegen="${codegen}:${extrajars}"
fi
exec java ${JAVA_OPTS} -cp "${codegen}" org.openapitools.codegen.OpenAPIGenerator "${command}" "$@"
elif [[ -n "$(echo $commands | tr ',' '\n' | grep "^$1\$" )" ]]; then
# If CLI jar does not exist, and $1 is a known CLI command, build the CLI jar and run that command.
if [[ ! -f "${codegen}" ]]; then
(cd "${GEN_DIR}" && exec mvn -am -pl "modules/openapi-generator-cli" -Duser.home=$(dirname $MAVEN_CONFIG) package)
fi
command=$1
shift
if [[ "${extrajars}" != "" ]]; then
codegen="${codegen}:"
fi
exec java ${JAVA_OPTS} -cp "${codegen}" org.openapitools.codegen.OpenAPIGenerator "${command}" "$@"
else
# Pass args as linux commands. This allows us to do something like: docker run -it (-e…, -v…) image ls -la
exec "$@"
fi
Loading
Loading