From feaff751212c51461ffb50f1f0a123faa2d5988a Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Fri, 3 Jun 2022 12:00:23 +0200 Subject: [PATCH] version update for testing. --- .gitignore | 1 + build_system.d | 59 ++++++++++++++++++++++++++++++++++++++++---------- pom.xml | 2 +- 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 114955f..59b2d00 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ build/ src/main/resources/app /build_system /log +/github_token.properties diff --git a/build_system.d b/build_system.d index 9a626f7..bd2e513 100755 --- a/build_system.d +++ b/build_system.d @@ -3,6 +3,7 @@ dependency "dsh" version="~>1.6.1" dependency "dxml" version="~>0.4.3" dependency "requests" version="~>2.0.8" + dependency "d-properties" version="~>1.0.4" +/ /** @@ -51,15 +52,9 @@ int main(string[] args) { buildApp(); buildApi(ver); if (args.length >= 3 && args[2].strip.toLower == "release") { - if (args.length >= 4) { - string token = args[3].strip(); - print("Are you sure you want to create a GitHub release for version %s?", ver); - string response = readln().strip.toLower; - if (response == "yes" || response == "y") createRelease(token, ver); - } else { - error("Missing required personal access token to create a GitHub release."); - return 1; - } + print("Are you sure you want to create a GitHub release for version %s?", ver); + string response = readln().strip.toLower; + if (response == "yes" || response == "y") createRelease(ver); } } } else { @@ -114,6 +109,48 @@ string getVersion() { return null; } -void createRelease(string token, string ver) { - +void createRelease(string ver) { + import d_properties; + import requests; + import std.json; + + print("Creating release..."); + + JSONValue data = [ + "tag_name": "v" ~ ver, + "name": "Rail Signal v" ~ ver, + "body": "An automated release." + ]; + data.object["prerelease"] = JSONValue(true); + data.object["generate_release_notes"] = JSONValue(false); + print("Sending release API request:\n%s", data.toPrettyString); + + auto rq = Request(); + rq.verbosity = 2; + auto props = Properties("github_token.properties"); + string username = props["username"]; + string token = props["token"]; + rq.authenticator = new BasicAuthentication(username, token); + auto response = rq.post( + "https://api.github.com/repos/andrewlalis/RailSignalAPI/releases", + data.toString, + "application/json" + ); + if (response.code == 201) { + string responseBody = cast(string) response.responseBody; + JSONValue responseData = parseJSON(responseBody); + string assetUrl = responseData["assets_url"].str; + print("Got asset url: %s", assetUrl); + auto f = File("./target/rail-signal-" ~ ver ~ ".jar", "rb"); + auto assetResponse = rq.post( + assetUrl, + f.byChunk(4096), + "application/zip" + ); + writeln(assetResponse); + } else { + error("An error occurred."); + writeln(response.responseBody); + } } + diff --git a/pom.xml b/pom.xml index 231d602..58d76f3 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ nl.andrewl rail-signal-api - 2.2.0 + 2.2.1 rail-signal-api A simple API for tracking rail traffic in signalled blocks.