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

Jenkins pipeline for sending PRs to agents when changing the BDD specs #231

Merged
merged 27 commits into from
Mar 30, 2020

Conversation

mdelapenya
Copy link
Contributor

@mdelapenya mdelapenya commented Mar 25, 2020

What is this PR doing?

It adds a Jenkins pipeline executing on pushes to the master branch, with the following stages:

  • Checkouts the SCM
  • Uses a parallel execution to send PRs to each subscribed agent, if and only if there are changes in the gherkin files. To subscribe an agent, simply add an entry in the .ci/.jenkins-agents.yml file:
---
agents:
  - NAME: "python"
    FEATURES_PATH: "tests/bdd/features"
  - NAME: "ruby"
    FEATURES_PATH: "features"

The name will represent the agent name (equals to the github repository: i.e. "apm-agent-python"), and the features path, the directory in the agent repository where the feature files are located.

  • Installs HUB in the worker
  • Executes a shell script per agent, this script should:
  1. clone the agent repo
  2. ensure the target directory exists
  3. copy the feature files to the target directory
  4. create a git commit with the changes
  5. send a PR to the default branch of the agent repo with the changes

Why is important?

We want to push changes to downstream repos (the agents) whenever a change on the specs is done. This way the repos are always up-to-date with the specs.

Follow-ups

  • Consider versioning the specs, so each agent follows a spec.
  • Consider destructive changes in the specs (deletion): they won't be applied as we are just copying the files. We could remove the target dir first, and then apply the shared specs.

@mdelapenya mdelapenya requested a review from a team March 25, 2020 22:48
@mdelapenya mdelapenya self-assigned this Mar 25, 2020
.ci/Jenkinsfile Outdated Show resolved Hide resolved
.ci/Jenkinsfile Outdated Show resolved Hide resolved
.ci/scripts/send-pr.sh Outdated Show resolved Hide resolved
.ci/Jenkinsfile Outdated Show resolved Hide resolved
.ci/Jenkinsfile Outdated Show resolved Hide resolved
.ci/Jenkinsfile Outdated Show resolved Hide resolved
.ci/Jenkinsfile Outdated Show resolved Hide resolved
.ci/Jenkinsfile Outdated Show resolved Hide resolved
.ci/Jenkinsfile Show resolved Hide resolved
.ci/scripts/install-dependencies.sh Outdated Show resolved Hide resolved
.ci/Jenkinsfile Outdated Show resolved Hide resolved
@SylvainJuge
Copy link
Member

For cross-agent features, we create a check list to make sure that we don't forget to update each agent, maybe it would be interesting to do the same here and test this for all agents. example: #92 (comment)

Also, while this "automatic PR on merged specs" will definitely be useful, we need to be able to update each agent specs independently (as we currently do with scripts similar to https://github.com/elastic/apm-agent-java/blob/master/scripts/shared-specs/download_gherkins.sh ), as it allows to work on not-yet-merged specs.

.ci/Jenkinsfile Outdated Show resolved Hide resolved
.ci/Jenkinsfile Outdated Show resolved Hide resolved
@mdelapenya
Copy link
Contributor Author

For cross-agent features, we create a check list to make sure that we don't forget to update each agent, maybe it would be interesting to do the same here and test this for all agents. example: #92 (comment)

Also, while this "automatic PR on merged specs" will definitely be useful, we need to be able to update each agent specs independently (as we currently do with scripts similar to https://github.com/elastic/apm-agent-java/blob/master/scripts/shared-specs/download_gherkins.sh ), as it allows to work on not-yet-merged specs.

Hey @SylvainJuge, could those custom agent specs be done in a different file? If each agent needs to contribute custom scenarios to a feature file, then I would suggest having a code-generation process that takes the upstream file as template, and then applies agent contributions.

We can discuss about that in a follow-up iteration. Does it make sense to you?

@SylvainJuge
Copy link
Member

Hey @SylvainJuge, could those custom agent specs be done in a different file? If each agent needs to contribute custom scenarios to a feature file, then I would suggest having a code-generation process that takes the upstream file as template, and then applies agent contributions.

Actually that won't be custom scenarios per agent, if we had such scenarios, we will just put them in a different folder. I was more thinking about one or two agents will have to work with not-yet-merged versions of those shared specs.

My point here is that we will still need to be able to use a different version of those specs in each agent repository, thus it won't completely replace update scripts that currently have.

@mdelapenya
Copy link
Contributor Author

Ok, got it. In that direction, then I'd suggest discarding the automated PR until the upstream specs are good-to-go. At the end of the day, the PR is not automatically merged 😃

.ci/scripts/send-pr.sh Outdated Show resolved Hide resolved
.ci/scripts/send-pr.sh Outdated Show resolved Hide resolved
git checkout -b update-feature-files-$(date "+%Y%m%d%H%M%S")
echo "Copying feature files to the ${APM_AGENT_REPO_NAME} repo"
git status
git add ${APM_AGENT_SPECS_DIR}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, the git user.name and user.email should be in place (see PR 17214 in the infra repo), if that's not the case, then you might get some warnings, or maybe some errors, although I don't recall now.

I'd say to use some validation in case they are not defined to set them. what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a validation, I have added two gitCmd calls to ensure they are present in the build agent (see 08f9d9a). wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started with the check, but I realised that it is worth it to be prescriptive in this case, where we do not want other configuration. Just in case, that was my initial validation, at script level:

readonly GIT_USERNAME="elasticmachine"
readonly GIT_EMAIL="infra-root-${GIT_USERNAME}@elastic.co"

function checkGitConfig {
    local config="${1}"
    local defaultValue="${2}"

    git config "${config}"
    local exitCode=$?
    if [ ${exitCode} -ne 0 ]; then
        git config "${config}" "${defaultValue}"
    fi
}

function checkGit {
    checkGitConfig "user.name" "${GIT_USERNAME}"
    checkGitConfig "user.email" "${GIT_EMAIL}"
}

.ci/scripts/send-pr.sh Outdated Show resolved Hide resolved
@v1v
Copy link
Member

v1v commented Mar 26, 2020 via email

Comment on lines +56 to +63
script {
dir("${BASE_DIR}"){
def regexps =[
"^tests/agents/gherkin-specs/"
]
env.GHERKIN_SPECS_UPDATED = isGitRegionMatch(patterns: regexps)
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the block that controls if there are changes in the gherkin files. If so, the environment variable will be set to true, causing https://github.com/elastic/apm/pull/231/files#diff-8db37e8fcea0f1a8f2f39667e94ebcc4R76 to evaluate to true too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of this, the script sending the PR has to add no logic for checking if changes exist, so it just follow orders from the pipeline.

@mdelapenya mdelapenya marked this pull request as ready for review March 26, 2020 23:10
@mdelapenya
Copy link
Contributor Author

Hey @elastic/apm-agent-devs, we would like to know if this PR could be merged. Please feel free to add any comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants