Skip to content

Commit

Permalink
GH-9 Refactor updater to gitcheck. Improve API to check update.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rollczi authored Jan 17, 2023
1 parent a08d978 commit 5b61e7a
Show file tree
Hide file tree
Showing 32 changed files with 1,150 additions and 303 deletions.
16 changes: 16 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Contributing to GitCheck
We welcome contributions to GitCheck! Here are some guidelines to follow:

## Submitting Issues
If you find a bug or have a feature request, please submit an issue on GitHub. Be sure to include as much information as possible, such as the version of GitCheck you are using, and steps to reproduce the issue.

## Pull Requests
We welcome pull requests!
If you would like to make changes to the code, please fork the repository, create a new branch, and submit a pull request.
Be sure to include a detailed description of the changes you have made, and include any relevant test cases.
Make sure to follow the code style of the project. :)

## License
By contributing to GitCheck, you agree that your contributions will be licensed under the [MIT License](../LICENSE).

Thank you for your interest in contributing to GitCheck! We look forward to reviewing your pull requests and issues.
34 changes: 34 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Java CI and Test with Gradle

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
name: "Build with JDK${{ matrix.jdk }}"
runs-on: ubuntu-latest
strategy:
matrix:
jdk: [ 9, 11, 17 ]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up JDK ${{ matrix.jdk }}
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.jdk }}
distribution: 'adopt'
cache: gradle

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew

- name: Build with Gradle
run: ./gradlew clean build

- name: Test with Gradle
run: ./gradlew clean test
28 changes: 0 additions & 28 deletions .github/workflows/buildAndPush.yml

This file was deleted.

29 changes: 29 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Publish package to Maven Repository

on:
release:
types: [ published ]

jobs:
publish:
name: "Publish to Maven Repository"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
cache: 'gradle'

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew

- name: Publish with Gradle
run: ./gradlew clean build publish
env:
ETERNALCODE_REPO_USERNAME: ${{ secrets.ETERNALCODE_REPO_USERNAME }}
ETERNALCODE_REPO_PASSWORD: ${{ secrets.ETERNALCODE_REPO_PASSWORD }}
File renamed without changes.
119 changes: 60 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,79 +1,80 @@
# Updater
# GitCheck
GitCheck is a Java library that makes it easy to check for updates to a GitHub repository.
It utilizes the GitHub API to retrieve information about the latest release and compares it to the current version of your application.
With GitCheck, you can ensure that your users are always running the latest version of your software.

#### Updater is a library for checking for updates for your plugin on GitHub. It uses the GitHub API to get information about the latest release of your plugin and compare it to the current version of your plugin.
## Features
- Simple and easy-to-use API
- Lightweight and efficient
- Supports Java 9 and above
- Utilizes the GitHub API for retrieving release information
- You can add your own implementation for another platform

### Usage
First, you need to create an instance of the `Updater` class by passing the plugin name, current version, and Github repository name as arguments. Then, you can call the `checkUpdates()` method to check for updates and get the `RemoteInformation` object.
## Installation

The `RemoteInformation` object contains information about the update, such as the availability of a new version, the current version, and the download URI.
To use GitCheck in your project, if you are using Gradle, add the following to your `build.gradle` file:

```java
if (remoteInformation.isAvailableNewVersion()) {
System.out.println("A new version is available: " + remoteInformation.getCurrentVersion());
System.out.println("Download URI: " + remoteInformation.getDownloadUri());
} else {
System.out.println("You are already running the latest version.");
}
```kotlin
maven { url = uri("https://repo.eternalcode.pl/releases") }
```

### Example
Here's an example of how to can use the Updater in `Spigot` plugin

```java

import com.eternalcode.updater.Updater;
import com.eternalcode.updater.http.RemoteInformation;

public class MyPlugin {
```kotlin
implementation("com.eternalcode:gitcheck:1.0.0")
```

private Updater updater;
Or, if you are using Maven, add the following to your `pom.xml` file:

public void onEnable() {
updater = new Updater("MyPlugin", "1.0", "MyGithubUsername/MyPlugin");
checkForUpdates();
}
```xml
<repository>
<id>eternalcode-releases</id>
<url>https://repo.eternalcode.pl/releases</url>
</repository>
```

private void checkForUpdates() {
RemoteInformation remoteInformation = updater.checkUpdates();
if (remoteInformation.isAvailableNewVersion()) {
System.out.println("A new version is available: " + remoteInformation.getCurrentVersion());
System.out.println("Download URI: " + remoteInformation.getDownloadUri());
} else {
System.out.println("You are already running the latest version.");
}
}
}
```xml
<dependency>
<groupId>com.eternalcode</groupId>
<artifactId>gitcheck</artifactId>
<version>1.0.0</version>
</dependency>
```

### Maven/Gradle
Get the latest version from [EternalCode Repository](https://repo.eternalcode.pl/#/releases/com/eternalcode/updater)
## API Usage

#### gradle groovy
```groovy
maven { url "https://repo.eternalcode.pl/releases" }
To use GitCheck, you need to create an instance of the `GitCheck` class.
Create `GitRepository` and `GitTag` objects to specify the repository and the current version of your application.
Then, call the `checkRelease` method to check for updates.

implementation "com.eternalcode:updater:{VERSION}"
```
```java
public class MyApplication {

```kotlin
maven { url = uri("https://repo.eternalcode.pl/releases") }
public static void main(String[] args) {
GitCheck gitCheck = new GitCheck();
GitRepository repository = GitRepository.of("Owner", "Project");

implementation("com.eternalcode:updater:{VERSION}")
```
GitCheckResult result = gitCheck.checkRelease(repository, GitTag.of("v1.0.0"));

```xml
<repository>
<id>eternalcode-reposilite-releases</id>
<name>EternalCode Repository</name>
<url>https://repo.eternalcode.pl/releases</url>
</repository>
if (!result.isUpToDate()) {
GitRelease release = result.getLatestRelease();
GitTag tag = release.getTag();

<dependency>
<groupId>com.eternalcode</groupId>
<artifactId>updater</artifactId>
<version>{VERSION}</version>
</dependency>
```
System.out.println("A new version is available: " + tag.getTag());
System.out.println("See release page: " + release.getPageUrl());
System.out.println("Release date: " + release.getPublishedAt());
}

// ...
}

}
```
In this example, `GitCheck` is used to check for updates to the repository `Owner/Project` with the current version `v1.0.0`.
If a new version is available, the details of the release are printed to the console.

## Contributing
We welcome contributions to GitCheck!
If you have an idea for a new feature or have found a bug that needs to be fixed, you can [open an issue](https://github.com/EternalCodeTeam/GitCheck/issues/new) or [submit a pull request](https://github.com/EternalCodeTeam/GitCheck/compare) with your changes.<br>
See [CONTRIBUTING.md](.github/CONTRIBUTING.md) for more information.

## License
GitCheck is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.
30 changes: 19 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
plugins {
`java-library`
`maven-publish`
id("com.github.johnrengelman.shadow") version "7.1.2"
}

group = "com.eternalcode"
version = System.getenv("E_VERSION")
version = "1.0.0"
val artifactId = "gitcheck"

java {
withJavadocJar()
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_1_9
targetCompatibility = JavaVersion.VERSION_1_9
}

repositories {
Expand All @@ -17,21 +22,23 @@ repositories {

dependencies {
// https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple
implementation("com.googlecode.json-simple:json-simple:1.1.1")
api("com.googlecode.json-simple:json-simple:1.1.1") {
exclude(group = "junit")
}

// OkHTTP
implementation("com.squareup.okhttp3:okhttp:4.10.0")
api("org.jetbrains:annotations:23.1.0")

testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
testImplementation("nl.jqno.equalsverifier:equalsverifier:3.12.3")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.2")
}

publishing {
publications {
create<MavenPublication>("maven") {
groupId = "com.eternalcode"
artifactId = "updater"
version = System.getenv("E_VERSION")
groupId = "$group"
artifactId = artifactId
version = "${project.version}"

from(components["java"])
}
Expand All @@ -40,9 +47,10 @@ publishing {
maven {
name = "eternalcode-repository"
url = uri("https://repo.eternalcode.pl/releases")

credentials {
username = System.getenv("E_REPO_USERNAME")
password = System.getenv("E_REPO_PASS")
username = System.getenv("ETERNALCODE_REPO_USERNAME")
password = System.getenv("ETERNALCODE_REPO_PASSWORD")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rootProject.name = "eternalupdater"
rootProject.name = "gitcheck"

70 changes: 70 additions & 0 deletions src/main/java/com/eternalcode/gitcheck/GitCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.eternalcode.gitcheck;

import com.eternalcode.gitcheck.git.GitRelease;
import com.eternalcode.gitcheck.git.GitReleaseProvider;
import com.eternalcode.gitcheck.git.GitRepository;
import com.eternalcode.gitcheck.git.GitTag;
import com.eternalcode.gitcheck.github.GitHubReleaseProvider;
import com.eternalcode.gitcheck.shared.Preconditions;
import org.jetbrains.annotations.NotNull;

/**
* Service for checking if the latest release is up to date.
* <p>
* This service uses {@link GitReleaseProvider} to get the latest release and compares it with the current tag.
* The current tag is provided by {@link GitTag#of(String)}
* <br>
*/
public class GitCheck {

private final GitReleaseProvider versionProvider;

/**
* Creates a new instance of {@link GitCheck} with the default {@link GitHubReleaseProvider}.
*/
public GitCheck() {
this(new GitHubReleaseProvider());
}

/**
* Creates a new instance of {@link GitCheck} with the given {@link GitReleaseProvider}.
*
* @param versionProvider the version provider
*/
public GitCheck(@NotNull GitReleaseProvider versionProvider) {
Preconditions.notNull(versionProvider, "release provider");
this.versionProvider = versionProvider;
}

/**
* Gets the latest release for the given repository.
*
* @param repository the repository
* @return the latest release
*/
@NotNull
public GitRelease getLatestRelease(@NotNull GitRepository repository) {
Preconditions.notNull(repository, "repository");

return this.versionProvider.getLatestRelease(repository);
}

/**
* Creates a new instance of {@link GitCheckResult} for the given repository and tag.
* Result contains the latest release and the current tag.
* Use {@link GitCheckResult#isUpToDate()} to check if the latest release is up to date.
*
* @param repository the repository
* @param currentTag the current tag
* @return the result
*/
@NotNull
public GitCheckResult checkRelease(@NotNull GitRepository repository, @NotNull GitTag currentTag) {
Preconditions.notNull(repository, "repository");
Preconditions.notNull(currentTag, "current tag");

GitRelease latestRelease = this.getLatestRelease(repository);
return new GitCheckResult(latestRelease, currentTag);
}

}
Loading

0 comments on commit 5b61e7a

Please sign in to comment.