-
Notifications
You must be signed in to change notification settings - Fork 41
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
Workflow to auto deploy contracts when changed #704
Conversation
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.
We'll need to publish the addresses somewhere accessible. If we stop here, I understand we can do the following:
- Open the GitHub Actions UI.
- Find the last job where this workflow ran.
- Scroll down the list to the last step.
- Expand the logs.
- Find the two addresses we care about in the firehose of logs
- Copy each address.
However, that is wasteful for us devs and very poor UX for adopters.
Instead, let's parse the two addresses we care about, construct a .json file, and commit that .json file elsewhere public, associated with the commit. We can then use shields.io's JSON support to display those addresses in the repo's README.
Here's the cleanest and most scalable way of doing this, in a way that does not muddy the commit history of main
:
- Create a long lived
cd/contracts
branch (standing for: continuous deployment > contracts). - When contracts change, have the workflow merge the
main
branch intocd/contracts
with a merge commit. - Execute the deployment, and extract the gateway and registry addresses.
- Generate a
deployments/r314159.json
file with the two addresses + master commit deployed.
{
"commit": "<sha1>",
"gateway_addr": "<eth addr>",
"registry_addr": "<eth addr>",
}
- Push a commit from within the action, containing the merge and the updated deployments metadata.
This solution allows us to hit all checkboxes:
- Tracks exactly which contracts commit was deployed (thanks to the merge preciding the metadata update commit).
- Keeps an easiliy accessible history of contract deployments (in case someone wants to test with an early version of contracts, e.g. when bisecting a bug).
- Addresses are always viewable by users, in a predictable URL.
- Latest addresses are machine-processable, always in a predictable URL.
- Repo stays lean in size.
deploy-contracts: | ||
runs-on: ubuntu-latest | ||
env: | ||
RPC_URL: https://calibration.filfox.info/rpc/v1 |
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.
Not necessary, but can we move the URL to a secret, and make sure that the subnet deployment automation uses the same URL? Trying to reduce entropy and consolidate to a single configuration spot, in case endpoints become unstable and we need to change them.
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.
Note that github secrets do not propagate between github workflows unless you explicitly forward them with (secrets: inherit
) which is what I had to do in this PR
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.
I don't think the URL is a secret per se. Besides, it's often that a RPC URL fails or take too long to response. In that case I would just make a PR to switch it to a different provider. But if we keep track them in secrets, we probably already forgotten what URL we were using. That just make things more implicit for maintainers.
Just a note that we discussed it in sync, and aligned that we need the addresses to be available somewhere. |
For the record, the alternative that @mb1896 suggested was placing the addresses in a file in |
@mb1896 this is the GitHub Action you should use: https://github.com/stefanzweifel/git-auto-commit-action It does not require a Personal Access Token, nor a bot account. |
Thanks for the comments. I'm following @raulk 's direction now. Will for sure make this ready soon for external developers to check out. |
36ae1c9
to
77f6c82
Compare
@mb1896 just cross-posting from Slack:
|
3ba6628
to
c0357dd
Compare
74fb86a
to
08c9007
Compare
echo "commit_hash: $commit_hash" | ||
echo "gateway_address: $gateway_address" | ||
echo "registry_address: $registry_address" | ||
- name: Switch code repo to cd/contract branch |
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.
@mb1896 we're missing the merge from main
into the cd branch, prior to committing the file. Can you please add it? This will (a) place the source and the addresses in one convenient branch, (b) create a nice merge graph tracking at the git history level what got deployed when.
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.
Fixed. Please take another look.
107f7ff
to
5371767
Compare
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.
LGTM, thanks!
3f95f0d
to
7facea7
Compare
@raulk Can you take another look? |
ref: cd/contracts | ||
submodules: recursive | ||
|
||
- name: (Dry run) Try merge from main branch and update cd/contracts branch |
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.
Dry run pull merge is to verify that the condition of cd/contracts branch is able to merge with latest main branch. If failed, we will resolve whatever error manually.
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.
Calling this a dry run is at bit confusing as its actually pulling and merging (so has side effects on the runner)... its just not pushing changes.
Also "... and update cd/contracts branch" does not seem to be right
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.
Yes, the "dry" part mostly means that we will not modify remote code repos. This is useful because we can fail early when merging generate conflicts (rather than complain after deploying the contract).
I updated the step's name to better describe what it does.
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.
had some minor comment, but otherwise this looks good to me
ref: cd/contracts | ||
submodules: recursive | ||
|
||
- name: (Dry run) Try merge from main branch and update cd/contracts branch |
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.
Calling this a dry run is at bit confusing as its actually pulling and merging (so has side effects on the runner)... its just not pushing changes.
Also "... and update cd/contracts branch" does not seem to be right
@mb1896 When you're online, let's address Fridrik's comments, merge |
Btw this is great, I was already able to unblock a dev who encountered error because of contracts incompatibility by sending addresses from this commit to them.. |
9d8021a
to
d9ca09f
Compare
8ea7d51
to
0315908
Compare
Sample output file: 7d65801
Saved in
cd/contracts
branch https://github.com/consensus-shipyard/ipc/commits/cd/contracts/Closes ENG-627