-
Couldn't load subscription status.
- Fork 314
Skip tests based on git changes on GitLab #9039
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3fc64a1
Skip tests based on git changes on GitLab
smola 283207e
Use DDCI_PULL_REQUEST_TARGET_SHA
smola 15a1ad8
Add script to infer base reference
smola a1ec019
Infer base branch
smola 0dccb3d
Fetch GitHub token from AWS SSM
smola b06a47b
Fix AWS SSM token name
smola bf4cb57
Extract gitlab_base_ref_params
smola File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #!/usr/bin/env bash | ||
| # Determines the base branch for the current PR (if we are running in a PR). | ||
| set -euo pipefail | ||
|
|
||
| # Happy path: if we're just one commit away from master, base ref is master. | ||
| if [[ $(git log --pretty=oneline origin/master..HEAD | wc -l) -eq 1 ]]; then | ||
| echo "We are just one commit away from master, base ref is master" >&2 | ||
| echo "master" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # In GitLab: we have no reference to the base branch or even the PR number. | ||
| # We have to find it from the current branch name, which is defined in | ||
| # CI_COMMIT_REF_NAME. | ||
| if [[ -z "${CI_COMMIT_REF_NAME}" ]]; then | ||
| echo "CI_COMMIT_REF_NAME is not set, not running in GitLab CI?" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ -z "${GITHUB_TOKEN:-}" ]]; then | ||
| echo "GITHUB_TOKEN is not set, fetching from AWS SSM" >&2 | ||
| if ! command -v aws >/dev/null 2>&1; then | ||
| echo "aws is not installed, please install it" >&2 | ||
| exit 1 | ||
| fi | ||
| GITHUB_TOKEN=$(aws ssm get-parameter --name "ci.$CI_PROJECT_NAME.gh_release_token" --with-decryption --query "Parameter.Value" --output text) | ||
| if [[ -z "${GITHUB_TOKEN}" ]]; then | ||
| echo "Failed to fetch GITHUB_TOKEN from AWS SSM" >&2 | ||
| exit 1 | ||
| fi | ||
| export GITHUB_TOKEN | ||
| fi | ||
|
|
||
| if ! command -v curl >/dev/null 2>&1; then | ||
| echo "curl is not installed, please install it" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! command -v jq >/dev/null 2>&1; then | ||
| echo "jq is not installed, please install it" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| while true; do | ||
| set +e | ||
| PR_DATA=$(curl \ | ||
| -XGET \ | ||
| --silent \ | ||
| --include \ | ||
| --fail-with-body \ | ||
| -H 'Accept: application/vnd.github+json' \ | ||
| -H "Authorization: Bearer ${GITHUB_TOKEN}" \ | ||
| -H "X-GitHub-Api-Version: 2022-11-28" \ | ||
| "https://api.github.com/repos/datadog/dd-trace-java/pulls?head=DataDog:${CI_COMMIT_REF_NAME}&sort=updated&direction=desc") | ||
| exit_code=$? | ||
| set -e | ||
| if [[ ${exit_code} -eq 0 ]]; then | ||
| PR_NUMBER=$(echo "$PR_DATA" | sed '1,/^[[:space:]]*$/d' | jq -r '.[].number') | ||
| PR_BASE_REF=$(echo "$PR_DATA" | sed '1,/^[[:space:]]*$/d' | jq -r '.[].base.ref') | ||
| echo "PR is https://github.com/datadog/dd-trace-java/pull/${PR_NUMBER} and base ref is ${PR_BASE_REF}">&2 | ||
| echo "${PR_BASE_REF}" | ||
| exit 0 | ||
| fi | ||
| if echo "$PR_DATA" | grep -q "^x-ratelimit-reset:"; then | ||
| reset_timestamp=$(echo -n "$PR_DATA" | grep "^x-ratelimit-reset:" | sed -e 's/^x-ratelimit-reset: //' -e 's/\r//') | ||
| now=$(date +%s) | ||
| sleep_time=$((reset_timestamp - now + 1)) | ||
| echo "GitHub rate limit exceeded, sleeping for ${sleep_time} seconds" >&2 | ||
| sleep "${sleep_time}" | ||
| continue | ||
| fi | ||
| echo -e "GitHub request failed for an unknown reason:\n$(echo "$PR_DATA" | sed '/^$/q')" >&2 | ||
| echo "Assuming base ref is master" >&2 | ||
| echo "master" | ||
| exit 0 | ||
| done |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Did you thought about making this part of our gradle itself. Not that I'm asking for it specifically. As I would like to avoid adding yet another groovy scripting at this time.
Also, I wonder does our gitlab CI have this resolved ?
cc @randomanderson
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be done at gradle level. A bash script for CI seemed pretty self-contained and easily debuggable though.
Not supported by GitLab, because GitHub PRs are not native to GitLab CI, and we do not use GitLab MR. We have an internal solution at DD that requires migrating to a new CI system for GitLab. That's apparently a lot of work for the repo since it was not used since the beginning.
In our current setup, this is the recommended way. I took it from dd-trace-py.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah thanks for the info !