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

Initializing upstream branch in empty repositories #21

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

liarco
Copy link

@liarco liarco commented Oct 1, 2021

While working on #20 I run into an issue with empty target repositories: brand new repositories are empty and don't have any commit, but his action fails pushing changes those kind of repositories.

I ended up with this solution:
The command git rev-list -n 1 --all outputs the latest commit hash or nothing when there is no commit yet. Testing the result of this command allows us to run a git branch -M TARGET_BRANCH on the repository before trying to commit any changes.

Here you can see a successful run on a brand new target repository: https://github.com/liarco/split-action-test-monorepo/runs/3768603331?check_suite_focus=true#step:4:63

Thank you for your time.

@TomasVotruba
Copy link
Collaborator

Hi, thanks for you PR. We'll need some kind of automated test to keep this working in the future. Could you add one?

@liarco
Copy link
Author

liarco commented Oct 1, 2021

Yes, of course!
Let me think about a proper way to create a bare repository (same as the one used by GitHub) and run the action against that.

I'm gonna work on it.

@liarco liarco marked this pull request as draft October 1, 2021 16:12
@liarco
Copy link
Author

liarco commented Oct 4, 2021

Hi @TomasVotruba I found two possible ways to create this test, but each has its pros and cons so I need your help.

1. Real GitHub repo (no code change)

This solution involves creating a new GitHub account (it wouldn't be safe to use an official one) and creating a Personal Access Token with permissions to create and delete repositories.

The action would perform the following steps:

  • the action actions/github-script is used to access the APIs
  • check if a repository named DUMMY_ACCOUNT/monorepo-split-on-empty-test exists, if so, then it will be deleted (this step is needed in order to prevent a stuck state if the test fails before deleting the repo)
  • create the repository from scratch
  • split the test package to the empty repository
  • clone the test repository to verify its integrity
  • delete the test repository from GitHub

✅ Pros

  • no need to change the source code

❌ Cons

  • requires an access token with an high permission level and it might be subject to abuses

2. Changing the action in order to support both local paths and remote repositories

The option 1 requires a real GitHub repository because we can't run the action on local repositories, but we may add one argument like repository_path and implement the support for it as follows:

  • the configuration class should fail the input validation if both repository_path and one of repository_organization, repository_name or repository_host are set at the same time
  • if a remote repository is configured, then everything works the same as before
  • if a local path is set, then it will be used instead of the remote one

The test action would perform the following steps:

  • create the empty bare repository locally
  • run the action with the local path set as target

✅ Pros

  • no need to use risky permissions or extra accounts
  • no need to create/delete GitHub repositories on each run (this may be seen like an abuse?)

❌ Cons

  • we need to implement the support for local target repositories

I didn't try any of these, do you have any suggestion?

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