Skip to content

Commit

Permalink
Automate branching project
Browse files Browse the repository at this point in the history
  • Loading branch information
johnaohara committed Jun 14, 2024
1 parent cf4fece commit ad9135a
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 90 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Create New Stable Branch

on:
workflow_dispatch:

jobs:
build:
name: Create new branch
env:
ENVIRONMENT: CI
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: 17
- name: install yq
run: wget https://github.com/mikefarah/yq/releases/download/v4.2.0/yq_linux_amd64 -O ~/yq && chmod +x ~/yq
- name: Maven Version
run: mvn --version
# Retrieve current version from the root pom
- name: Get version
run: |
PROJECT_VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:3.4.0:evaluate -Dexpression=project.version -q -DforceStdout)
echo PROJECT_VERSION=${PROJECT_VERSION} >> $GITHUB_ENV
echo CUR_VERSION=$(echo ${PROJECT_VERSION} | awk -F'.' '{print $1"."$2+0"."$3}' | sed s/[.]$//) >> $GITHUB_ENV
echo NEXT_VERSION=$(echo ${PROJECT_VERSION} | awk -F'.' '{print $1"."$2+1"."$3}' | sed s/[.]$//) >> $GITHUB_ENV
- name: Create branch ${{ env.CUR_VERSION }}
run: git branch ${{ env.CUR_VERSION }} master
- name: Bump next version ${{ env.NEXT_VERSION }}-SNAPSHOT
run: mvn versions:set -DnewVersion=${{ env.NEXT_VERSION }}-SNAPSHOT
- name: Set major version ${{ env.NEXT_VERSION }}
run: mvn versions:set-property -Dproperty=major-version -DnewVersion=${{ env.NEXT_VERSION }}
- name: Update main workflow
run: ~/yq -i e '.on.push.branches |= [ "master", '${{ env.NEXT_VERSION }}' ]' .github/workflows/main.yml
- name: Update Notify clients workflow
run: ~/yq -i e '.on.push.branches |= [ "master", '${{ env.NEXT_VERSION }}' ]' .github/workflows/notify-clients.yml
- name: Commit main branch changes
run: |
git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}"
git config --global user.email "username@users.noreply.github.com"
git commit -a -m "Next is ${{ env.NEXT_VERSION }}"
- name: push branches
run: |
git push master
git push ${{ env.CUR_VERSION }}
93 changes: 42 additions & 51 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,67 +1,58 @@
name: Java CI with Maven

on:
push:
branches: [ master, 0.12.x, 0.13.x ]
tags: [ "*" ]
pull_request:
workflow_dispatch:

jobs:
build:
name: Build on ${{ matrix.os.name }}
strategy:
matrix:
os:
- {
name: "windows-latest",
build-options: "\"-Dquarkus.container-image.build=false\" -pl '!horreum-client, !horreum-integration-tests' -DskipITs -DskipTests"
}
- {
name: "ubuntu-latest",
build-options: ""
}
- {name: "windows-latest", build-options: "\"-Dquarkus.container-image.build=false\" -pl '!horreum-client, !horreum-integration-tests' -DskipITs -DskipTests"}
- {name: "ubuntu-latest", build-options: ""}
env:
ENVIRONMENT: CI
runs-on: ${{ matrix.os.name }}

runs-on: ${{ matrix.os.name }}
steps:
- uses: actions/checkout@v4
- name: Reclaim Disk Space
run: .github/scripts/ci-prerequisites.sh
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: 17
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Install Hunter
run: pipx install git+https://github.com/datastax-labs/hunter.git
- name: Maven Version
run: mvn --version
- name: Build and Test
run: mvn clean install -B --file pom.xml ${{ matrix.os.build-options }} -P ci
- name: Check uncommitted changes
if: matrix.os.name == 'ubuntu-latest'
run: |
clean=$(git status --porcelain)
if [[ -z "$clean" ]]; then
echo "Empty git status --porcelain: $clean"
else
echo "Uncommitted file changes detected: $clean"
git diff
exit 1
fi
- name: Upload artifact for failed workflow
if: failure()
uses: actions/upload-artifact@v4
with:
name: test logs
path: |
*/target/surefire-reports/*
test-suite/target/hyperfoil/*.log
- uses: actions/checkout@v4
- name: Reclaim Disk Space
run: .github/scripts/ci-prerequisites.sh
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: 17
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Install Hunter
run: pipx install git+https://github.com/datastax-labs/hunter.git
- name: Maven Version
run: mvn --version
- name: Build and Test
run: mvn clean install -B --file pom.xml ${{ matrix.os.build-options }} -P ci
- name: Check uncommitted changes
if: matrix.os.name == 'ubuntu-latest'
run: |
clean=$(git status --porcelain)
if [[ -z "$clean" ]]; then
echo "Empty git status --porcelain: $clean"
else
echo "Uncommitted file changes detected: $clean"
git diff
exit 1
fi
- name: Upload artifact for failed workflow
if: failure()
uses: actions/upload-artifact@v4
with:
name: test logs
path: |
*/target/surefire-reports/*
test-suite/target/hyperfoil/*.log
3 changes: 0 additions & 3 deletions .github/workflows/notify-clients.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: Notify clients

on:
push:
branches:
Expand All @@ -8,7 +7,6 @@ on:
- 0.13.x
paths:
- "docs/site/content/en/openapi/openapi.yaml"

jobs:
clients-notification:
runs-on: ubuntu-latest
Expand All @@ -19,7 +17,6 @@ jobs:
repository: Hyperfoil/horreum-client-golang
- name: Python
repository: Hyperfoil/horreum-client-python

steps:
- name: Extract trigger branch
id: extractor
Expand Down
36 changes: 5 additions & 31 deletions docs/RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,52 +99,28 @@ Generate release notes:

https://github.com/Hyperfoil/Horreum/releases

## After the release

The version identifier for a release is from

```
./horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/Version.java
```

so that file needs to be updated after a release.

## Creating a new Stable Branch

To create a new stable branch, for example creating a `0.11.x` branch, first create the branch locally:

```bash
git checkout origin/master
git checkout -b 0.11.x
git checkout origin/master
git branch 0.11.x master
```

Update the new main branch to the next snapshot version:

```bash
mvn versions:set -DnewVersion=0.12-SNAPSHOT
```

Update the openapi version in the `horreum-api/pom.xml` file:

```xml
<openapi-version>0.12</openapi-version>
```

Update the `horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/Version.java` file

```java
public class Version {
public static final String VERSION = "0.12.0";
}
mvn versions:set-property -Dproperty=major-version -DnewVersion=0.12
```

Update the Github actions to build the new stable branch for each push:

```yaml
on:
push:
branches: [ master, 0.12.x ]
branches: [ master, 0.11.x ]
tags: [ "*" ]
pull_request:
workflow_dispatch:
Expand All @@ -154,9 +130,7 @@ Update the Github action to notify openapi changes to the clients on every stabl
```yaml
on:
push:
branches:
- main
- 0.12.x
branches: [ master, 0.11.x ]
paths:
- "docs/site/content/en/openapi/openapi.yaml"
```
Expand All @@ -171,7 +145,7 @@ git commit -m "Next is 0.12"
Push the new branch and main branch to github:

```bash
git push origin 0.12.x
git push origin 0.11.x
git push origin master
```

23 changes: 20 additions & 3 deletions horreum-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<openapi-version>0.14</openapi-version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -65,7 +64,7 @@
</goals>
<configuration>
<configProperties>${basedir}/src/main/resources/application.properties</configProperties>
<infoVersion>${openapi-version}</infoVersion>
<infoVersion>${major-version}</infoVersion>
<scanPackages>
io.hyperfoil.tools.horreum.api,
io.hyperfoil.tools.horreum.api.alerting,
Expand Down Expand Up @@ -94,7 +93,7 @@
</goals>
<configuration>
<configProperties>${basedir}/src/main/resources/application.properties</configProperties>
<infoVersion>${openapi-version}</infoVersion>
<infoVersion>${major-version}</infoVersion>
<scanPackages>
io.hyperfoil.tools.horreum.api,
io.hyperfoil.tools.horreum.api.alerting,
Expand Down Expand Up @@ -207,6 +206,24 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>write-project-properties</goal>
</goals>
<configuration>
<outputFile>
${project.build.outputDirectory}/build.properties
</outputFile>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
package io.hyperfoil.tools.horreum.api;

import io.quarkus.logging.Log;

import java.io.IOException;
import java.util.Properties;

public class Version {
public static final String VERSION = "0.14.0";
public static final String getVersion(){
final Properties properties = new Properties();
try {
properties.load(Version.class.getClassLoader().getResourceAsStream("build.properties"));
return properties.getProperty("horreum.version");
} catch (IOException e) {
Log.error("Failed to load version.properties",e);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public KeycloakConfig keycloak() {
@Override
public VersionInfo version() {
VersionInfo info = new VersionInfo();
info.version = Version.VERSION;
info.version = Version.getVersion();
info.startTimestamp = startTimestamp;
info.privacyStatement = privacyStatement.orElse(null);
return info;
Expand Down
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
<dev.images.postgres>postgres:16</dev.images.postgres>
<dev.images.keycloak>quay.io/keycloak/keycloak:23.0.3</dev.images.keycloak>

<horreum.version>${project.version}</horreum.version>
<major-version>0.14</major-version>

</properties>

<developers>
Expand Down

0 comments on commit ad9135a

Please sign in to comment.