Skip to content

Commit

Permalink
chore: fix for upload-artifacts@v4 (#25)
Browse files Browse the repository at this point in the history
* chore: when using upload-artifacts@v4 , files are stored in a different way and we need to follow redirects using HttpClient (but removing the authorization) .

* chore: bump build dependencies
  • Loading branch information
filipelautert authored Dec 26, 2024
1 parent b172674 commit 597e9d6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
name: Build & Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.event.after}}

Expand All @@ -34,15 +34,15 @@ jobs:
- name: Archive Test Results
if: ${{ always() }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: liquibase-sdk-maven-plugin-test-results
path: |
./**/target/surefire-reports
./**/target/site
- name: Archive Packages
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: liquibase-sdk-maven-plugin-artifacts
path: target/liquibase-sdk-maven-plugin-*.jar
2 changes: 1 addition & 1 deletion .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
name: Draft Release ${{ needs.setup.outputs.version }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up JDK for GPG
uses: actions/setup-java@v2
Expand Down
38 changes: 26 additions & 12 deletions src/main/java/liquibase/sdk/github/GitHubClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.ProtocolException;
import org.kohsuke.github.*;
import org.slf4j.Logger;

Expand Down Expand Up @@ -304,25 +305,38 @@ public File downloadArtifact(URL url) throws IOException {
File file = File.createTempFile("liquibase-sdk-" + url.getPath().replaceFirst(".*/", "").replaceAll("\\W", "_") + "-", "." + extension);

//archive.download() threw timeout errors too often. So using httpClient instead
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
HttpGet httpGet = new HttpGet(url.toURI());
httpGet.addHeader("Authorization", "token " + githubToken);

try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
if (response.getCode() != 200) {
throw new IOException("Non-200 response: " + response.getCode() + " " + response.getReasonPhrase());
}

try (OutputStream out = new FileOutputStream(file)) {
response.getEntity().writeTo(out);
}
try (CloseableHttpClient httpclient = HttpClients.custom()
.disableRedirectHandling()
.build()) {
CloseableHttpResponse response = getResponse(url, httpclient, false);
try (OutputStream out = new FileOutputStream(file)) {
response.getEntity().writeTo(out);
}
} catch (URISyntaxException e) {
throw new IOException(e);
}
return file;
}

private CloseableHttpResponse getResponse(URL url, CloseableHttpClient httpclient, boolean skipAuth) throws URISyntaxException, IOException {
HttpGet httpGet = new HttpGet(url.toURI());
if (!skipAuth) {
httpGet.addHeader("Authorization", "token " + githubToken);
}

try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
if (response.getCode() == 302) {
return getResponse(new URL(response.getHeader("Location").getValue()), httpclient, true);
}
if (response.getCode() != 200) {
throw new IOException("Non-200 response: " + response.getCode() + " " + response.getReasonPhrase());
}
return response;
} catch (ProtocolException e) {
throw new IOException(e);
}
}

public void setCommitStatus(String repo, String sha1, GHCommitState statusState, String statusContext, String statusDescription, String statusUrl) throws IOException {
GHRepository repository = getRepository(repo);
log.debug("Successfully found repository " + repository.getHtmlUrl());
Expand Down

0 comments on commit 597e9d6

Please sign in to comment.