DiscordSRV

DiscordSRV

86.8k Downloads

Switch Update-check to GitHub

Androkai opened this issue ยท 0 comments

commented

This idea is work in progress. I was unhappy with the #CUSTOM-variable which needs an additional sed-command to overwrite and depends on the build-server so I searched for an alternative and found a Maven plugin which get the hash for the build. Next I experimented with the GitHub-API and get first ideas about how this could look like. The example below shows some parts for a check against the latest dev-build. For a check against the latest official release there are other possibilities like using the releases on GitHub and check against this one or make use of tags or only commit release-versions to the master-branch. I thought about a possibility to check against develop or stable builds editable in the config.

pom.xml - Maven-plugin which get the build-hash and save it into ${buildNumber}

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>buildnumber-maven-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>create</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <doCheck>true</doCheck>
                    <doUpdate>false</doUpdate>
                </configuration>
            </plugin>
        </plugins>
    </build>

This can be for example used within plugin.yml:
e.g.: version: ${project.version}-${buildNumber}
Saving in java/class-files is tricky so I recommend saving it in plugin.yml or an extra file in ressoures-folder.

Check for GitHub-API status
https://status.github.com/api/status.json

{"status":"good","last_updated":"2016-09-10T00:36:08Z"}

Possible status: "good"=green, "minor"=yellow or "major"=red

Validate sha
https://api.github.com/repos/Scarsz/DiscordSRV/commits/[sha of build]
If invalid returns as JSON-text:

{
  "message": "Not Found",
  "documentation_url": "https://developer.github.com/v3"
}

Get sha of latest commit from master
https://api.github.com/repos/Scarsz/DiscordSRV/git/refs/heads/master
https://api.github.com/repos/Scarsz/DiscordSRV/git/refs/heads/develop

{
  "ref": "refs/heads/develop",
  "url": "https://api.github.com/repos/Scarsz/DiscordSRV/git/refs/heads/develop",
  "object": {
    "sha": "e1204d9cca3bd08a1352609b4c27b23a808a16b2",
    "type": "commit",
    "url": "https://api.github.com/repos/Scarsz/DiscordSRV/git/commits/e1204d9cca3bd08a1352609b4c27b23a808a16b2"
  }
}

Compare builds against each other
https://api.github.com/repos/Scarsz/DiscordSRV/compare/[sha_of_latest_version/master]...[sha_of_build]
e.g.:
https://api.github.com/repos/Scarsz/DiscordSRV/compare/e1204d9cca3bd08a1352609b4c27b23a808a16b2...7fcce2be418ffa8d2f4813af076aafb8e627c8d9
returns:

{
...
  "status": "behind",
  "ahead_by": 0,
  "behind_by": 18,
...
}