Files

99 lines
3.4 KiB
YAML

steps:
# Download all required tools
prepare:
image: alpine/curl
commands:
- curl -L https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.33/swagger-codegen-cli-3.0.33.jar > swagger-codegen-cli.jar
- curl -L https://github.com/google/google-java-format/releases/download/v1.15.0/google-java-format-1.15.0-all-deps.jar > google-java-format.jar
when:
event: [ push, pull_request, tag, cron ]
cron: sync
# Generate code and docs from official swagger template
generate:
image: eclipse-temurin:11-jdk
commands:
- >
java
-DsupportingFiles=true
-Dapis -DapiTests=false
-Dmodels -DmodelTests=false
-jar swagger-codegen-cli.jar generate
--input-spec https://raw.githubusercontent.com/go-gitea/gitea/master/templates/swagger/v1_json.tmpl
--config config.json
--lang java
--output ./generated/
when:
event: [ push, pull_request, tag, cron ]
cron: sync
# Format generated and custom code according to the Google Java Style Guide
format:
image: eclipse-temurin:11-jdk
commands:
- java -jar google-java-format.jar --replace $(find ./generated/ -name "*.java")
- java -jar google-java-format.jar --replace $(find ./custom/ -name "*.java")
when:
event: [ push, pull_request, tag, cron ]
cron: sync
# Recreate directories and copy files of previous pipeline step
combine:
image: alpine
commands:
- mkdir --verbose --parents ./src/main/java/ && cp --verbose --recursive ./generated/src/main/java/* ./src/main/java/
- mkdir --verbose --parents ./docs/ && cp --verbose --recursive ./generated/docs/* ./docs/
- mkdir --verbose --parents ./src/ && cp --verbose --recursive ./custom/src/* ./src/
when:
event: [ push, pull_request, tag, cron ]
cron: sync
# Check if generated code can be compiled at language level 8
build:
image: eclipse-temurin:11-jdk
commands:
- ./gradlew clean assemble
when:
event: [ push, pull_request, tag, cron ]
cron: sync
# Upload updated code to repository
publish:
image: alpine/git
environment:
GIT_AUTHOR_NAME:
from_secret: GIT_AUTHOR_NAME
GIT_AUTHOR_EMAIL:
from_secret: GIT_AUTHOR_EMAIL
GIT_COMMIT_MESSAGE:
from_secret: GIT_COMMIT_MESSAGE
GITEA_HOST:
from_secret: GITEA_HOST
GITEA_REPOSITORY:
from_secret: GITEA_REPOSITORY
GITEA_BRANCH:
from_secret: GITEA_BRANCH
GITEA_USERNAME:
from_secret: gitea_username
GITEA_TOKEN:
from_secret: gitea_token
commands:
# Setup git credentials and checkout target branch
- git config user.name "$${GIT_AUTHOR_NAME}"
- git config user.email "$${GIT_AUTHOR_EMAIL}"
- git checkout "$${GITEA_BRANCH}"
# Stage all important files for commit
- git add -A ./docs
- git add -A ./src
# If files have changed, create a new commit and push it to the branch this pipeline was started on
- >
if git commit --message "$${GIT_COMMIT_MESSAGE}"; then
git remote set-url origin "https://$${GITEA_TOKEN}@$${GITEA_HOST}/$${GITEA_REPOSITORY}"
git push origin "$${GITEA_BRANCH}"
fi
when:
branch: main
event: [ push, tag, cron ]
cron: sync