Skip to content

Commit

Permalink
Merge pull request #13 from vierbergenlars/add-appveyor-provider
Browse files Browse the repository at this point in the history
Add appveyor provider
  • Loading branch information
vierbergenlars authored Oct 19, 2020
2 parents 91b6038 + 845e8d4 commit a6d83ce
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Supported CI platforms:
* [Jenkins](https://jenkins.io)
* [GitLab CI](https://about.gitlab.com/product/continuous-integration/)
* [Github actions](https://github.com/features/actions)
* [Appveyor](https://www.appveyor.com)

### Programmatic usage

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package be.vbgn.gradle.cidetect.impl.appveyor;

import be.vbgn.gradle.cidetect.CiInformation;
import java.util.Map;
import javax.annotation.Nullable;

/**
* https://www.appveyor.com/docs/environment-variables/
*/
public class AppveyorInformation implements CiInformation {

private final Map<String, String> env;

AppveyorInformation(Map<String, String> env) {
this.env = env;
}

@Override
public boolean isCi() {
return env.containsKey("APPVEYOR");
}

@Nullable
@Override
public String getBuildNumber() {
return env.getOrDefault("APPVEYOR_BUILD_NUMBER", null);
}

@Nullable
@Override
public String getBranch() {
if (isTag()) {
return null;
}
if (isPullRequest()) {
return env.getOrDefault("APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH", null);
}
return env.getOrDefault("APPVEYOR_REPO_BRANCH", null);
}

@Nullable
@Override
public String getPullRequest() {
return env.getOrDefault("APPVEYOR_PULL_REQUEST_NUMBER", null);
}

@Nullable
@Override
public String getPullRequestTargetBranch() {
if (isPullRequest()) {
return env.getOrDefault("APPVEYOR_REPO_BRANCH", null);
}
return null;
}

@Nullable
@Override
public String getTag() {
return env.getOrDefault("APPVEYOR_REPO_TAG_NAME", null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package be.vbgn.gradle.cidetect.impl.appveyor;

import be.vbgn.gradle.cidetect.CiInformation;
import be.vbgn.gradle.cidetect.provider.CiInformationProvider;
import javax.annotation.Nullable;
import org.gradle.api.Project;

public class AppveyorInformationProvider implements CiInformationProvider {

@Nullable
@Override
public CiInformation newCiInformation(@Nullable Project project) {
return new AppveyorInformation(System.getenv());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ be.vbgn.gradle.cidetect.impl.travis.TravisCiInformationProvider
be.vbgn.gradle.cidetect.impl.jenkins.JenkinsInformationProvider
be.vbgn.gradle.cidetect.impl.gitlab.GitlabCiInformationProvider
be.vbgn.gradle.cidetect.impl.github.GithubActionsInformationProvider
be.vbgn.gradle.cidetect.impl.appveyor.AppveyorInformationProvider
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package be.vbgn.gradle.cidetect.impl.appveyor;

import static org.junit.Assert.assertEquals;

import be.vbgn.gradle.cidetect.CiInformation;
import be.vbgn.gradle.cidetect.impl.AbstractCiInformationTest;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;

public class AppveyorInformationTest extends AbstractCiInformationTest {

@Override
protected Map<String, String> getBaseEnv(String buildNumber) {
Map<String, String> env = new HashMap<>();
env.put("APPVEYOR", "True");
env.put("APPVEYOR_BUILD_NUMBER", buildNumber);
return env;
}

@Override
protected Map<String, String> getBranchBuildEnv(String branch) {
return Collections.singletonMap("APPVEYOR_REPO_BRANCH", branch);
}

@Override
protected Map<String, String> getPullRequestBuildEnv(String sourceBranch, String targetBranch, String prNumber) {
Map<String, String> environment = new HashMap<>();
environment.put("APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH", sourceBranch);
environment.put("APPVEYOR_REPO_BRANCH", targetBranch);
environment.put("APPVEYOR_PULL_REQUEST_NUMBER", prNumber);
return environment;
}

@Override
protected Map<String, String> getTagBuildEnv(String tagName) {
Map<String, String> environment = new HashMap<>();
environment.put("APPVEYOR_REPO_BRANCH", "some-branch-name");
environment.put("APPVEYOR_REPO_TAG_NAME", tagName);
environment.put("APPVEYOR_REPO_TAG", "true");
return environment;
}

@Override
protected CiInformation createCiInformation(Map<String, String> env) {
return new AppveyorInformation(env);
}

@Test
public void testPlatform() {
assertEquals("Appveyor", new AppveyorInformation(getBaseEnv("12")).getPlatform());
}
}

0 comments on commit a6d83ce

Please sign in to comment.