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

WIP: Automated android branch builds #33

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

complexspaces
Copy link
Collaborator

@complexspaces complexspaces commented Sep 9, 2023

This PR is a followup to #32, in order to reduce friction around Cargo Git dependencies.

To create this, these changes introduce a new GitHub Action workflow that runs on every successful merge to main. The action follows these high-level steps:

  1. Reset the main-with-maven branch state to match main.
  2. Run the packaging script and generate the local maven repository
  3. Run git add --force to include the generated files and artifacts.
  4. Commit the artifacts in a dedicated commit that is clear in purpose.
  5. Force push and overwrite the main-with-maven branch with the new artifacts.

As the end result, there is a branch with identical contents to crates.io releases. As noted in the parent PR, this allows us to keep some of the nice properties of Cargo's Git dependency management and avoid friction between true releases.

One open question is if this should wipe out main-with-maven's Git history each time or if it should perform a git merge instead. The upsides of the former are that its simple, clean over time, and easy to follow. The downside is that a merge to main may render that commit revision useless for those. It should be available for quite some time though unless GitHub intervenes and manually purges the repository cache. I lean towards wiping it every time given the above.

@complexspaces complexspaces force-pushed the automated-android-branch branch 16 times, most recently from 2237dd9 to ba8de84 Compare September 9, 2023 05:31
@complexspaces
Copy link
Collaborator Author

complexspaces commented Sep 9, 2023

This will need some cleanup to checkout the correct branch and push only the new commit, but that is blocked on the parent PR merging so main has the new packaging script and template available.

With that said, this confirms the general idea works. You can see a commit with the pre-built maven repository here: a54d920

@complexspaces complexspaces force-pushed the automated-android-branch branch 2 times, most recently from 7c9586f to 5bf2f42 Compare September 9, 2023 06:02
Copy link
Member

@cpu cpu left a comment

Choose a reason for hiding this comment

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

Cool stuff, thank you :-)

I'm a little bit nervous about GitHub workflows that use the $GITHUB_TOKEN to write back to the repository, but I think the risk/reward tradeoff is sensible here and we can approach changes with care.

If there's a way to use branch protection rules (or some other mechanism) to further limit the workflow to only being able to operate with the Android maven branches we intend that would be a nice extra addition 🤞

Comment on lines +5 to +6
# types:
# - closed
Copy link
Member

Choose a reason for hiding this comment

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

Tagging this as a place to fixup pre-merge. I see this types arg un-commented in the upstream docs.


jobs:
update-android-branch:
# if: github.event.pull_request.merged == true
Copy link
Member

Choose a reason for hiding this comment

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

Tag for fixup.


git add --force android-release-support/*
git commit -am "[Automated] Bundle Android component artifacts"
# git push -f origin main-with-maven
Copy link
Member

Choose a reason for hiding this comment

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

one more pre-merge fixup

Comment on lines +6 to +9
#pull_request:
# merge_group:
#schedule:
# - cron: '0 18 * * *'
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to disable these? Leftover from testing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is just a testing artifact, yes. I didn't want to waste CI resources when I was pushing to this branch a lot during development. I'll make sure to undo this before merging.

Comment on lines +10 to +11
permissions:
contents: write
Copy link
Member

Choose a reason for hiding this comment

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

Maybe prudent to leave a warning at the top of this YML that changes to this workflow should be carefully vetted since it can write to the repository.

I wonder if branch protection rules to require pull-requests into main would protect against this workflow pushing main or if that would be possible through malice or bugs in the script :-/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe branch protection rules do apply to Workflow Actions as well, although I'm unsure we can exactly test the existing main protection rule without risking a little bit.

Following this comment from you:

If there's a way to use branch protection rules (or some other mechanism) to further limit the workflow to only being able to operate with the Android maven branches we intend that would be a nice extra addition 🤞

I tried adding a custom ruleset (see here) to the repository that applies to every branch except main-with-maven. I then tried to push from the CI job to a testing branch. It failed to push with a permissions error like we'd want.

The downside of it seems to be that it treats our pushes to working branches in the repository as rule bypasses as well, which causes extra noise locally 😞

remote: Bypassed rule violations for refs/heads/automated-android-branch:
remote:
remote: - Cannot update this protected ref.
remote:
To github.com:rustls/rustls-platform-verifier.git
   036ac7e..e147cb2  automated-android-branch -> automated-android-branch

Copy link
Member

Choose a reason for hiding this comment

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

The downside of it seems to be that it treats our pushes to working branches in the repository as rule bypasses as well, which causes extra noise locally

Interesting! Thanks for testing.

I'm in the habit of pushing branches to a fork and opening PRs from there, so I don't think the noise would bother me but I can see how its annoying for others that don't want the overhead of managing branches on a fork.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To clarify, I am personally fine with the noise since I know what it means, and the gained benefit of locking this job down tightly feels very worth it. If I ever get tired of it I could also switch to using a fork. IMO given that we should keep the rule before merging this and live with the very minor downsides.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could also consider adding a CODEOWNERS rule to this file to require another approval to prevent accidentally (though not malicious) updates to this workflow that are incorrect and have security consequences.

Copy link
Member

Choose a reason for hiding this comment

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

We could also consider adding a CODEOWNERS rule to this file to require another approval

I wouldn't mind that extra caution if you wouldn't :-)

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

Successfully merging this pull request may close these issues.

2 participants