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
170 changes: 144 additions & 26 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: Build and test
on:
# Build PRs and branches.
pull_request_target:
types: [ opened, synchronize, reopened ]
pull_request:
types: [opened, synchronize, reopened, closed]
paths-ignore:
- .github/workflows/deploy-tagged.yml

push:
branches:
- '**'
- "**"
tags-ignore:
- '**'
- "**"
paths-ignore:
- .github/workflows/deploy-tagged.yml

Expand All @@ -19,41 +19,49 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
# https://en.wikipedia.org/wiki/Java_version_history
java: [ '8', '11' ] # LTS
java: ["8", "11"]

steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
# For pull_request, github.sha is a merge commit; we want the PR head SHA.
# For push, github.sha is correct.
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}

- name: Setup JDK
uses: actions/setup-java@v5
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
distribution: temurin

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
# The Gradle wrapper's version (already the default, putting it here to clarity)
gradle-version: wrapper
# Removing unused files from Gradle User Home before saving to cache (i.e. older versions of gradle)
gradle-home-cache-cleanup: true
# Cache downloaded JDKs in addition to the default directories.
gradle-home-cache-includes: |
caches
notifications
jdks

- name: Build and test
env:
UPLOADCARE_PUBLIC_KEY: ${{ secrets.UPLOADCARE_PUBLIC_KEY }}
UPLOADCARE_SECRET_KEY: ${{ secrets.UPLOADCARE_SECRET_KEY }}
run: ./gradlew build --stacktrace

publish-snapshot:
name: Publish snapshot to GitHub Packages
publish-pr-snapshot:
name: Publish PR snapshot to GitHub Packages
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/master')

# Only publish for PRs from the same repo (forks won't have permissions to publish packages).
if: >
github.event_name == 'pull_request' &&
github.event.action != 'closed' &&
github.event.pull_request.head.repo.full_name == github.repository

permissions:
contents: read
packages: write
Expand All @@ -63,30 +71,26 @@ jobs:
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Get base version
id: get-version
run: |
BASE_VERSION=$(grep -iE "version([ ]*)=" gradle.properties | cut -f 2 -d "=" | tr -d '[:space:]')
# Strip any existing -SNAPSHOT suffix so we can re-apply it cleanly
BASE_VERSION="${BASE_VERSION%-SNAPSHOT}"
echo "base_version=${BASE_VERSION}" >> $GITHUB_OUTPUT

- name: Determine snapshot version
- name: Determine PR snapshot version
id: snapshot-version
run: |
if [ "${{ github.event_name }}" == "pull_request_target" ]; then
SNAPSHOT_VERSION="${{ steps.get-version.outputs.base_version }}-PR-${{ github.event.pull_request.number }}-SNAPSHOT"
else
SNAPSHOT_VERSION="${{ steps.get-version.outputs.base_version }}-SNAPSHOT"
fi
SNAPSHOT_VERSION="${{ steps.get-version.outputs.base_version }}-PR-${{ github.event.pull_request.number }}-SNAPSHOT"
echo "snapshot_version=${SNAPSHOT_VERSION}" >> $GITHUB_OUTPUT
echo "Publishing snapshot version: ${SNAPSHOT_VERSION}"
echo "Publishing PR snapshot version: ${SNAPSHOT_VERSION}"

- name: Setup JDK
uses: actions/setup-java@v5
with:
java-version: 8
distribution: 'temurin'
java-version: "8"
distribution: temurin

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
Expand All @@ -98,8 +102,122 @@ jobs:
notifications
jdks

- name: Publish snapshot to GitHub Packages
- name: Publish PR snapshot to GitHub Packages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_ACTOR: ${{ github.actor }}
run: ./gradlew publishReleasePublicationToGitHubPackagesRepository -Pversion=${{ steps.snapshot-version.outputs.snapshot_version }} --stacktrace

publish-master-snapshot:
name: Publish master snapshot to GitHub Packages
runs-on: ubuntu-latest
needs: build

# Publish on direct pushes to master (including merge commits).
if: github.event_name == 'push' && github.ref == 'refs/heads/master'

permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@v6

- name: Get base version
id: get-version
run: |
BASE_VERSION=$(grep -iE "version([ ]*)=" gradle.properties | cut -f 2 -d "=" | tr -d '[:space:]')
BASE_VERSION="${BASE_VERSION%-SNAPSHOT}"
echo "base_version=${BASE_VERSION}" >> $GITHUB_OUTPUT

- name: Determine master snapshot version
id: snapshot-version
run: |
SNAPSHOT_VERSION="${{ steps.get-version.outputs.base_version }}-SNAPSHOT"
echo "snapshot_version=${SNAPSHOT_VERSION}" >> $GITHUB_OUTPUT
echo "Publishing master snapshot version: ${SNAPSHOT_VERSION}"

- name: Setup JDK
uses: actions/setup-java@v5
with:
java-version: "8"
distribution: temurin

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
gradle-home-cache-cleanup: true
gradle-home-cache-includes: |
caches
notifications
jdks

- name: Publish master snapshot to GitHub Packages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_ACTOR: ${{ github.actor }}
run: ./gradlew publishReleasePublicationToGitHubPackagesRepository -Pversion=${{ steps.snapshot-version.outputs.snapshot_version }} --stacktrace

cleanup-merged-pr-snapshot:
name: Delete merged PR snapshot from GitHub Packages
runs-on: ubuntu-latest

# Triggered by pull_request.closed (merge) into master
if: >
github.event_name == 'pull_request' &&
github.event.action == 'closed' &&
github.event.pull_request.merged == true &&
github.event.pull_request.base.ref == 'master'

permissions:
packages: write

steps:
- name: Compute PR snapshot version
id: prver
run: |
# Must match the same scheme used in publish-pr-snapshot
# We need base version too:
BASE_VERSION=$(grep -iE "version([ ]*)=" gradle.properties | cut -f 2 -d "=" | tr -d '[:space:]')
BASE_VERSION="${BASE_VERSION%-SNAPSHOT}"
echo "version=${BASE_VERSION}-PR-${{ github.event.pull_request.number }}-SNAPSHOT" >> $GITHUB_OUTPUT

- name: Delete package version via GitHub API
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;

const package_type = "maven";

// TODO: IMPORTANT:
// Set this to the exact "Package name" as shown in the repo's Packages UI.
// For Maven packages this is often the artifactId, but verify.
const package_name = "YOUR_PACKAGE_NAME_HERE";

const versionName = "${{ steps.prver.outputs.version }}";

const versions = await github.paginate(
github.rest.packages.getAllPackageVersionsForPackageOwnedByRepo,
{ owner, repo, package_type, package_name, per_page: 100 }
);

const match = versions.find(v => v.name === versionName);
if (!match) {
core.warning(`No package version found named "${versionName}" in ${package_type}/${package_name}. Nothing to delete.`);
return;
}

await github.rest.packages.deletePackageVersionForRepoOwnedByOwner({
owner,
repo,
package_type,
package_name,
package_version_id: match.id,
});

core.info(`Deleted ${package_type}/${package_name}@${versionName} (id=${match.id}).`);
75 changes: 73 additions & 2 deletions src/main/java/com/uploadcare/api/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,35 @@ public boolean isImage() {
}

public ImageInfo getImageInfo() {
return fileData.imageInfo;
if (fileData.imageInfo != null) {
return fileData.imageInfo;
}
if (fileData.contentInfo != null) {
return fileData.contentInfo.image;
}
return null;
}

public VideoInfo getVideoInfo() {
return fileData.videoInfo;
if (fileData.videoInfo != null) {
return fileData.videoInfo;
}
if (fileData.contentInfo != null) {
return fileData.contentInfo.video;
}
return null;
}

public ContentInfo getContentInfo() {
return fileData.contentInfo;
}

public Map<String, String> getMetadata() {
return fileData.metadata;
}

public Map<String, AppData> getAppData() {
return fileData.appdata;
}

public Map<String, Float> getRekognitionInfo() {
Expand Down Expand Up @@ -260,4 +284,51 @@ public String toString() {
public enum ColorMode {
RGB, RGBA, RGBa, RGBX, L, LA, La, P, PA, CMYK, YCbCr, HSV, LAB
}

public static class MimeInfo {
public String mime;
public String type;
public String subtype;

@Override
public String toString() {
return "MimeInfo{" +
"mime='" + mime + '\'' +
", type='" + type + '\'' +
", subtype='" + subtype + '\'' +
'}';
}
}

public static class ContentInfo {
public MimeInfo mime;
public ImageInfo image;
public VideoInfo video;

@Override
public String toString() {
return "ContentInfo{" +
"mime=" + mime +
", image=" + image +
", video=" + video +
'}';
}
}

public static class AppData {
public Map<String, Object> data;
public String version;
public Date datetimeCreated;
public Date datetimeUpdated;

@Override
public String toString() {
return "AppData{" +
"data=" + data +
", version='" + version + '\'' +
", datetimeCreated=" + datetimeCreated +
", datetimeUpdated=" + datetimeUpdated +
'}';
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/uploadcare/api/RequestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import static com.uploadcare.urls.UrlUtils.trustedBuild;

/**
* A helper class for doing API calls to the Uploadcare API. Supports API version 0.6.
* A helper class for doing API calls to the Uploadcare API. Supports API version 0.7.
*
* TODO Support of throttled requests needs to be added
*/
Expand Down Expand Up @@ -117,7 +117,7 @@ public void setApiHeaders(HttpUriRequest request, String requestBodyMD5) {
String formattedDate = rfc2822(calendar.getTime());

request.addHeader("Content-Type", JSON_CONTENT_TYPE);
request.setHeader("Accept", "application/vnd.uploadcare-v0.6+json");
request.setHeader("Accept", "application/vnd.uploadcare-v0.7+json");
request.setHeader("Date", formattedDate);
request.setHeader("User-Agent",
String.format("javauploadcare/%s/%s", LIBRARY_VERSION, client.getPublicKey()));
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/uploadcare/data/FileData.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class FileData {
public File.VideoInfo videoInfo;
public Map<String, Float> rekognitionInfo;
public Map<String, String> variations;
public File.ContentInfo contentInfo;
public Map<String, String> metadata;
public Map<String, File.AppData> appdata;

@Override
public String toString() {
Expand Down
Loading
Loading