Skip to content

Commit e355ca7

Browse files
authored
Merge pull request #39 from mcanoy/versioning
Versioning
2 parents aeddc38 + 1d51478 commit e355ca7

File tree

8 files changed

+98
-2
lines changed

8 files changed

+98
-2
lines changed

.github/workflows/ci-cd.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Java CI
1+
name: Container Build
22

33
on:
44
push:
@@ -18,6 +18,18 @@ jobs:
1818
java-version: 13.0.1
1919
- name: Build with Maven & Quarkus
2020
run: mvn test
21+
- name: Find and Replace Commit
22+
uses: jacobtomlinson/[email protected]
23+
with:
24+
find: "###GIT_COMMIT###"
25+
replace: "${{ github.sha }}"
26+
include: ".s2i"
27+
- name: Find and Replace Tag
28+
uses: jacobtomlinson/[email protected]
29+
with:
30+
find: "###GIT_TAG###"
31+
replace: "${{ github.ref }}"
32+
include: ".s2i"
2133
- uses: redhat-cop/github-actions/s2i@v2
2234
with:
2335
base: registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift:1.8

.github/workflows/pull-request-checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Java CI
1+
name: PR check
22

33
on:
44
- pull_request

.s2i/environment

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
GIT_API_GIT_COMMIT=###GIT_COMMIT###
2+
GIT_API_GIT_TAG=###GIT_TAG###

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
![Container Build](https://github.com/rht-labs/open-management-portal-git-api/workflows/Container%20Build/badge.svg)
2+
13
# open-management-portal-git-api project
24

35
This project uses Quarkus, the Supersonic Subatomic Java Framework.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.redhat.labs.omp.models;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
@Data
9+
@Builder
10+
@NoArgsConstructor
11+
@AllArgsConstructor
12+
public class Version {
13+
14+
private String gitCommit;
15+
private String gitTag;
16+
17+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.redhat.labs.omp.resource;
2+
3+
import javax.ws.rs.Consumes;
4+
import javax.ws.rs.GET;
5+
import javax.ws.rs.Path;
6+
import javax.ws.rs.Produces;
7+
import javax.ws.rs.core.MediaType;
8+
9+
import org.eclipse.microprofile.config.inject.ConfigProperty;
10+
import org.eclipse.microprofile.metrics.annotation.Counted;
11+
import org.eclipse.microprofile.metrics.annotation.Timed;
12+
13+
import com.redhat.labs.omp.models.Version;
14+
15+
/**
16+
* Provides version information via api. Expected to come from the container in a prod env
17+
* @author mcanoy
18+
*
19+
*/
20+
@Path("/api/v1/version")
21+
@Produces(MediaType.APPLICATION_JSON)
22+
@Consumes(MediaType.APPLICATION_JSON)
23+
public class VersionResource {
24+
25+
@ConfigProperty(name = "git.commit")
26+
String gitCommit;
27+
28+
@ConfigProperty(name = "git.tag")
29+
String gitTag;
30+
31+
@GET
32+
@Timed(name="versionResourceTimer")
33+
@Counted(name="versionResourceCounter")
34+
public Version getVersion() {
35+
return new Version(gitCommit, gitTag);
36+
}
37+
}

src/main/resources/application.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ residenciesParentRepositoryId=${RESIDENCIES_PARENT_REPOSITORIES_ID:2}
3737
gitlab.api/mp-rest/url=${GITLAB_API_URL:https://acmegit.com}
3838
deployKey=${DEPLOY_KEY:0}
3939

40+
git.commit=${GIT_API_GIT_COMMIT:not.set}
41+
git.tag=${GIT_API_GIT_TAG:not.set}
42+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.redhat.labs.omp.resource;
2+
3+
import static io.restassured.RestAssured.given;
4+
import static org.hamcrest.CoreMatchers.is;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
import io.quarkus.test.junit.QuarkusTest;
9+
10+
@QuarkusTest
11+
public class VersionResourceTest {
12+
13+
@Test
14+
public void testValidResourceVersion() {
15+
given()
16+
.when()
17+
.get("/api/v1/version")
18+
.then()
19+
.statusCode(200)
20+
.body(is("{\"git_commit\":\"not.set\",\"git_tag\":\"not.set\"}"));
21+
}
22+
}
23+

0 commit comments

Comments
 (0)