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

Add github-server-url option (and more) #70

Closed
wants to merge 17 commits into from
Closed

Add github-server-url option (and more) #70

wants to merge 17 commits into from

Conversation

jcbhmr
Copy link
Contributor

@jcbhmr jcbhmr commented May 2, 2023

This PR would...

  • Add a github-server-url input option
  • Change the description of repository to reflect that it's just user/repo now
  • Change the descriptions in the readme to match
  • Pass it in action.yml to the script
  • Use it in the bash script
  • Fix the test.yml token param that was still x:$TOKEN to just the default

This PR would also do

  • Use gh CLI instead of plain git
  • Use more GITHUB_* env vars to override/replace those from https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables with the ones that the user wants (i.e. replace $GITHUB_TOKEN with $INPUT_TOKEN)
  • ❓ Use GIT_* env vars to override/setup git features as defined https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables
  • Remove git_exists.sh since we use catching-style instead of pretesting-style code for error handling
  • Move src/index.sh to index.sh since having a folder for one file seems redundant. if we add more files in the future, re-add the src/ folder.
  • Fix up some of the error print messaging >&2 stderr stuff when repo clone fails
    these things were outside the scope of what i originally wanted to do, but just kinda happened as i made more changes...

using more $GITHUB_* env vars has the added benefit of interop-ing well with gh since gh sniffs $GITHUB_TOKEN for its auth token

closes #68
closes #67
closes #59 via using gh instead of rolling our own
closes #2 via using gh which handles that for us

@jcbhmr jcbhmr changed the title Add github-server-url option (and restructure) Add github-server-url option (and more) May 2, 2023
@jcbhmr jcbhmr marked this pull request as ready for review May 2, 2023 19:33
@jcbhmr
Copy link
Contributor Author

jcbhmr commented May 2, 2023

@spenserblack requesting review
this is a relatively big pr

index.sh Outdated Show resolved Hide resolved
index.sh Outdated Show resolved Hide resolved
Co-authored-by: Spenser Black <spenserblack01@gmail.com>
@jcbhmr
Copy link
Contributor Author

jcbhmr commented May 3, 2023

Btw do you know what the gh repo sync command does? Is it akin to git pull or git push or both? I'm confused
https://cli.github.com/manual/gh_repo_sync

@spenserblack
Copy link
Owner

Never actually used repo sync, since I just do pull/push. But it looks like it's similar to VS Code's sync. So it pulls if the repo is behind, and pushes if the repo is ahead. Personally I'd prefer to continue using pull/push, but I guess some would want a catch-all command before and after making changes 🤷

index.sh Show resolved Hide resolved
echo "🟪 Cloning $GITHUB_REPOSITORY.wiki into $INPUT_PATH..."
cd "$INPUT_PATH"
gh repo clone "$GITHUB_REPOSITORY.wiki" .git -- --bare
trap 'rm -rf .git' SIGINT SIGTERM ERR EXIT
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is this a good cleanup operation, or is there a better way? bash doesn't really have try-finally

Copy link
Owner

Choose a reason for hiding this comment

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

Perhaps we can just naively cleanup at the end without any "try-finally" behavior. The majority of workflows would stop if this action fails, which basically "cleans up," except possibly in a self-hosted runner. On failure, the .git folder can continue to exist for the user's debug purposes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i added a bunch of logs with using the 🟥🟧🟨🟩🟦🟪⬛ emojis like log levels. i know gh actions have like fancy builtin ::warning:: or something.. should I be using that? 😆

https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions

Copy link
Owner

Choose a reason for hiding this comment

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

🤔 Yeah, probably best to use the built-in log levels

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is it ok if i do that in a separate pr to avoid this getting too big, or do you want me to do it now?

Copy link
Owner

Choose a reason for hiding this comment

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

🤔 Yeah, probably best to use the built-in log levels

index.sh Show resolved Hide resolved
# https://stackoverflow.com/a/28180781
echo "🟪 Cloning $GITHUB_REPOSITORY.wiki into $INPUT_PATH..."
cd "$INPUT_PATH"
gh repo clone "$GITHUB_REPOSITORY.wiki" .git -- --bare
Copy link
Owner

Choose a reason for hiding this comment

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

Just realized that this could have a potential conflict with the documented usage to use path: ., since a .git directory will likely already exist at ./.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ohh shoot yeah
thats a problem when just plain git init-ing or git clone --bare-ing 😱

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we could use:

  • GIT_DIR is the location of the .git folder. If this isn’t specified, Git walks up the directory tree until it gets to ~ or /, looking for a .git directory at every step.
  • GIT_WORK_TREE is the location of the root of the working directory for a non-bare repository. If --git-dir or GIT_DIR is specified but none of --work-tree, GIT_WORK_TREE or core.worktree is specified, the current working directory is regarded as the top level of your working tree.
    from https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables

and basically do

export GIT_DIR=../wiki.git
export GIT_WORK_TREE="$INPUT_PATH"
gh repo clone "$GITHUB_REPOSITORY" "$GIT_DIR" -- --bare
git config --unset core.bare
git reset

?? 🤔

echo "🟪 Cloning $GITHUB_REPOSITORY.wiki into $INPUT_PATH..."
cd "$INPUT_PATH"
gh repo clone "$GITHUB_REPOSITORY.wiki" .git -- --bare
trap 'rm -rf .git' SIGINT SIGTERM ERR EXIT
Copy link
Owner

Choose a reason for hiding this comment

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

Perhaps we can just naively cleanup at the end without any "try-finally" behavior. The majority of workflows would stop if this action fails, which basically "cleans up," except possibly in a self-hosted runner. On failure, the .git folder can continue to exist for the user's debug purposes.

@jcbhmr jcbhmr mentioned this pull request May 8, 2023
@jcbhmr
Copy link
Contributor Author

jcbhmr commented May 17, 2023

closing in favor of more focused for things from #73

@jcbhmr jcbhmr closed this May 17, 2023
@jcbhmr jcbhmr deleted the add-github-server-url branch May 26, 2023 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants