Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

[CI] Add cumulus + beefy companions #9010

Closed
wants to merge 25 commits into from
Closed

Conversation

s3krit
Copy link
Contributor

@s3krit s3krit commented Jun 3, 2021

Adds companion builds to ensure we don't break cumulus & grandpa-bridge-gadget repos.
Actually builds out a generic companion-build script which takes a repo and organisation (& an optional build string) as an argument. Initially for cumulus and beefy we just run a cargo check but I'm open to changing that to something more appropriate if we feel that would be useful.
We can also specify additional dependencies. Consider the case of Cumulus:

  • Cumulus depends on polkadot and substrate
  • Polkadot also depends on substrate
  • If there is a companion PR for polkadot, when building cumulus we also need to tell cumulus to use the companion version of polkadot.

There will be a followup PR that breaks this out into another repo so we can add companion builds to other projects that have dependents we don't want to break, but baby steps :)

Initially, we're almost definitely going to have some teething problems with this PR so I don't want the statuses to be required yet... that can come later.

NOTE: For the companion to be properly detected, you need to comment with the actual name of the repo (see below's beefy companion - you can't just put 'beefy companion:')

Closes: https://github.com/paritytech/ci_cd/issues/139

Polkadot companion: paritytech/polkadot#3379
Cumulus companion: paritytech/cumulus#518
grandpa-bridge-gadget companion: paritytech/grandpa-bridge-gadget#223

@s3krit s3krit added A3-in_progress Pull request is in progress. No review needed at this stage. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. labels Jun 3, 2021
@adoerr
Copy link
Contributor

adoerr commented Jun 3, 2021

While you are at it, do you think it would be possible to include BEEFY as well? Please!! 😄

@s3krit
Copy link
Contributor Author

s3krit commented Jun 3, 2021

While you are at it, do you think it would be possible to include BEEFY as well? Please!! smile

since you asked nicely ;)

@s3krit s3krit changed the title [WIP] [CI] Add cumulus companions [WIP] [CI] Add cumulus + beefy companions Jun 3, 2021
@s3krit s3krit changed the title [WIP] [CI] Add cumulus + beefy companions [CI] Add cumulus + beefy companions Jun 3, 2021
@s3krit s3krit marked this pull request as ready for review June 3, 2021 16:38
@s3krit s3krit requested a review from a team as a code owner June 3, 2021 16:38
@github-actions github-actions bot added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Jun 3, 2021
.gitlab-ci.yml Outdated Show resolved Hide resolved
.gitlab-ci.yml Outdated Show resolved Hide resolved
.gitlab-ci.yml Outdated Show resolved Hide resolved
.gitlab-ci.yml Outdated Show resolved Hide resolved
.maintain/gitlab/check_companion_build.sh Outdated Show resolved Hide resolved
Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

When there is a polkadot companion, you will also need to overwrite polkadot in cumulus to use this companion. As otherwise it will fail to build

.maintain/gitlab/check_companion_build.sh Outdated Show resolved Hide resolved
.gitlab-ci.yml Show resolved Hide resolved
@s3krit s3krit changed the title [WIP][CI] Add cumulus + beefy companions [CI] Add cumulus + beefy companions Jun 29, 2021
.gitlab-ci.yml Outdated
variables:
COMPANION_ORG: paritytech
COMPANION_REPO: cumulus
COMPANION_BUILD: "cargo check"
Copy link
Member

Choose a reason for hiding this comment

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

Hmm this isn't really great :P I can understand why you are doing this, but honestly I don't know...

Overall it would be nice to have pre merge checks that runs the entire test suite of cumulus to make sure we don't break anything..

Copy link
Contributor

Choose a reason for hiding this comment

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

You mean it's better to trigger the entire cumulus CI here? Is it worth doing on every commit? Maybe on some certain files/dirs changes at least?

Copy link
Member

Choose a reason for hiding this comment

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

I mean for cumulus it is not that important at the moment. A cargo test --all --release would do it as well. However, even that takes some time. I would actually like to have this as a precommit check, but we don't have support for this :(

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, we're kinda stuck between not being able to use the existing tools for pre-merge pipelines and the inability to use some kind of a pre-commit tool with github.com. This means we'll be looking into how to deal with it nicely, but currently, we're scaling vertically.

Copy link
Contributor

@TriplEight TriplEight Aug 2, 2021

Choose a reason for hiding this comment

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

I suggest we could generalize these checks by actually triggering the CIs of the relevant repository. As we've been doing it with Simnet recently. This script passes overriding variables to the downstream CI and returns the status of all checks.
It will require some changes in the relevant repos, (with which @paritytech/ci will certainly help), but will be more future-proof.

Copy link
Contributor

Choose a reason for hiding this comment

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

Now, this triggering script looks like this, it's a bit more specialized for Simnet.

.gitlab-ci.yml Outdated
variables:
COMPANION_ORG: paritytech
COMPANION_REPO: cumulus
COMPANION_BUILD: "cargo check"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
COMPANION_BUILD: "cargo check"
COMPANION_BUILD: "cargo check --benches --all --tests"

Copy link
Contributor

Choose a reason for hiding this comment

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

How about cargo check --all-targets --workspace?

--all is deprecated in favour of --workspace https://doc.rust-lang.org/cargo/commands/cargo-check.html
--all-targets = --lib --bins --tests --benches --examples

.gitlab-ci.yml Outdated
variables:
COMPANION_ORG: paritytech
COMPANION_REPO: grandpa-bridge-gadget
COMPANION_BUILD: "cargo check"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
COMPANION_BUILD: "cargo check"
COMPANION_BUILD: "cargo check --benches --all --tests"


pr_body="$(sed -n -r 's/^[[:space:]]+"body": (".*")[^"]+$/\1/p' "${pr_data_file}")"

echo "${pr_body}" | sed -n -r \
Copy link
Contributor

Choose a reason for hiding this comment

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

Does sed account for newlines in the JSON string?

This probably never happens but you might have a comment like this:

Something something companion

Bla bla another pull request: https://github.com/foo/pull/1

As I understand it, since you're not matching [Cc]ompanion: [regex] all in the same line, that comment would be detected although it should not be.

Using echo -e will output the JSON newlines as actual newlines so you'll be able to match it line-by-line.

#shellcheck source=../common/lib.sh
. "$(dirname "${0}")/../common/lib.sh"

ORGANISATION=$1
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Apparently "Organisation" is valid spelling in British English but IMO it'd look better ORGANIZATION

if expr match "${CI_COMMIT_REF_NAME}" '^[0-9]\+$' >/dev/null
then
boldprint "this is pull request no ${CI_COMMIT_REF_NAME}"
pr_companion="$(get_companion "paritytech/substrate" "$CI_COMMIT_REF_NAME" "$ORGANISATION/$REPO")"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I get why "paritytech/substrate" is hardcoded for now (because this script is only used in this repository at the moment?) but it'd be good to have this as another variable for clarity's sake

diener_commands["paritytech/grandpa-bridge-gadget"]='--beefy'

for dep in "${DEPS[@]}"; do
dep_companion="$(get_companion "paritytech/substrate" "$CI_COMMIT_REF_NAME" "$dep")"
Copy link
Contributor

Choose a reason for hiding this comment

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

since you're already fetching the description once in the lines above, it would be good to reuse it instead of making more API requests

git -C "$dep" checkout "pr/${dep_companion}"
git -C "$dep" merge origin/master
# Tell this dependency to use the version of substrate in this PR
diener patch --crates-to-patch "$SUBSTRATE_DIR" --substrate --path "$dep/Cargo.toml"
Copy link
Contributor

@joao-paulo-parity joao-paulo-parity Jun 29, 2021

Choose a reason for hiding this comment

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

SUBSTRATE_DIR and --substrate will have a rework to be dynamic once this script is made more general, right?

fi

# Test pr or master branch with this Substrate commit.
diener patch --crates-to-patch ".." --substrate --path "Cargo.toml"
Copy link
Contributor

Choose a reason for hiding this comment

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

Changing this ".." to "$SUBSTRATE_DIR" makes the script less confusing to follow. It makes sense because you're doing cd at the start but it's not immediately obvious which is the current directory when this line is reached.

Comment on lines +63 to +64
git fetch --depth 100 origin
git merge origin/master
Copy link
Contributor

Choose a reason for hiding this comment

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

can it just be git pull origin master? I don't quite get the depth numbers but fetching a single branch is better than doing fetch origin (which fetches everything)

boldprint "companion pr specified/detected: #${pr_companion}"
git fetch origin "refs/pull/${pr_companion}/head:pr/${pr_companion}"
git checkout "pr/${pr_companion}"
git merge origin/master
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be merging whatever branch the PR is currently targetting instead of master (although PRs usually target master). Perhaps it doesn't need to be handled at the moment, but a FIXME note about this detail would be welcome.

git clone --depth 20 "https://github.com/$dep.git" "$dep"
git -C "$dep" fetch origin "refs/pull/${dep_companion}/head:pr/${dep_companion}"
git -C "$dep" checkout "pr/${dep_companion}"
git -C "$dep" merge origin/master
Copy link
Contributor

Choose a reason for hiding this comment

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

diener_commands["paritytech/substrate"]='--substrate'
diener_commands["paritytech/grandpa-bridge-gadget"]='--beefy'

for dep in "${DEPS[@]}"; do
Copy link
Contributor

Choose a reason for hiding this comment

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

If https://github.com/paritytech/substrate/pull/9010/files#r660727553 is taken care of, you could try to get rid of this $DEPS and just loop through all companion lines in the description; and if some repository is not supported (might be typo) then just fail the script.

@stale
Copy link

stale bot commented Jul 31, 2021

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. and removed A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. labels Jul 31, 2021
@stale
Copy link

stale bot commented Sep 5, 2021

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Sep 5, 2021
@joao-paulo-parity
Copy link
Contributor

FYI a critical bug was found in #9677 (comment). I think it's grave enough to warrant implementing a fix in a separate PR and then rebase this on top of the fix PR.

@stale stale bot removed the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Sep 5, 2021
@joao-paulo-parity
Copy link
Contributor

joao-paulo-parity commented Sep 9, 2021

FYI I've asked @s3krit to let me take over this effort. I would like to merge #9721 before moving to this since the changes over there are simpler and the implementation should be finished, right now it's simply waiting for the CI image to be updated (paritytech/scripts#309).

@joao-paulo-parity
Copy link
Contributor

The implementation I have ended up being very different from this one, so I've opened a separate PR #9749 instead of pushing code over the work here. We can revisit this if the approach in #9749 does not work well.

@stale
Copy link

stale bot commented Oct 10, 2021

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. label Oct 10, 2021
@bkchr bkchr closed this Oct 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. A5-stale Pull request did not receive any updates in a long time. No review needed at this stage. Close it. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants