Compare commits

...

2 Commits

Author SHA1 Message Date
0a56bef53d Merge remote-tracking branch 'origin/master'
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 42s
# Conflicts:
#	README.md
2024-04-29 07:17:03 +01:00
6eb13e18eb maybe fix new server count? 2024-04-29 07:16:51 +01:00
3 changed files with 25 additions and 11 deletions

View File

@ -0,0 +1,13 @@
package cc.fascinated.piaservers.common;
public class Config {
/**
* Are we in production?
*
* @return If we are in production
*/
public static boolean isProduction() {
return System.getenv().containsKey("ENVIRONMENT") && System.getenv("ENVIRONMENT").equals("production");
}
}

View File

@ -12,22 +12,22 @@ public class GitUtils {
*/
public static void commitFiles(String message, Path... files) {
System.out.println("Committing files");
if (System.getenv("ENVIRONMENT").equals("production")) {
if (Config.isProduction()) {
runCommand("git", "config", "--global", "user.email", "liam+pia-servers-ci@fascinated.cc");
runCommand("git", "config", "--global", "user.name", "PIA Servers CI");
}
for (Path file : files) {
runCommand("git", "add", file.toAbsolutePath().toString());
}
runCommand("git", "commit", "-m", message);
runCommand("git", "push", "https://pia-servers-ci:%s@git.fascinated.cc/Fascinated/PIA-Servers".formatted(System.getenv("AUTH_TOKEN")));
}
}
/**
* Clone the repository
*/
public static void cloneRepo() {
if (System.getenv("ENVIRONMENT").equals("production")) {
if (Config.isProduction()) {
System.out.println("Cloning repository");
runCommand("git", "clone", "https://git.fascinated.cc/Fascinated/PIA-Servers.git");
runCommand("mv", "PIA-Servers/.git", ".");

View File

@ -40,6 +40,7 @@ public class PiaManager {
if (SERVERS == null) {
SERVERS = new HashSet<>();
}
System.out.println("Loaded " + SERVERS.size() + " servers from the file");
GitUtils.cloneRepo(); // Clone the repository
@ -82,13 +83,13 @@ public class PiaManager {
// Add the new servers to the list
for (PiaServerToken serverToken : piaDomain) {
// Add the server to the list
PiaServer server = new PiaServer(serverToken.getIp(), serverToken.getRegion(), new Date());
SERVERS.add(server);
boolean newServer = SERVERS.stream().noneMatch(s -> s.getIp().equals(server.getIp()));
boolean newServer = SERVERS.stream().noneMatch(server -> server.getIp().equals(serverToken.getIp()));
if (newServer) {
newServers++;
}
// Add the server to the list
SERVERS.add(new PiaServer(serverToken.getIp(), serverToken.getRegion(), new Date()));
}
// Save the servers to the file