Skip to content

Commit

Permalink
Fix test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
udda1996 committed Aug 12, 2022
1 parent 3901823 commit 847d107
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- name: Build with Gradle
env:
GITHUB_TOKEN: ${{ secrets.PUBLISH_PAT }}
BALLERINA_DEV_UPDATE: true
run: |
./gradlew build jacocoTestReport
- name: Generate Codecov Report
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ballerinaJreVersion=0.8.0
# For test purpose
swan-lake-version=2201.0.0
swan-lake-spec-version=2022R1
swan-lake-latest-version=2201.1.0
swan-lake-latest-version=2201.1.1
swan-lake-latest-spec-version=2022R2
1-x-channel-version=1.2.0
1-x-channel-spec-version=2020R1
Expand Down
49 changes: 48 additions & 1 deletion src/main/java/org/ballerinalang/command/util/ToolUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ private static void downloadAndSetupDist(PrintStream printStream, HttpURLConnect
String zipFileLocation = getDistributionsPath() + File.separator + distribution + ".zip";
downloadFile(conn, zipFileLocation, distribution, printStream);
String downloadedDistSha = calcDistSHA(zipFileLocation);
String remoteDistSha = conn.getHeaderField("hash");
String remoteDistSha = getDistSHA(distribution);
if (downloadedDistSha.equals(remoteDistSha)) {
unzip(zipFileLocation, distPath);
addExecutablePermissionToFile(new File(distPath + File.separator
Expand Down Expand Up @@ -506,6 +506,53 @@ private static void downloadAndSetupDist(PrintStream printStream, HttpURLConnect
}
}

private static String getDistSHA(String distribution) {
HttpURLConnection conn = null;
String hash = "";
try {
URL url = new URL(getServerURL() + "/distributions");
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("user-agent",
OSUtils.getUserAgent(getCurrentBallerinaVersion(),
getCurrentToolsVersion(), "jballerina"));
conn.setRequestProperty("Accept", "application/json");
if (conn.getResponseCode() != 200) {
conn.disconnect();
throw ErrorUtil.createCommandException(getServerRequestFailedErrorMessage(conn));
} else {
String json = convertStreamToString(conn.getInputStream());
Matcher matcher = Pattern.compile("\"version\":\"(.*?)\"").matcher(json);
int i = 0;
while (matcher.find()) {
if (!matcher.group(1).equals(distribution)) {
i++;
} else {
break;
}
}

matcher = Pattern.compile("\"hash\":\"(.*?)\"").matcher(json);
int j = 0;
while (matcher.find()) {
if (j==i) {
hash = matcher.group(1);
break;
} else {
j++;
}
}
}
} catch (IOException e) {
throw ErrorUtil.createCommandException(CONNECTION_ERROR_MESSAGE);
} finally {
if (conn != null) {
conn.disconnect();
}
}
return hash;
}

private static String calcDistSHA(String zipFileLocation) throws NoSuchAlgorithmException, IOException {
File zipFilePath = new File(zipFileLocation);
MessageDigest digest = MessageDigest.getInstance("SHA-1");
Expand Down

0 comments on commit 847d107

Please sign in to comment.