GitUtils { public String getTag(Project project) { if (currentlyRunningOnTravisCi()) { String travisTagEnv = System.getenv("TRAVIS_TAG"); if (travisTagEnv != null && !travisTagEnv.isEmpty()) { return travisTagEnv; } } if (currentlyRunningOnGithubActions()) { String githubRef = System.getenv("GITHUB_REF"); if (githubRef != null) { if (githubRef.startsWith("refs/tags/")) { return githubRef.substring("refs/tags/".length()); } } } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ExecResult execResult = project.exec(execSpec -> { execSpec.workingDir(project.getProjectDir()); execSpec.commandLine("git", "tag", "--points-at", "HEAD"); execSpec.setStandardOutput(outputStream); }); if (execResult.getExitValue() == 0) { String gitTag = outputStream.toString().trim(); if (!gitTag.isEmpty()) { return gitTag; } } return "HEAD"; }  static boolean currentlyRunningOnTravisCi(); static boolean currentlyRunningOnGithubActions(); @Nullable static String findSlug(Project project); @Nullable String findTravisSlug(Project project); String getRemoteUrl(Project project, String remote); File findWorkingDirectory(Project project); String getTag(Project project); @Nullable String findGithubUsername(Project project); @Nullable String findGithubToken(Project project);  }
@Test void getTag() { assertThat(GitUtils.getTag(project)).isNotNull(); }