chore: Update the build process to refer the Appsmith version from the info.json in all build artifacts (#29903)

Fixes #29623

Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
This commit is contained in:
Abhijeet 2024-01-12 19:44:58 +05:30 committed by GitHub
parent 7fcbb44d7d
commit efc303e760
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 43 deletions

View File

@ -41,7 +41,7 @@ jobs:
github.event_name == 'push' || github.event_name == 'push' ||
github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_dispatch' ||
github.event_name == 'repository_dispatch' || github.event_name == 'repository_dispatch' ||
github.event_name == 'schedule' github.event_name == 'schedule'
defaults: defaults:
run: run:
working-directory: app/client working-directory: app/client
@ -242,13 +242,6 @@ jobs:
if [[ "${{github.ref}}" == "refs/heads/release" ]]; then if [[ "${{github.ref}}" == "refs/heads/release" ]]; then
echo "REACT_APP_ENVIRONMENT=STAGING" >> $GITHUB_OUTPUT echo "REACT_APP_ENVIRONMENT=STAGING" >> $GITHUB_OUTPUT
fi fi
# Since this is an unreleased build, we set the version to incremented version number with
# a `-SNAPSHOT` suffix.
latest_released_version="$(git ls-remote --tags --sort=-v:refname "$(git remote | head -1)" 'v*' | awk -F/ '{print $NF; exit}')"
echo "latest_released_version = $latest_released_version"
next_version="$(echo "$latest_released_version" | awk -F. -v OFS=. '{ $NF++; print }')"
echo "next_version = $next_version"
echo version=$next_version-SNAPSHOT >> $GITHUB_OUTPUT
# We burn React environment & the Segment analytics key into the build itself. # We burn React environment & the Segment analytics key into the build itself.
# This is to ensure that we don't need to configure it in each installation # This is to ensure that we don't need to configure it in each installation
@ -263,8 +256,6 @@ jobs:
REACT_APP_ENVIRONMENT=${{steps.vars.outputs.REACT_APP_ENVIRONMENT}} \ REACT_APP_ENVIRONMENT=${{steps.vars.outputs.REACT_APP_ENVIRONMENT}} \
REACT_APP_FUSIONCHARTS_LICENSE_KEY=${{ secrets.APPSMITH_FUSIONCHARTS_LICENSE_KEY }} \ REACT_APP_FUSIONCHARTS_LICENSE_KEY=${{ secrets.APPSMITH_FUSIONCHARTS_LICENSE_KEY }} \
SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }} \ SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }} \
REACT_APP_VERSION_ID=${{ steps.vars.outputs.version }} \
REACT_APP_VERSION_RELEASE_DATE=$(date -u '+%Y-%m-%dT%H:%M:%SZ') \
REACT_APP_VERSION_EDITION="Community" \ REACT_APP_VERSION_EDITION="Community" \
yarn build yarn build

View File

@ -145,23 +145,6 @@ jobs:
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2 restore-keys: ${{ runner.os }}-m2
# Here, the GITHUB_REF is of type /refs/head/<branch_name>. We extract branch_name from this by removing the
# first 11 characters. This can be used to build images for several branches
# Since this is an unreleased build, we get the latest released version number, increment the minor number in it,
# append a `-SNAPSHOT` at it's end to prepare the snapshot version number. This is used as the project's version.
- name: Get the version to tag the Docker image
if: steps.run_result.outputs.run_result != 'success' && (steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')
id: vars
run: |
# Since this is an unreleased build, we set the version to incremented version number with a
# `-SNAPSHOT` suffix.
latest_released_version="$(git ls-remote --tags --sort=-v:refname "$(git remote | head -1)" 'v*' | awk -F/ '{print $NF; exit}')"
echo "latest_released_version = $latest_released_version"
next_version="$(echo "$latest_released_version" | awk -F. -v OFS=. '{ $NF++; print }')"
echo "next_version = $next_version"
echo version=$next_version-SNAPSHOT >> $GITHUB_OUTPUT
echo tag=$(echo ${GITHUB_REF:11}) >> $GITHUB_OUTPUT
# Build the code # Build the code
- name: Build - name: Build
if: steps.run_result.outputs.run_result != 'success' && (steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule') if: steps.run_result.outputs.run_result != 'success' && (steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')
@ -176,10 +159,6 @@ jobs:
APPSMITH_ENVFILE_PATH: /tmp/dummy.env APPSMITH_ENVFILE_PATH: /tmp/dummy.env
APPSMITH_VERBOSE_LOGGING_ENABLED: false APPSMITH_VERBOSE_LOGGING_ENABLED: false
run: | run: |
mvn --batch-mode versions:set \
-DnewVersion=${{ steps.vars.outputs.version }} \
-DgenerateBackupPoms=false \
-DprocessAllModules=true
./build.sh -DskipTests ./build.sh -DskipTests
# Test the code # Test the code
@ -246,7 +225,7 @@ jobs:
if [ "$reponame" = "appsmith" ]; then export repodir="CE"; fi if [ "$reponame" = "appsmith" ]; then export repodir="CE"; fi
if [ "$reponame" = "appsmith-ee" ]; then export repodir="EE"; fi if [ "$reponame" = "appsmith-ee" ]; then export repodir="EE"; fi
cd cibuildcache/$repodir/release/server cd cibuildcache/$repodir/release/server
git lfs pull ./server.jar git lfs pull ./server.jar
mv ./server.jar ../../../../../server.jar mv ./server.jar ../../../../../server.jar
cd ../../../../../ cd ../../../../../
tar -xzvf ./server.jar tar -xzvf ./server.jar

View File

@ -1,9 +1,11 @@
package com.appsmith.server; package com.appsmith.server;
import com.appsmith.server.configurations.ProjectProperties;
import io.micrometer.observation.ObservationRegistry; import io.micrometer.observation.ObservationRegistry;
import io.micrometer.observation.aop.ObservedAspect; import io.micrometer.observation.aop.ObservedAspect;
import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.Banner; import org.springframework.boot.Banner;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -16,14 +18,28 @@ import static com.appsmith.server.constants.EnvVariables.APPSMITH_NEW_RELIC_ACCO
@SpringBootApplication @SpringBootApplication
@EnableScheduling @EnableScheduling
@Slf4j
public class ServerApplication { public class ServerApplication {
private final ProjectProperties projectProperties;
public ServerApplication(ProjectProperties projectProperties) {
this.projectProperties = projectProperties;
printBuildInfo();
}
public static void main(String[] args) { public static void main(String[] args) {
new SpringApplicationBuilder(ServerApplication.class) new SpringApplicationBuilder(ServerApplication.class)
.bannerMode(Banner.Mode.OFF) .bannerMode(Banner.Mode.OFF)
.run(args); .run(args);
} }
private void printBuildInfo() {
String version = projectProperties.getVersion();
String commitId = projectProperties.getCommitSha();
log.info("Application started with build version {}, and commitSha {}", version, commitId);
}
@Bean @Bean
public OpenTelemetry openTelemetry() { public OpenTelemetry openTelemetry() {
String instanceName = String instanceName =

View File

@ -1,23 +1,40 @@
package com.appsmith.server.configurations; package com.appsmith.server.configurations;
import com.appsmith.server.dtos.BuildInfo;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter; import lombok.Getter;
import org.springframework.beans.factory.annotation.Value; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
/** import java.io.IOException;
* Properties in this configuration object are loaded from the `pom.properties` file that is generated by Maven import java.nio.file.Files;
* automatically. This file is included in the final JAR file at import java.nio.file.Path;
* `META-INF/maven/{project.group}/{project.name}/pom.properties`. Outside the JAR file, it can be accessed from import java.nio.file.Paths;
* `target/maven-archiver/pom.properties`.
*/
@Configuration @Configuration
@PropertySource(value = "classpath:META-INF/maven/com.appsmith/server/pom.properties", ignoreResourceNotFound = true)
@Getter @Getter
@Slf4j
public class ProjectProperties { public class ProjectProperties {
private static final String INFO_JSON_PATH = "/opt/appsmith/info.json";
private static final ObjectMapper objectMapper = new ObjectMapper();
public static final String EDITION = "CE"; public static final String EDITION = "CE";
private String version = "UNKNOWN";
private String commitSha = "UNKNOWN";
@Value("${version:UNKNOWN}") public ProjectProperties() {
private String version; try {
Path infoJsonPath = Paths.get(INFO_JSON_PATH);
if (Files.exists(infoJsonPath)) {
String jsonContent = Files.readString(infoJsonPath);
// Parse JSON content using the AppsmithInfo class
BuildInfo buildInfo = objectMapper.readValue(jsonContent, BuildInfo.class);
version = buildInfo.getVersion();
commitSha = buildInfo.getCommitSha();
}
} catch (IOException e) {
// Ignore the exception and return "UNKNOWN" as the version
log.debug("Error reading version from info.json {}", e.getMessage());
}
}
} }

View File

@ -0,0 +1,16 @@
package com.appsmith.server.dtos;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
/**
* This class is used to parse the JSON content of the info.json file. This file is generated during the build process
* and contains the version of the Appsmith server.
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class BuildInfo {
private String version;
private String commitSha;
}

View File

@ -1,6 +1,7 @@
package com.appsmith.server.controllers; package com.appsmith.server.controllers;
import com.appsmith.server.applications.base.ApplicationService; import com.appsmith.server.applications.base.ApplicationService;
import com.appsmith.server.configurations.ProjectProperties;
import com.appsmith.server.configurations.RedisTestContainerConfig; import com.appsmith.server.configurations.RedisTestContainerConfig;
import com.appsmith.server.configurations.SecurityTestConfig; import com.appsmith.server.configurations.SecurityTestConfig;
import com.appsmith.server.constants.Url; import com.appsmith.server.constants.Url;
@ -87,6 +88,9 @@ public class ApplicationControllerTest {
@MockBean @MockBean
PartialImportService partialImportService; PartialImportService partialImportService;
@MockBean
ProjectProperties projectProperties;
private String getFileName(int length) { private String getFileName(int length) {
StringBuilder fileName = new StringBuilder(); StringBuilder fileName = new StringBuilder();
for (int count = 0; count < length; count++) { for (int count = 0; count < length; count++) {