mirror of
https://github.com/CarmJos/GithubReleases4J.git
synced 2026-06-04 21:18:16 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8445ac812d | |||
| c53ca18e96 | |||
| a3cb4bcb1a | |||
| 7eae212bc3 |
@@ -26,12 +26,15 @@ jobs:
|
||||
server-id: github
|
||||
server-username: MAVEN_USERNAME
|
||||
server-password: MAVEN_TOKEN
|
||||
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
|
||||
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
|
||||
|
||||
- name: "Maven Deploy"
|
||||
run: mvn -B deploy --file pom.xml -DskipTests
|
||||
env:
|
||||
MAVEN_USERNAME: ${{ github.repository_owner }}
|
||||
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}} # env variable for gpg signing in deploy
|
||||
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
||||
|
||||
- name: "Javadoc Deploy Staging"
|
||||
run: |
|
||||
|
||||
@@ -25,7 +25,7 @@ jobs:
|
||||
server-username: MAVEN_USERNAME
|
||||
server-password: MAVEN_TOKEN
|
||||
- name: "Package"
|
||||
run: mvn -B package --file pom.xml -Dmaven.javadoc.skip=true
|
||||
run: mvn --no-transfer-progress -B package --file pom.xml -Dmaven.javadoc.skip=true
|
||||
env:
|
||||
MAVEN_USERNAME: ${{ github.repository_owner }}
|
||||
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>githubreleases4j</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<version>1.3.0</version>
|
||||
|
||||
<name>GithubReleases4J</name>
|
||||
<description>Github Releases for Java</description>
|
||||
@@ -130,6 +130,26 @@
|
||||
<useSystemClassLoader>false</useSystemClassLoader>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>1.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<gpgArguments>
|
||||
<arg>--pinentry-mode</arg>
|
||||
<arg>loopback</arg>
|
||||
</gpgArguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.json.JSONObject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@@ -135,10 +134,8 @@ public class GithubRelease {
|
||||
*
|
||||
* @return The author user {@link GithubUser}
|
||||
*/
|
||||
public @Nullable GithubUser getAuthor() {
|
||||
return Optional.ofNullable(getContents().getJSONObject("author"))
|
||||
.map(GithubUser::of)
|
||||
.orElse(null);
|
||||
public @NotNull GithubUser getAuthor() {
|
||||
return GithubUser.of(getContents().getJSONObject("author"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,6 +27,7 @@ public class GithubReleases4J {
|
||||
// Should not be the instance.
|
||||
}
|
||||
|
||||
public static String GITHUB_URL = "https://github.com";
|
||||
public static String GITHUB_API_URL = "https://api.github.com";
|
||||
public static SimpleDateFormat GH_TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
|
||||
@@ -160,6 +161,62 @@ public class GithubReleases4J {
|
||||
return getLatestRelease(owner, repository, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get how many versions behind the current version's tag name.
|
||||
*
|
||||
* @param owner Repository's Owner
|
||||
* @param repository Repository's Name
|
||||
* @param token OAuth Access Token
|
||||
* <br> Necessary when this repository is private.
|
||||
* @param currentTagName Current Version's tag name.
|
||||
* @return NULL if not fetch releases, -1 if no match tag name.
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public static @Nullable Integer getVersionBehind(@NotNull String owner, @NotNull String repository,
|
||||
@Nullable String token, @NotNull String currentTagName) {
|
||||
List<GithubRelease> releases = GithubReleases4J.listReleases(owner, repository, token);
|
||||
if (releases.isEmpty()) return null; // Could not fetch releases.
|
||||
|
||||
int i = 0;
|
||||
for (GithubRelease release : releases) {
|
||||
if (release.getTagName().equalsIgnoreCase(currentTagName)) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i == releases.size()) return -1; // No match tag name;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get how many versions behind the current version's tag name.
|
||||
*
|
||||
* @param owner Repository's Owner
|
||||
* @param repository Repository's Name
|
||||
* @param currentTagName Current Version's tag name.
|
||||
* @return NULL if not fetch releases, -1 if no match tag name.
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public static @Nullable Integer getVersionBehind(@NotNull String owner, @NotNull String repository,
|
||||
@NotNull String currentTagName) {
|
||||
return getVersionBehind(owner, repository, null, currentTagName);
|
||||
}
|
||||
|
||||
public static @NotNull String getReleasesURL(@NotNull String owner, @NotNull String repository) {
|
||||
return buildURL("%s/%s/%s/releases", GITHUB_URL, owner, repository);
|
||||
}
|
||||
|
||||
public static @NotNull String getLatestReleaseURL(@NotNull String owner, @NotNull String repository) {
|
||||
return getReleasesURL(owner, repository) + "/latest";
|
||||
}
|
||||
|
||||
public static @NotNull String getReleaseURLByTag(@NotNull String owner, @NotNull String repository,
|
||||
@NotNull String releaseTagName) {
|
||||
return getReleasesURL(owner, repository) + "/tag/" + releaseTagName;
|
||||
}
|
||||
|
||||
private static String buildURL(@NotNull String url, Object... params) {
|
||||
return String.format(url, params);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import cc.carm.lib.githubreleases4j.GithubReleases4J;
|
||||
import org.junit.Test;
|
||||
|
||||
public class GithubVersionTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
System.out.println(GithubReleases4J.getVersionBehind("CarmJos", "UltraDepository", "1.3.4"));
|
||||
|
||||
System.out.println(GithubReleases4J.getVersionBehind("CarmJos", "UltraDepository", "v1.2.0"));
|
||||
|
||||
System.out.println(GithubReleases4J.getVersionBehind("CarmJos", "UltraDepository", "TEST"));
|
||||
|
||||
System.out.println(GithubReleases4J.getVersionBehind("CarmJos", "NULL", "TEST"));
|
||||
|
||||
System.out.println("Download at " + GithubReleases4J.getReleaseURLByTag("CarmJos", "UltraDepository", "1.3.4"));
|
||||
System.out.println("Download at " + GithubReleases4J.getLatestReleaseURL("CarmJos", "UltraDepository"));
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user