Allow other refspecs to be used.
That gives us a way to test e.g. pull requests by specifying ph_scripts_refspec="pull/123/head" Also keep "ph_" prefix to remove confusion we had between "scripts_branch" and "ph_scripts_branch" before. Update docs and moved "testing" sections up.
This commit is contained in:
parent
381b1bf1a6
commit
405643a089
6 changed files with 93 additions and 50 deletions
|
@ -43,23 +43,28 @@ account for writing comments.
|
||||||
|
|
||||||
Buildkite allows [dynamically define pipelines as the output of a
|
Buildkite allows [dynamically define pipelines as the output of a
|
||||||
command](https://buildkite.com/docs/pipelines/defining-steps#dynamic-pipelines).
|
command](https://buildkite.com/docs/pipelines/defining-steps#dynamic-pipelines).
|
||||||
That gives us the flexibility to generate pipeline code using a script from a
|
That gives us the flexibility to generate pipeline code using the code from a
|
||||||
specific branch of pre-merge checks.
|
specific branch of pre-merge checks. Thus,
|
||||||
|
[changes can be tested](./playbooks.md#testing-changes-before-merging)
|
||||||
|
before affecting everyone.
|
||||||
|
|
||||||
For example, "pre-merge" pipeline has a single fixed step, that checks out this
|
For example, "pre-merge" pipeline has a single "setup" step, that checks out this
|
||||||
repo and runs a python script to generate further steps:
|
repo and runs a python script to generate further steps:
|
||||||
|
|
||||||
```shell script
|
```shell script
|
||||||
export SRC=${BUILDKITE_BUILD_PATH}/llvm-premerge-checks
|
export SRC="${BUILDKITE_BUILD_PATH}"/llvm-premerge-checks
|
||||||
rm -rf ${SRC}
|
export SCRIPT_DIR="${SRC}"/scripts
|
||||||
git clone --depth 1 --branch ${scripts_branch:-master} https://github.com/google/llvm-premerge-checks.git ${SRC}
|
rm -rf "${SRC}"
|
||||||
export SCRIPT_DIR=${SRC}/scripts
|
git clone --depth 1 https://github.com/google/llvm-premerge-checks.git "${SRC}"
|
||||||
|
cd "${SRC}"
|
||||||
|
git fetch origin "${ph_scripts_refspec:-master}":x
|
||||||
|
git checkout x
|
||||||
|
cd "$BUILDKITE_BUILD_CHECKOUT_PATH"
|
||||||
${SCRIPT_DIR}/buildkite/build_branch_pipeline.py | tee /dev/tty | buildkite-agent pipeline upload
|
${SCRIPT_DIR}/buildkite/build_branch_pipeline.py | tee /dev/tty | buildkite-agent pipeline upload
|
||||||
```
|
```
|
||||||
|
|
||||||
One typically edits corresponding script, not a pipeline definition in the
|
One typically edits corresponding script, instead of manually updating a pipeline
|
||||||
Buildkite interface. [How to test
|
in the Buildkite interface.
|
||||||
changes](playbooks.md#testing-changes-before-merging).
|
|
||||||
|
|
||||||
# Life of a pre-merge check
|
# Life of a pre-merge check
|
||||||
|
|
||||||
|
@ -69,8 +74,8 @@ testers").
|
||||||
That in sends an HTTP POST request to [**phab-proxy**](../phabricator-proxy)
|
That in sends an HTTP POST request to [**phab-proxy**](../phabricator-proxy)
|
||||||
that submits a new buildkite job **diff-checks**. All parameters from the
|
that submits a new buildkite job **diff-checks**. All parameters from the
|
||||||
original request are put in the build's environment with `ph_` prefix (to avoid
|
original request are put in the build's environment with `ph_` prefix (to avoid
|
||||||
shadowing any Buildkite environment variable). "scripts_branch" parameter
|
shadowing any Buildkite environment variable). "ph_scripts_refspec" parameter
|
||||||
defines which branch of llvm-premerge-checks to use.
|
defines refspec of llvm-premerge-checks to use ("master" by default).
|
||||||
|
|
||||||
**diff-checks** pipeline
|
**diff-checks** pipeline
|
||||||
([create_branch_pipeline.py](../scripts/buildkite/create_branch_pipeline.py))
|
([create_branch_pipeline.py](../scripts/buildkite/create_branch_pipeline.py))
|
||||||
|
|
|
@ -1,16 +1,41 @@
|
||||||
- [Playbooks](#playbooks)
|
- [Playbooks](#playbooks)
|
||||||
* [deployment to a clean infrastructure](#deployment-to-a-clean-infrastructure)
|
* [Testing scripts locally](#testing-scripts-locally)
|
||||||
|
* [Testing changes before merging](#testing-changes-before-merging)
|
||||||
|
* [Deployment to a clean infrastructure](#deployment-to-a-clean-infrastructure)
|
||||||
* [Creating docker containers on Windows](#creating-docker-containers-on-windows)
|
* [Creating docker containers on Windows](#creating-docker-containers-on-windows)
|
||||||
* [Spawning a new windows agent](#spawning-a-new-windows-agent)
|
* [Spawning a new windows agent](#spawning-a-new-windows-agent)
|
||||||
+ [Buildkite](#buildkite)
|
+ [Buildkite](#buildkite)
|
||||||
* [Testing scripts locally](#testing-scripts-locally)
|
|
||||||
* [Custom environment variables](#custom-environment-variables)
|
* [Custom environment variables](#custom-environment-variables)
|
||||||
* [Testing changes before merging](#testing-changes-before-merging)
|
|
||||||
* [Update HTTP auth credentials](#update-http-auth-credentials)
|
* [Update HTTP auth credentials](#update-http-auth-credentials)
|
||||||
|
|
||||||
# Playbooks
|
# Playbooks
|
||||||
|
|
||||||
## deployment to a clean infrastructure
|
## Testing scripts locally
|
||||||
|
|
||||||
|
Build and run agent docker image `sudo ./containers/build_run.sh buildkite-premerge-debian /bin/bash`.
|
||||||
|
|
||||||
|
Set `CONDUIT_TOKEN` with your personal one from `https://reviews.llvm.org/settings/user/<USERNAME>/page/apitokens/`.
|
||||||
|
|
||||||
|
## Testing changes before merging
|
||||||
|
|
||||||
|
It's recommended to test even smallest changes before committing them to the `master` branch.
|
||||||
|
|
||||||
|
1. Create a pull request here.
|
||||||
|
1. Manually create a buildkite build in the pipeline you are updating and specify
|
||||||
|
environment variable `ph_scripts_refspec="pull/123/head"`. Replace `123`
|
||||||
|
with your PR number. If you don't have access to create buildkite builds,
|
||||||
|
please ask a reviewer to do that.
|
||||||
|
|
||||||
|
To test "premerge-tests" pipeline pick an existing build and copy "ph_"
|
||||||
|
parameters from it, omitting "ph_target_phid" (so that build does not update
|
||||||
|
existing review. That will likely lead to an error though).
|
||||||
|
|
||||||
|
See also [custom environment variables](#custom-environment-variables).
|
||||||
|
1. Wait for build to complete and maybe attach a link to it to your PR.
|
||||||
|
|
||||||
|
To test changes for the pipeline "setup" step please experiment on a copy first.
|
||||||
|
|
||||||
|
## Deployment to a clean infrastructure
|
||||||
|
|
||||||
General remarks:
|
General remarks:
|
||||||
* GCP does not route any traffic to your services unless the service is
|
* GCP does not route any traffic to your services unless the service is
|
||||||
|
@ -131,12 +156,6 @@ git clone https://github.com/google/llvm-premerge-checks.git C:\llvm-premerge-ch
|
||||||
schtasks.exe /create /tn "Start Buildkite agent" /ru SYSTEM /SC ONSTART /DELAY 0005:00 /tr "powershell -command 'C:\llvm-premerge-checks\scripts\windows_agent_start_buildkite.ps1 -workdir c:\ws'"
|
schtasks.exe /create /tn "Start Buildkite agent" /ru SYSTEM /SC ONSTART /DELAY 0005:00 /tr "powershell -command 'C:\llvm-premerge-checks\scripts\windows_agent_start_buildkite.ps1 -workdir c:\ws'"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Testing scripts locally
|
|
||||||
|
|
||||||
Build and run agent docker image `sudo ./containers/build_run.sh buildkite-premerge-debian /bin/bash`.
|
|
||||||
|
|
||||||
Additionally set `WORKSPACE`, `PHID` and `DIFF_ID` parameters. Set `CONDUIT_TOKEN` with your personal one from `https://reviews.llvm.org/settings/user/<USERNAME>/page/apitokens/`.
|
|
||||||
|
|
||||||
## Custom environment variables
|
## Custom environment variables
|
||||||
|
|
||||||
Buildkite pipelines have a number of custom environment variables one can set to change their behavior. That is useful to debug issues
|
Buildkite pipelines have a number of custom environment variables one can set to change their behavior. That is useful to debug issues
|
||||||
|
@ -145,7 +164,7 @@ please refer to the source code for the details. These variables have `ph_` pref
|
||||||
|
|
||||||
Most commonly used are:
|
Most commonly used are:
|
||||||
|
|
||||||
- `scripts_branch` ("master" by default): which branch of llvm-premerge-checks to use. This variable is also used in pipeline "bootstrap" in Buildkite interface.
|
- `ph_scripts_refspec` ("master" by default): refspec branch of llvm-premerge-checks to use. This variable is also used in pipeline "bootstrap" in Buildkite interface.
|
||||||
- `ph_no_cache`: (if set to any value) clear compilation cache before the build.
|
- `ph_no_cache`: (if set to any value) clear compilation cache before the build.
|
||||||
- `ph_projects`: which projects to use, "detect" will look on diff to infer the projects, "default" selects all projects.
|
- `ph_projects`: which projects to use, "detect" will look on diff to infer the projects, "default" selects all projects.
|
||||||
- `ph_notify_email`: comma-separated list of email addresses to be notified when build is complete.
|
- `ph_notify_email`: comma-separated list of email addresses to be notified when build is complete.
|
||||||
|
@ -154,15 +173,6 @@ Most commonly used are:
|
||||||
- `ph_linux_agents`, `ph_windows_agents`: custom JSON constraints on agents. For example you might put one machine to a custom queue if it's errornous and send jobs to it with `ph_windows_agents="{{\"queue\": \"custom\"}}"`.
|
- `ph_linux_agents`, `ph_windows_agents`: custom JSON constraints on agents. For example you might put one machine to a custom queue if it's errornous and send jobs to it with `ph_windows_agents="{{\"queue\": \"custom\"}}"`.
|
||||||
- `ph_skip_linux`, `ph_skip_windows` (if set to any value): skip build on this OS.
|
- `ph_skip_linux`, `ph_skip_windows` (if set to any value): skip build on this OS.
|
||||||
|
|
||||||
## Testing changes before merging
|
|
||||||
|
|
||||||
It's recommended to test even smallest changes before committing them to the `master` branch.
|
|
||||||
|
|
||||||
1. Create a branch with your changes, e.g. "my-feature" and push it to origin.
|
|
||||||
1. Manually create a buildkite build in the pipeline you are updating and specify environment variable
|
|
||||||
`scripts_branch="my-feature"` (see also "Custom environment variables" for other options above). To test "premerge-tests" pipeline pick an existing build and copy parameters from it, omitting "ph_target_phid", namely: "ph_build_id", "ph_buildable_diff", "ph_buildable_revision", "ph_initiator_phid" and "scripts_branch" variables.
|
|
||||||
1. Wait for build to complete and maybe attach a link to it to your PR.
|
|
||||||
|
|
||||||
## Update HTTP auth credentials
|
## Update HTTP auth credentials
|
||||||
|
|
||||||
To update e.g. buildkite http-auth:
|
To update e.g. buildkite http-auth:
|
||||||
|
|
|
@ -27,12 +27,12 @@ def build():
|
||||||
for k, v in params.items():
|
for k, v in params.items():
|
||||||
if len(v) == 1:
|
if len(v) == 1:
|
||||||
build_env['ph_' + k] = v[0]
|
build_env['ph_' + k] = v[0]
|
||||||
branch = 'master'
|
refspec = 'master'
|
||||||
if 'ph_scripts_branch' in build_env:
|
if 'ph_scripts_refspec' in build_env:
|
||||||
branch = build_env['ph_scripts_branch']
|
refspec = build_env['ph_scripts_refspec']
|
||||||
build_request = {
|
build_request = {
|
||||||
'commit': 'HEAD',
|
'commit': 'HEAD',
|
||||||
'branch': branch,
|
'branch': refspec,
|
||||||
'env': build_env,
|
'env': build_env,
|
||||||
'message': f'D{build_env["ph_buildable_revision"]}',
|
'message': f'D{build_env["ph_buildable_revision"]}',
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,14 @@ import os
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
scripts_branch = os.getenv("scripts_branch", "master")
|
scripts_refspec = os.getenv("ph_scripts_refspec", "master")
|
||||||
queue_prefix = os.getenv("ph_queue_prefix", "")
|
queue_prefix = os.getenv("ph_queue_prefix", "")
|
||||||
diff_id = os.getenv("ph_buildable_diff", "")
|
diff_id = os.getenv("ph_buildable_diff", "")
|
||||||
no_cache = os.getenv('ph_no_cache') is not None
|
no_cache = os.getenv('ph_no_cache') is not None
|
||||||
filter_output = '--filter-output' if os.getenv('ph_no_filter_output') is None else ''
|
filter_output = '--filter-output' if os.getenv('ph_no_filter_output') is None else ''
|
||||||
projects = os.getenv('ph_projects', 'detect')
|
projects = os.getenv('ph_projects', 'detect')
|
||||||
log_level = os.getenv('ph_log_level', 'WARNING')
|
log_level = os.getenv('ph_log_level', 'WARNING')
|
||||||
|
|
||||||
steps = []
|
steps = []
|
||||||
linux_agents = {'queue': f'{queue_prefix}linux'}
|
linux_agents = {'queue': f'{queue_prefix}linux'}
|
||||||
t = os.getenv('ph_linux_agents')
|
t = os.getenv('ph_linux_agents')
|
||||||
|
@ -40,12 +41,17 @@ if __name__ == '__main__':
|
||||||
'ccache --show-config',
|
'ccache --show-config',
|
||||||
'mkdir -p artifacts',
|
'mkdir -p artifacts',
|
||||||
'dpkg -l >> artifacts/packages.txt',
|
'dpkg -l >> artifacts/packages.txt',
|
||||||
|
# Clone scripts.
|
||||||
'export SRC=${BUILDKITE_BUILD_PATH}/llvm-premerge-checks',
|
'export SRC=${BUILDKITE_BUILD_PATH}/llvm-premerge-checks',
|
||||||
'rm -rf ${SRC}',
|
'rm -rf ${SRC}',
|
||||||
f'git clone --depth 1 --branch {scripts_branch} https://github.com/google/llvm-premerge-checks.git '
|
'git clone --depth 1 https://github.com/google/llvm-premerge-checks.git "${SRC}"',
|
||||||
'${SRC}',
|
'cd ${SRC}',
|
||||||
|
f'git fetch origin "{scripts_refspec}":x',
|
||||||
|
'git checkout x',
|
||||||
'echo "llvm-premerge-checks commit"',
|
'echo "llvm-premerge-checks commit"',
|
||||||
'git --git-dir ${SRC}/.git rev-parse HEAD',
|
'git rev-parse HEAD',
|
||||||
|
'cd "$BUILDKITE_BUILD_CHECKOUT_PATH"',
|
||||||
|
|
||||||
'set +e',
|
'set +e',
|
||||||
# Add link in review to the build.
|
# Add link in review to the build.
|
||||||
'${SRC}/scripts/phabtalk/add_url_artifact.py '
|
'${SRC}/scripts/phabtalk/add_url_artifact.py '
|
||||||
|
@ -81,11 +87,18 @@ if __name__ == '__main__':
|
||||||
'commands': [
|
'commands': [
|
||||||
clear_sccache if no_cache else '',
|
clear_sccache if no_cache else '',
|
||||||
'sccache --zero-stats',
|
'sccache --zero-stats',
|
||||||
|
|
||||||
|
# Clone scripts.
|
||||||
'set SRC=%BUILDKITE_BUILD_PATH%/llvm-premerge-checks',
|
'set SRC=%BUILDKITE_BUILD_PATH%/llvm-premerge-checks',
|
||||||
'rm -rf %SRC%',
|
'rm -rf %SRC%',
|
||||||
f'git clone --depth 1 --branch {scripts_branch} https://github.com/google/llvm-premerge-checks.git %SRC%',
|
'git clone --depth 1 https://github.com/google/llvm-premerge-checks.git %SRC%',
|
||||||
|
'cd %SRC%',
|
||||||
|
f'git fetch origin "{scripts_refspec}":x',
|
||||||
|
'git checkout x',
|
||||||
'echo llvm-premerge-checks commit:',
|
'echo llvm-premerge-checks commit:',
|
||||||
'git --git-dir %SRC%/.git rev-parse HEAD',
|
'git rev-parse HEAD',
|
||||||
|
'cd %BUILDKITE_BUILD_CHECKOUT_PATH%',
|
||||||
|
|
||||||
'powershell -command "'
|
'powershell -command "'
|
||||||
f'%SRC%/scripts/premerge_checks.py --projects=\'{projects}\' --log-level={log_level} {filter_output}; '
|
f'%SRC%/scripts/premerge_checks.py --projects=\'{projects}\' --log-level={log_level} {filter_output}; '
|
||||||
'\\$exit=\\$?;'
|
'\\$exit=\\$?;'
|
||||||
|
@ -122,7 +135,7 @@ if __name__ == '__main__':
|
||||||
'buildkite-agent artifact download "*_result.json" .',
|
'buildkite-agent artifact download "*_result.json" .',
|
||||||
'export SRC=${BUILDKITE_BUILD_PATH}/llvm-premerge-checks',
|
'export SRC=${BUILDKITE_BUILD_PATH}/llvm-premerge-checks',
|
||||||
'rm -rf ${SRC}',
|
'rm -rf ${SRC}',
|
||||||
f'git clone --depth 1 --branch {scripts_branch} https://github.com/google/llvm-premerge-checks.git '
|
f'git clone --depth 1 --branch {scripts_refspec} https://github.com/google/llvm-premerge-checks.git '
|
||||||
'${SRC}',
|
'${SRC}',
|
||||||
'${SRC}/scripts/buildkite/summary.py',
|
'${SRC}/scripts/buildkite/summary.py',
|
||||||
],
|
],
|
||||||
|
|
|
@ -18,7 +18,7 @@ import os
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
scripts_branch = os.getenv("scripts_branch", "master")
|
scripts_refspec = os.getenv("ph_scripts_refspec", "master")
|
||||||
queue_prefix = os.getenv("ph_queue_prefix", "")
|
queue_prefix = os.getenv("ph_queue_prefix", "")
|
||||||
no_cache = os.getenv('ph_no_cache') is not None
|
no_cache = os.getenv('ph_no_cache') is not None
|
||||||
filter_output = '--filter-output' if os.getenv('ph_no_filter_output') is None else ''
|
filter_output = '--filter-output' if os.getenv('ph_no_filter_output') is None else ''
|
||||||
|
@ -40,12 +40,17 @@ if __name__ == '__main__':
|
||||||
'ccache --show-config',
|
'ccache --show-config',
|
||||||
'mkdir -p artifacts',
|
'mkdir -p artifacts',
|
||||||
'dpkg -l >> artifacts/packages.txt',
|
'dpkg -l >> artifacts/packages.txt',
|
||||||
|
# Clone scripts.
|
||||||
'export SRC=${BUILDKITE_BUILD_PATH}/llvm-premerge-checks',
|
'export SRC=${BUILDKITE_BUILD_PATH}/llvm-premerge-checks',
|
||||||
'rm -rf ${SRC}',
|
'rm -rf ${SRC}',
|
||||||
f'git clone --depth 1 --branch {scripts_branch} https://github.com/google/llvm-premerge-checks.git '
|
'git clone --depth 1 https://github.com/google/llvm-premerge-checks.git "${SRC}"',
|
||||||
'${SRC}',
|
'cd ${SRC}',
|
||||||
|
f'git fetch origin "{scripts_refspec}":x',
|
||||||
|
'git checkout x',
|
||||||
'echo "llvm-premerge-checks commit"',
|
'echo "llvm-premerge-checks commit"',
|
||||||
'git --git-dir ${SRC}/.git rev-parse HEAD',
|
'git rev-parse HEAD',
|
||||||
|
'cd "$BUILDKITE_BUILD_CHECKOUT_PATH"',
|
||||||
|
|
||||||
'set +e',
|
'set +e',
|
||||||
f'${{SRC}}/scripts/premerge_checks.py --projects="{projects}" --log-level={log_level} {filter_output}',
|
f'${{SRC}}/scripts/premerge_checks.py --projects="{projects}" --log-level={log_level} {filter_output}',
|
||||||
'EXIT_STATUS=\\$?',
|
'EXIT_STATUS=\\$?',
|
||||||
|
@ -77,11 +82,18 @@ if __name__ == '__main__':
|
||||||
'commands': [
|
'commands': [
|
||||||
clear_sccache if no_cache else '',
|
clear_sccache if no_cache else '',
|
||||||
'sccache --zero-stats',
|
'sccache --zero-stats',
|
||||||
|
|
||||||
|
# Clone scripts.
|
||||||
'set SRC=%BUILDKITE_BUILD_PATH%/llvm-premerge-checks',
|
'set SRC=%BUILDKITE_BUILD_PATH%/llvm-premerge-checks',
|
||||||
'rm -rf %SRC%',
|
'rm -rf %SRC%',
|
||||||
f'git clone --depth 1 --branch {scripts_branch} https://github.com/google/llvm-premerge-checks.git %SRC%',
|
'git clone --depth 1 https://github.com/google/llvm-premerge-checks.git %SRC%',
|
||||||
|
'cd %SRC%',
|
||||||
|
f'git fetch origin "{scripts_refspec}":x',
|
||||||
|
'git checkout x',
|
||||||
'echo llvm-premerge-checks commit:',
|
'echo llvm-premerge-checks commit:',
|
||||||
'git --git-dir %SRC%/.git rev-parse HEAD',
|
'git rev-parse HEAD',
|
||||||
|
'cd %BUILDKITE_BUILD_CHECKOUT_PATH%',
|
||||||
|
|
||||||
'powershell -command "'
|
'powershell -command "'
|
||||||
f'%SRC%/scripts/premerge_checks.py --projects=\'{projects}\' --log-level={log_level} {filter_output}; '
|
f'%SRC%/scripts/premerge_checks.py --projects=\'{projects}\' --log-level={log_level} {filter_output}; '
|
||||||
'\\$exit=\\$?;'
|
'\\$exit=\\$?;'
|
||||||
|
|
|
@ -41,12 +41,15 @@ if __name__ == '__main__':
|
||||||
'depends_on': 'create-branch',
|
'depends_on': 'create-branch',
|
||||||
'build': {
|
'build': {
|
||||||
'branch': f'phab-diff-{diff_id}',
|
'branch': f'phab-diff-{diff_id}',
|
||||||
'env': {'scripts_branch': '${BUILDKITE_BRANCH}'},
|
'env': {},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for e in os.environ:
|
for e in os.environ:
|
||||||
if e.startswith('ph_'):
|
if e.startswith('ph_'):
|
||||||
build_linux_step['build']['env'][e] = os.getenv(e)
|
build_linux_step['build']['env'][e] = os.getenv(e)
|
||||||
|
# Set scripts source from the current build if it's not yet defined.
|
||||||
|
if 'ph_scripts_refspec' not in build_linux_step['build']['env']:
|
||||||
|
build_linux_step['build']['env']['ph_scripts_refspec'] = '${BUILDKITE_BRANCH}'
|
||||||
steps.append(create_branch_step)
|
steps.append(create_branch_step)
|
||||||
if run_build:
|
if run_build:
|
||||||
steps.append(build_linux_step)
|
steps.append(build_linux_step)
|
||||||
|
|
Loading…
Reference in a new issue