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
6 changes: 6 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ jobs:
- name: Checkout codebase
uses: actions/checkout@v3

# Generate deployed-version info (git hash, commit date, build run) into a file
# that the backend exposes as `buildVersion` on the REST root endpoint (issue #813).
# Must run before the Docker build so the file is included in the image.
- name: Add version
run: python scripts/sourceversion.py ${{ github.server_url }}/${{ github.repository }}/actions/runs/ ${{ github.run_id }} > dspace/config/VERSION_D.txt

# https://github.com/docker/setup-buildx-action
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

import static org.dspace.app.util.Util.getSourceVersion;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import org.apache.commons.lang3.StringUtils;
import org.dspace.app.rest.model.RootRest;
import org.dspace.services.ConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -29,6 +34,37 @@ public RootRest convert() {
rootRest.setDspaceUI(configurationService.getProperty("dspace.ui.url"));
rootRest.setDspaceServer(configurationService.getProperty("dspace.server.url"));
rootRest.setDspaceVersion("DSpace " + getSourceVersion());
rootRest.setBuildVersion(getBuildVersion());
return rootRest;
}

/**
* Read the build version from the `build.version.file.path` property
*
* @return content of the version file
*/
private String getBuildVersion() {
String bVersionFilePath = configurationService.getProperty("build.version.file.path");

if (StringUtils.isBlank(bVersionFilePath)) {
return "Unknown";
}

StringBuilder buildVersion = new StringBuilder();
try {
FileReader fileReader = new FileReader(bVersionFilePath);
BufferedReader bufferedReader = new BufferedReader(fileReader);

String line;
// Read each line from the file until the end of the file is reached
while ((line = bufferedReader.readLine()) != null) {
buildVersion.append(line);
}

} catch (IOException e) {
// Empty - do not log anything
}

return buildVersion.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class RootRest extends RestAddressableModel {
private String dspaceName;
private String dspaceServer;
private String dspaceVersion;
private String buildVersion;

public String getCategory() {
return CATEGORY;
Expand Down Expand Up @@ -67,6 +68,14 @@ public void setDspaceVersion(String dspaceVersion) {
this.dspaceVersion = dspaceVersion;
}

public String getBuildVersion() {
return buildVersion;
}

public void setBuildVersion(String buildVersion) {
this.buildVersion = buildVersion;
}

@Override
public boolean equals(Object object) {
return (object instanceof RootRest &&
Expand All @@ -76,6 +85,7 @@ public boolean equals(Object object) {
.append(this.getDspaceUI(), ((RootRest) object).getDspaceUI())
.append(this.getDspaceName(), ((RootRest) object).getDspaceName())
.append(this.getDspaceServer(), ((RootRest) object).getDspaceServer())
.append(this.getBuildVersion(), ((RootRest) object).getBuildVersion())
.isEquals());
}

Expand All @@ -88,6 +98,7 @@ public int hashCode() {
.append(this.getDspaceName())
.append(this.getDspaceUI())
.append(this.getDspaceServer())
.append(this.getBuildVersion())
.toHashCode();
}
}
Empty file added dspace/config/VERSION_D.txt
Empty file.
6 changes: 5 additions & 1 deletion dspace/config/clarin-dspace.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,8 @@ identifiers.item-status.register-doi = true

##### Dataquest URL - sing in the footer #####
themed.by.url = https://www.dataquest.sk/dspace
themed.by.company.name = dataquest s.r.o.
themed.by.company.name = dataquest s.r.o.

### The build version is stored in the specific file (issue #813) ###
### Exposed as `buildVersion` on the REST root endpoint (/server/api). ###
build.version.file.path = ${dspace.dir}/config/VERSION_D.txt
22 changes: 22 additions & 0 deletions scripts/sourceversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import subprocess
import sys
from datetime import datetime, timezone

def get_time_in_timezone(zone: str = "Europe/Bratislava"):
try:
from zoneinfo import ZoneInfo
my_tz = ZoneInfo(zone)
except Exception as e:
my_tz = timezone.utc
return datetime.now(my_tz)


if __name__ == '__main__':
ts = get_time_in_timezone()
print(f"This info was generated on: {ts.strftime('%Y-%m-%d %H:%M:%S %Z%z')}")

cmd = 'git log -1 --pretty=format:"Git hash: %H Date of commit: %ai"'
subprocess.check_call(cmd, shell=True)

link = sys.argv[1] + sys.argv[2]
print(' Build run: ' + link + ' ')
Loading