Skip to content
Open
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
20 changes: 20 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 2
updates:
- package-ecosystem: "maven"
directories:
- "stack-clients"
- "stack-data-uploader"
- "stack-manager"
schedule:
interval: "weekly"
- package-ecosystem: "docker"
directories:
- "stack-clients"
- "stack-data-uploader"
- "stack-manager"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
57 changes: 57 additions & 0 deletions .github/scripts/check-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

VERSION=$(cat -s "VERSION" 2>/dev/null)
MAIN_VERSION=$(curl -s "https://raw.githubusercontent.com/TheWorldAvatar/stack/main/VERSION")

if [ "$VERSION" == "" ]; then
echo -e "\e[31mError\e[0m: VERSION file is empty. Please ensure the correct version number is written here. Version currently on main is: $MAIN_VERSION"
exit 1
fi
echo "Version set in this PR: $VERSION"
echo "Version on main: $MAIN_VERSION"

# Get the VERSION file from the main branch of the repo, check that this new version is updated ie does not match
if [ "$VERSION" == "$MAIN_VERSION" ]; then
echo -e "\e[31mError\e[0m: VERSION specified on this branch matches that on main. Update the VERSION file before merging."
exit 1
fi

# Check that there's no -SNAPSHOT qualifier and that the version follows the semantic versioning pattern
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo -e "\e[31mError\e[0m: VERSION must follow the semantic versioning pattern x.y.z where x, y, and z are numbers"
exit 1
fi

# Check that the new version is incremented correctly
IFS='.' read -r -a MAIN_VERSION_PARTS <<<"$MAIN_VERSION"
IFS='.' read -r -a VERSION_PARTS <<<"$VERSION"

# Check for valid patch increment (x.y.z+1)
PATCH_INCREMENT=$((MAIN_VERSION_PARTS[2] + 1))
if [ "${VERSION_PARTS[0]}" -eq "${MAIN_VERSION_PARTS[0]}" ] &&
[ "${VERSION_PARTS[1]}" -eq "${MAIN_VERSION_PARTS[1]}" ] &&
[ "${VERSION_PARTS[2]}" -eq "$PATCH_INCREMENT" ]; then
VALID_INCREMENT=true
fi

# Check for valid minor increment (x.y+1.0)
MINOR_INCREMENT=$((MAIN_VERSION_PARTS[1] + 1))
if [ "${VERSION_PARTS[0]}" -eq "${MAIN_VERSION_PARTS[0]}" ] &&
[ "${VERSION_PARTS[1]}" -eq "$MINOR_INCREMENT" ] &&
[ "${VERSION_PARTS[2]}" -eq 0 ]; then
VALID_INCREMENT=true
fi

# Check for valid major increment (x+1.0.0)
MAJOR_INCREMENT=$((MAIN_VERSION_PARTS[0] + 1))
if [ "${VERSION_PARTS[0]}" -eq "$MAJOR_INCREMENT" ] &&
[ "${VERSION_PARTS[1]}" -eq 0 ] &&
[ "${VERSION_PARTS[2]}" -eq 0 ]; then
VALID_INCREMENT=true
fi

if [ "$VALID_INCREMENT" != true ]; then
echo -e "\e[31mError\e[0m: VERSION must be properly incremented. Valid increments are: patch (x.y.z+1), minor (x.y+1.0), or major (x+1.0.0)"
exit 1
fi
exit 0
64 changes: 64 additions & 0 deletions .github/scripts/increment-package-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

# Update image version in docker-compose.yml
DOCKER_COMPOSE_CLIENT="stack-clients/docker-compose.yml"
DOCKER_COMPOSE_MANAGER="stack-manager/docker-compose.yml"
DOCKER_COMPOSE_UPLOADER="stack-data-uploader/docker-compose.yml"

POM_CLIENT="stack-clients/pom.xml"
POM_MANAGER="stack-manager/pom.xml"
POM_UPLOADER="stack-data-uploader/pom.xml"

POM_FILES=("$POM_CLIENT" "$POM_MANAGER" "$POM_UPLOADER")
COMPOSE_FILES=("$DOCKER_COMPOSE_CLIENT" "$DOCKER_COMPOSE_MANAGER" "$DOCKER_COMPOSE_UPLOADER")

for compose in "${COMPOSE_FILES[@]}"; do
if [ -f "$compose" ]; then
sed -i.bak -E "s|(image: .+:).+|\1$VERSION|" "$compose" && rm "$compose.bak"
echo "Updated image version in $compose to $VERSION"
else
echo -e "\e[31mError\e[0m: $compose not found"
exit 1
fi
done

for POM in "${POM_FILES[@]}"; do
if [ -f "$POM" ]; then
ARTIFACT_ID=$(basename "$(dirname "$POM")")
# Update the main <version> for the artifact
awk -v ver="$VERSION" -v aid="$ARTIFACT_ID" '
BEGIN { found=0 }
/<artifactId>/ {
if ($0 ~ "<artifactId>" aid "</artifactId>") found=1
else found=0
}
found && /<version>[0-9]+\.[0-9]+\.[0-9]+<\/version>/ && !done[aid] {
sub(/<version>[0-9]+\.[0-9]+\.[0-9]+<\/version>/, "<version>" ver "</version>")
done[aid]=1
}
{ print }
' "$POM" > "$POM.tmp" && mv "$POM.tmp" "$POM"

# If this is stack-manager or stack-data-uploader, update stack-clients dependency version robustly
if [[ "$ARTIFACT_ID" == "stack-manager" || "$ARTIFACT_ID" == "stack-data-uploader" ]]; then
awk -v ver="$VERSION" '
BEGIN { in_dep=0; found=0 }
/<dependency>/ { in_dep=1; found=0 }
in_dep && /<artifactId>stack-clients<\/artifactId>/ { found=1 }
in_dep && found && /<version>[0-9]+\.[0-9]+\.[0-9]+<\/version>/ {
sub(/<version>[0-9]+\.[0-9]+\.[0-9]+<\/version>/, "<version>" ver "</version>")
found=0
}
/<\/dependency>/ { in_dep=0; found=0 }
{ print }
' "$POM" > "$POM.tmp" && mv "$POM.tmp" "$POM"
fi

echo "Updated version in $POM to $VERSION"
else
echo -e "\e[31mError\e[0m: $POM not found"
exit 1
fi
done

echo -e "\e[32mVersion incremented\e[0m, compose file updated. Next step in this action will commit the changes"
60 changes: 60 additions & 0 deletions .github/workflows/check-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Check and Consolidate Version

on:
pull_request:
branches:
- main
paths:
- stack-clients/src**
- stack-manager/src**
- stack-data-uploader/src**

jobs:
check-version:
if: github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest

permissions:
contents: write

steps:
- name: Check out repository
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Set up Git
run: |
git config --global user.email "stack-bot@noreply.theworldavatar.io"
git config --global user.name "twa-stack-bot"

- name: Check VERSION file
run: |
chmod +x .github/scripts/check-version.sh
.github/scripts/check-version.sh

- name: Save version to github environment
run: echo "VERSION=$(cat VERSION)" >> $GITHUB_ENV

- name: Set VERSION in pom.xml and docker-compose.yml
run: |
chmod +x .github/scripts/increment-package-version.sh
.github/scripts/increment-package-version.sh

- name: Check for changes
id: changes
run: |
git checkout ${{ github.head_ref }}
git add stack-clients/pom.xml stack-manager/pom.xml stack-data-uploader/pom.xml stack-clients/docker-compose.yml stack-manager/docker-compose.yml stack-data-uploader/docker-compose.yml
if ! git diff-index --quiet HEAD --; then
echo "::set-output name=changes::changes"
fi

- name: Push auto incremented version changes
if: steps.changes.outputs.changes == 'changes'
run: |
git commit -m "Update version to $VERSION in package files"
git push origin ${{ github.head_ref }}

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111 changes: 111 additions & 0 deletions .github/workflows/docker-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Docker Image CI

on:
push:
branches:
- main
paths:
- code/**
workflow_dispatch:
pull_request:
branches:
- main

permissions:
contents: write
packages: write

jobs:
build-and-push-image:
runs-on: ubuntu-latest

permissions:
packages: write

steps:
- name: Check out repository
uses: actions/checkout@v4

- uses: s4u/maven-settings-action@v3.1.0
with:
servers: |
[{
"id": "github",
"username": "${{ github.actor }}",
"password": "${{ secrets.GHCR_PAT }}"
}]

- name: Set version variables from file
id: read-version
run: |
if [ -f VERSION ]; then
VERSION=$(cat VERSION)
else
echo "VERSION file not found"
exit 1
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "MAJOR=$(echo $VERSION | cut -d. -f1)" >> $GITHUB_ENV
echo "MINOR=$(echo $VERSION | cut -d. -f1).$(echo $VERSION | cut -d. -f2)" >> $GITHUB_ENV

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

- name: Build with Maven (stack-clients)
working-directory: stack-clients
run: mvn clean package --update-snapshots -DskipTests

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

- name: Build stack clients docker image and push to ghcr
uses: docker/build-push-action@v6
with:
context: stack-clients
file: stack-clients/Dockerfile
push: true
tags: |
ghcr.io/theworldavatar/stack-clients:latest
ghcr.io/theworldavatar/stack-clients:${{ env.VERSION }}
ghcr.io/theworldavatar/stack-clients:${{ env.MAJOR }}
ghcr.io/theworldavatar/stack-clients:${{ env.MINOR }}

- name: Build with Maven (stack-manager)
working-directory: stack-manager
run: mvn clean package --update-snapshots -DskipTests

- name: Build stack manager docker image and push to ghcr
uses: docker/build-push-action@v6
with:
context: stack-manager
file: stack-manager/Dockerfile
push: true
tags: |
ghcr.io/theworldavatar/stack-manager:latest
ghcr.io/theworldavatar/stack-manager:${{ env.VERSION }}
ghcr.io/theworldavatar/stack-manager:${{ env.MAJOR }}
ghcr.io/theworldavatar/stack-manager:${{ env.MINOR }}

- name: Build with Maven (stack-data-uploader)
working-directory: stack-data-uploader
run: mvn clean package --update-snapshots -DskipTests

- name: Build stack data uploader docker image and push to ghcr
uses: docker/build-push-action@v6
with:
context: stack-data-uploader
file: stack-data-uploader/Dockerfile
push: true
tags: |
ghcr.io/theworldavatar/stack-data-uploader:latest
ghcr.io/theworldavatar/stack-data-uploader:${{ env.VERSION }}
ghcr.io/theworldavatar/stack-data-uploader:${{ env.MAJOR }}
ghcr.io/theworldavatar/stack-data-uploader:${{ env.MINOR }}
48 changes: 48 additions & 0 deletions .github/workflows/tag-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Tag Version

on:
push:
branches:
- main
workflow_dispatch:

jobs:
tag-version:
runs-on: ubuntu-latest

permissions:
contents: write

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Git
run: |
git config --global user.email "stack-bot@noreply.theworldavatar.io"
git config --global user.name "twa-stack-bot"

- name: Save version to environment
run: |
if [ -f VERSION ]; then
echo "VERSION=$(cat VERSION)" >> $GITHUB_ENV
else
echo "VERSION file not found" && exit 1
fi

- name: Check if tag exists
id: check_tag
run: |
if git rev-parse "v${{ env.VERSION }}" >/dev/null 2>&1; then
echo "TAG_EXISTS=true" >> $GITHUB_ENV
else
echo "TAG_EXISTS=false" >> $GITHUB_ENV
fi

- name: Create tag
if: env.TAG_EXISTS == 'false'
run: |
git tag -a "v${{ env.VERSION }}" -m "Version ${{ env.VERSION }}"
git push origin "v${{ env.VERSION }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "bashdb",
"request": "launch",
"name": "Bash-Debug (select script from list of sh files)",
"cwd": "${workspaceFolder}",
"program": "${command:SelectScriptName}",
"args": []
}
]
}
Loading
Loading