setup common workflows
This commit is contained in:
17
.editorconfig
Normal file
17
.editorconfig
Normal file
@@ -0,0 +1,17 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
max_line_length = 120
|
||||
tab_width = 4
|
||||
|
||||
[*.{md,yaml}]
|
||||
max_line_length = 1024
|
||||
|
||||
[*.yaml]
|
||||
indent_size = 2
|
||||
tab_width = 2
|
||||
36
.gitea/workflows/gradle-build.yaml
Normal file
36
.gitea/workflows/gradle-build.yaml
Normal file
@@ -0,0 +1,36 @@
|
||||
name: Gradle Build on PR
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
BUILD_OPTION:
|
||||
default: ""
|
||||
description: "Gradle build option"
|
||||
required: false
|
||||
type: "string"
|
||||
JAVA_DISTRIBUTION:
|
||||
default: "temurin"
|
||||
description: "Java distribution to use"
|
||||
required: false
|
||||
type: "string"
|
||||
JAVA_VERSION:
|
||||
default: "25"
|
||||
description: "Java version to use"
|
||||
required: false
|
||||
type: "string"
|
||||
|
||||
jobs:
|
||||
gradle-build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: ${{ inputs.JAVA_DISTRIBUTION }}
|
||||
java-version: ${{ inputs.JAVA_VERSION }}
|
||||
- name: Run Gradle Build
|
||||
run: ./gradlew build ${{ inputs.BUILD_OPTION }}
|
||||
41
.gitea/workflows/publish-artifact.yaml
Normal file
41
.gitea/workflows/publish-artifact.yaml
Normal file
@@ -0,0 +1,41 @@
|
||||
name: Publish Artifact
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
BRANCH_REFERENCE:
|
||||
description: "Branch reference"
|
||||
required: true
|
||||
type: "string"
|
||||
JAVA_DISTRIBUTION:
|
||||
default: "temurin"
|
||||
description: "Java distribution to use"
|
||||
required: false
|
||||
type: "string"
|
||||
JAVA_VERSION:
|
||||
default: "25"
|
||||
description: "Java version to use"
|
||||
required: false
|
||||
type: "string"
|
||||
|
||||
jobs:
|
||||
publish-artifact:
|
||||
runs-on: "ubuntu-latest"
|
||||
steps:
|
||||
- name: "Checkout repository"
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
ref: ${{ inputs.BRANCH_REFERENCE }}
|
||||
token: ${{ secrets.CI_BOT_TOKEN }}
|
||||
- name: "Set up JDK"
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: ${{ inputs.JAVA_DISTRIBUTION }}
|
||||
java-version: ${{ inputs.JAVA_VERSION }}
|
||||
- name: "Run Gradle"
|
||||
run: ./gradlew publishAllPublicationsToHlaejaRepository
|
||||
shell: bash
|
||||
env:
|
||||
REPOSITORY_USER: ${{ secrets.CI_BOT_USERNAME }}
|
||||
REPOSITORY_TOKEN: ${{ secrets.CI_BOT_TOKEN }}
|
||||
78
.gitea/workflows/publish-container.yaml
Normal file
78
.gitea/workflows/publish-container.yaml
Normal file
@@ -0,0 +1,78 @@
|
||||
name: Publish Docker Images
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
BRANCH_REFERENCE:
|
||||
description: "Branch reference"
|
||||
required: true
|
||||
type: "string"
|
||||
JAVA_DISTRIBUTION:
|
||||
default: "temurin"
|
||||
description: "Java distribution to use"
|
||||
required: false
|
||||
type: "string"
|
||||
JAVA_VERSION:
|
||||
default: "25"
|
||||
description: "Java version to use"
|
||||
required: false
|
||||
type: "string"
|
||||
|
||||
jobs:
|
||||
publish-artifact:
|
||||
runs-on: "ubuntu-latest"
|
||||
steps:
|
||||
- name: "Checkout repository"
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
ref: ${{ inputs.BRANCH_REFERENCE }}
|
||||
token: ${{ secrets.CI_BOT_TOKEN }}
|
||||
- name: "Set up JDK"
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: ${{ inputs.JAVA_DISTRIBUTION }}
|
||||
java-version: ${{ inputs.JAVA_VERSION }}
|
||||
- name: "Extract project information"
|
||||
id: project
|
||||
run: |
|
||||
NAME=$(awk -F '=' '/^rootProject\.name/{gsub(/[[:space:]]*/,"",$2); gsub(/"/,"",$2); print $2}' settings.gradle.kts)
|
||||
if [ -z "$NAME" ]; then
|
||||
echo "Error: No application name found in settings.gradle.kts" >&2
|
||||
exit 1
|
||||
fi
|
||||
VERSION=$(awk -F '=' '/^version[[:space:]]*=/{gsub(/[[:space:]]*/,"",$2); print $2}' gradle.properties)
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "Error: No version found in gradle.properties" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "name=$NAME" >> $GITHUB_OUTPUT
|
||||
echo "Extracted application name: $NAME"
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
echo "Extracted application version: $VERSION"
|
||||
- name: "Build Docker Image"
|
||||
run: ./gradlew dockerBuildImage
|
||||
env:
|
||||
REPOSITORY_USER: ${{ secrets.CI_BOT_USERNAME }}
|
||||
REPOSITORY_TOKEN: ${{ secrets.CI_BOT_TOKEN }}
|
||||
- name: "Set up Docker Buildx"
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
install: true
|
||||
driver: docker-container
|
||||
- name: Log in to Gitea Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: "gitea.lulz.ltd"
|
||||
username: ${{ secrets.CI_BOT_USERNAME }}
|
||||
password: ${{ secrets.CI_BOT_TOKEN }}
|
||||
- name: "Build and push Docker image"
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: ./build/docker/
|
||||
platforms: linux/amd64
|
||||
provenance: false
|
||||
push: true
|
||||
sbom: false
|
||||
tags: |
|
||||
gitea.lulz.ltd/hlaeja/${{ steps.project.outputs.name }}:${{ steps.project.outputs.version }}
|
||||
144
.gitea/workflows/release.yaml
Normal file
144
.gitea/workflows/release.yaml
Normal file
@@ -0,0 +1,144 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
DATABASE_FILES:
|
||||
default: ""
|
||||
description: "Whether to handle database files"
|
||||
required: false
|
||||
type: "string"
|
||||
FAIL_FOR_NO_CHANGES:
|
||||
default: true
|
||||
description: "Fail if there were no changes to release"
|
||||
required: false
|
||||
type: "boolean"
|
||||
JAVA_DISTRIBUTION:
|
||||
default: "temurin"
|
||||
description: "Java distribution to use"
|
||||
required: false
|
||||
type: "string"
|
||||
JAVA_VERSION:
|
||||
default: "25"
|
||||
description: "Java version to use"
|
||||
required: false
|
||||
type: "string"
|
||||
RELEASE_TYPE:
|
||||
default: ""
|
||||
description: "Type of release (service, library, plugin, or catalog)"
|
||||
required: false
|
||||
type: "string"
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: "ubuntu-latest"
|
||||
outputs:
|
||||
release-version: ${{ steps.project.outputs.release }}
|
||||
steps:
|
||||
- name: "Checkout repository"
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.CI_BOT_TOKEN }}
|
||||
- name: "Set git credentials"
|
||||
run: |
|
||||
git config --global user.name "${{ vars.BOT_NAME }}"
|
||||
git config --global user.email "${{ vars.BOT_EMAIL }}"
|
||||
echo "Set Git name: ${{ vars.BOT_NAME }}"
|
||||
echo "Set Git email: ${{ vars.BOT_EMAIL }}"
|
||||
- name: "Extract project information"
|
||||
id: project
|
||||
run: |
|
||||
VERSION=$(awk -F '=' '/^version[[:space:]]*=/{ gsub(/[[:space:]]*/,"",$2); sub(/-SNAPSHOT$/,"",$2); print $2 }' gradle.properties)
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "Error: No version found in gradle.properties" >&2
|
||||
exit 1
|
||||
fi
|
||||
CHANGE="false"
|
||||
if [[ $(git log -1 --pretty=%B) != *"[RELEASE] - Bump version"* ]]; then
|
||||
CHANGE="true"
|
||||
fi
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
echo "release=v$VERSION" >> $GITHUB_OUTPUT
|
||||
echo "Extracted application version: $VERSION"
|
||||
echo "change=$CHANGE" >> $GITHUB_OUTPUT
|
||||
echo "Has changes to release? $CHANGE"
|
||||
- name: "Fail workflow if there are no changes"
|
||||
if: steps.project.outputs.change == 'false' && inputs.FAIL_FOR_NO_CHANGES
|
||||
run: |
|
||||
echo "No changes to release, failing..."
|
||||
exit 1
|
||||
- name: "Un-snapshot catalog versions"
|
||||
if: ${{ inputs.RELEASE_TYPE == 'catalog' }}
|
||||
run: |
|
||||
if [ -f versions-catalog.toml ]; then
|
||||
sed -i -E 's/^(lulz[A-Za-z]+[[:space:]]*=[[:space:]]*")([0-9]+\.[0-9]+\.[0-9]+)-SNAPSHOT(")/\1\2\3/' hlaeja-versions-catalog.toml
|
||||
if ! git diff --quiet hlaeja-versions-catalog.toml; then
|
||||
git add hlaeja-versions-catalog.toml
|
||||
echo "Versions catalog: updated"
|
||||
else
|
||||
echo "Versions catalog: no changes"
|
||||
fi
|
||||
fi
|
||||
- name: "Un-snapshot version and commit changes"
|
||||
run: |
|
||||
sed -i "s/\(version\s*=\s*[0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/" gradle.properties
|
||||
sed -i "s/\(catalog\s*=\s*[0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/" gradle.properties
|
||||
if ! git diff --exit-code --quiet -- "gradle.properties"; then
|
||||
git add gradle.properties
|
||||
git commit -m "[RELEASE] - Release version: ${{ steps.project.outputs.version }}"
|
||||
git push origin master
|
||||
else
|
||||
echo "No changes to commit"
|
||||
fi
|
||||
- name: "Add release tag"
|
||||
run: |
|
||||
git_tag="v${{ steps.project.outputs.version }}"
|
||||
git tag -a "$git_tag" -m "Release version $git_tag"
|
||||
git push origin "$git_tag"
|
||||
- name: "Archive database files and commit changes"
|
||||
if: ${{ inputs.DATABASE_FILES != '' }}
|
||||
run: |
|
||||
type="${{ inputs.DATABASE_FILES }}"
|
||||
version_dir="${type}/v${{ steps.project.outputs.version }}"
|
||||
if [ -d "$type" ] && [ -n "$(ls -A $type/*."$type" 2>/dev/null)" ]; then
|
||||
mkdir -p "$version_dir"
|
||||
mv "$type"/*."$type" "$version_dir/"
|
||||
git add "$type"
|
||||
git commit -m "[RELEASE] - Move $type files to ${version_dir}"
|
||||
git push origin master
|
||||
else
|
||||
echo "No database files to process"
|
||||
fi
|
||||
- name: "Snapshot version and commit changes"
|
||||
run: |
|
||||
next_version=$(awk -F '.' '{print $1 "." $2+1 ".0"}' <<< "${{ steps.project.outputs.version }}")
|
||||
sed -i "s/\(version\s*=\s*\)[0-9.]*/\1${next_version}-SNAPSHOT/" gradle.properties
|
||||
echo "Bumped version to: ${next_version}-SNAPSHOT"
|
||||
if ! git diff --exit-code --quiet -- "gradle.properties"; then
|
||||
git add gradle.properties
|
||||
git commit -m "[RELEASE] - Bump version"
|
||||
git push origin master
|
||||
else
|
||||
echo "No changes to commit"
|
||||
fi
|
||||
|
||||
finalise-publish-artifact:
|
||||
needs: release
|
||||
if: inputs.RELEASE_TYPE == 'catalog' || inputs.RELEASE_TYPE == 'library' || inputs.RELEASE_TYPE == 'plugin'
|
||||
uses: workflow/hlaeja/.gitea/workflows/publish-artifact.yaml@master
|
||||
with:
|
||||
BRANCH_REFERENCE: ${{ needs.release.outputs.release-version }}
|
||||
JAVA_DISTRIBUTION: ${{ inputs.JAVA_DISTRIBUTION }}
|
||||
JAVA_VERSION: ${{ inputs.JAVA_VERSION }}
|
||||
secrets: inherit
|
||||
|
||||
finalise-publish-container:
|
||||
needs: release
|
||||
if: inputs.RELEASE_TYPE == 'service'
|
||||
uses: workflow/hlaeja/.gitea/workflows/publish-container.yaml@master
|
||||
with:
|
||||
BRANCH_REFERENCE: ${{ needs.release.outputs.release-version }}
|
||||
JAVA_DISTRIBUTION: ${{ inputs.JAVA_DISTRIBUTION }}
|
||||
JAVA_VERSION: ${{ inputs.JAVA_VERSION }}
|
||||
secrets: inherit
|
||||
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
.idea/
|
||||
16
README.md
Normal file
16
README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# Hlæja Common Workflows
|
||||
|
||||
GitHub actions [reusing workflows](https://docs.github.com/en/actions/using-workflows/reusing-workflows).
|
||||
Rules and stuff say keep workflow in `/.gite/workflow`.
|
||||
|
||||
## Actions secrets and variables.
|
||||
|
||||
### Secrets
|
||||
|
||||
- CI_BOT_USERNAME = gitea_username
|
||||
- CI_BOT_TOKEN = gitea_token
|
||||
|
||||
### Variables
|
||||
|
||||
- BOT_NAME = Hlæja
|
||||
- BOT_EMAIL = noreply@lulz.ltd
|
||||
Reference in New Issue
Block a user