forked from AndreasAugustin/actions-template-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/enable git app #1
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
Merged
msiebeneicher
merged 19 commits into
msiebeneicher:feat/use_gh_auth_for_authentication
from
AndreasAugustin:feat/enable_git_app
Jan 3, 2023
Merged
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d1717e2
feat(gh-auth): add gh auth login and credential helper
4c18507
feat(gh-auth): add own source_repo_github_token handling for template…
3590d73
chore(): add test for PAT :rocket:
AndreasAugustin 9b74224
chore(gh-cli): update gh cli version to latest :rocket:
AndreasAugustin edc9216
# This is a combination of 6 commits.
AndreasAugustin 7c68c1c
parent 9b742247ad7218490f30978af7abf4d6fc4ed9ad
AndreasAugustin 561434a
Merge branch 'feat/use_gh_auth_for_authentication' into feat/enable_g…
AndreasAugustin 1b2dd57
fix(): small logic fix in script
AndreasAugustin f274056
fix(): small logic fix in script
AndreasAugustin 42728fc
feat(): #238 hopefully a final version :rocket:
AndreasAugustin abd4251
feat(): #238 hopefully a final version :rocket:
AndreasAugustin 7f15131
feat(): #238 hopefully a final version :rocket:
AndreasAugustin 0419389
feat(): #238 hopefully a final version :rocket:
AndreasAugustin 69f59a2
feat(): #238 hopefully a final version :rocket:
AndreasAugustin 0264978
Update test_ssh.yml
AndreasAugustin 33baa75
Update test.yml
AndreasAugustin ed6009a
Update entrypoint.sh
AndreasAugustin a2527a0
fix(): fix for GITHUB_TOKEN env variable :bug:
AndreasAugustin 1435ce1
fix(): fix for GITHUB_TOKEN env variable :bug:
AndreasAugustin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| name: test-pat | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| # manual trigger | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| test-implementation-job: | ||
|
|
||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| # To use this repository's private action, you must check out the repository | ||
| - | ||
| name: Checkout | ||
| uses: actions/checkout@v3 | ||
| - | ||
| name: Test action step PAT | ||
| uses: ./ # Uses an action in the root directory | ||
| with: | ||
| github_token: ${{ secrets.SOURCE_REPO_PAT }} | ||
| source_repo_path: ${{ secrets.SOURCE_REPO_PATH_TEST }} # <owner/repo>, should be within secrets | ||
| is_dry_run: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,8 +63,7 @@ You will receive a pull request within your repository if there are some changes | |
| | github_token | Token for the repo. Can be passed in using `$\{{ secrets.GITHUB_TOKEN }}` | `true` | | | ||
| | source_repo_path | Repository path of the template | `true` | | | ||
| | upstream_branch | The target branch | `true` | `main` | | ||
| | source_repo_ssh_private_key | `[optional]` private ssh key for the source repository. E.q. useful if using a private template repository. [see](#private-template-repository)| `false` | | | ||
| | source_repo_github_token | `[optional]` separate github token to interact with the source repository. | `false` | `$\{{ inputs.github_token }}` | | ||
| | source_repo_ssh_private_key | `[optional]` private ssh key for the source repository. [see](#private-template-repository)| `false` | | | ||
| | pr_branch_name_prefix | `[optional]` the prefix of branches created by this action | `false` | `chore/template_sync` | | ||
| | pr_title | `[optional]` the title of PRs opened by this action. Must be already created. | `false` | `upstream merge template repository` | | ||
| | pr_labels | `[optional]` comma separated list. [pull request labels][pr-labels]. Must be already created. | `false` | | | ||
|
|
@@ -89,7 +88,8 @@ If you have a private template repository. | |
|
|
||
| #### Using github app | ||
|
|
||
| You can create and use a [GitHub App](https://docs.github.com/en/developers/apps/getting-started-with-apps/about-apps#about-github-apps) to handle the access to your private repository. To generate a token for your app you can use a separate action like [tibdex/github-app-token](https://github.com/tibdex/github-app-token). | ||
| You can create and use a [GitHub App][github-app] to handle the access to your private repository. | ||
| To generate a token for your app you can use a separate action like [tibdex/github-app-token][github-app-token]. | ||
|
|
||
| ```yaml | ||
| jobs: | ||
|
|
@@ -105,10 +105,9 @@ jobs: | |
| private_key: ${{ secrets.PRIVATE_KEY }} | ||
|
|
||
| - name: actions-template-sync | ||
| uses: AndreasAugustin/[email protected].0-draft | ||
| uses: AndreasAugustin/[email protected].5-draft | ||
| with: | ||
| github_token: ${{ secrets.GITHUB_TOKEN }} | ||
| source_repo_github_token: ${{ steps.generate_token.outputs.token }} | ||
| github_token: ${{ steps.generate_token.outputs.token }} | ||
| source_repo_path: <owner/repo> | ||
| upstream_branch: <target_branch> # defaults to main | ||
| pr_labels: <label1>,<label2>[,...] # optional, no default | ||
|
|
@@ -143,7 +142,7 @@ jobs: | |
|
|
||
| ## Ignore Files | ||
|
|
||
| Create a `.templatesyncignore` file. Just like writing a `.gitignore` file, follow the [glob pattern](https://en.wikipedia.org/wiki/Glob_(programming)) | ||
| Create a `.templatesyncignore` file. Just like writing a `.gitignore` file, follow the [glob pattern][glob-pattern] | ||
| in defining the files and folders that should be excluded from syncing with the template repository. | ||
|
|
||
| It can also be stored inside `.github` folder. | ||
|
|
@@ -212,3 +211,6 @@ specification. Contributions of any kind welcome! | |
| [pr-labels]: https://docs.github.com/en/issues/using-labels-and-milestones-to-track-work/managing-labels | ||
| [devto-example]: https://dev.to/andreasaugustin/github-actions-template-sync-1g9k | ||
| [github-example]: https://github.com/AndreasAugustin/teaching/blob/main/docs/git/git_action_sync.md | ||
| [github-app]: https://docs.github.com/en/developers/apps/getting-started-with-apps/about-apps#about-github-apps | ||
| [glob-pattern]: https://en.wikipedia.org/wiki/Glob_(programming) | ||
| [github-app-token]: https://github.com/tibdex/github-app-token | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 working, if
GITHUB_TOKENenv variable is set, the command throws.@msiebeneicher is it possible that you use another
ghversion? I do not understand why this is happeningThere 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.
The order here looks mandatory. Also it is not possible to use
gh auth statushere because gh wants to check a github.com auth by default which is not possible in a github enterprise setup. A working solution for my setup is this:Uh oh!
There was an error while loading. Please reload this page.
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.
related to docs
gh auth statusshould also work on other hosts (GitHub enterprise), but seems not?Related to your working solution

n. Sad but it does not work on github.com https://github.com/AndreasAugustin/actions-template-sync/actions/runs/3823961230/jobs/6505672841
hmmm if it is not a
gh --versionissue, I guess it is a runner issue (or some magic with the former github app to token action)Tested on https://github.com/AndreasAugustin/actions-template-sync/tree/chore/auto_test_2

with
Update
we need to change
gh auth status --hostname <hostname>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.
weird - for me it's running fine with gh 2.15.0:
So back to the idea of unsetting the default github_token and using an own env var for it?
Uh oh!
There was an error while loading. Please reload this page.
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 weird, just tested on my machine within a docker container also with version
2.15.0(actually within the sync action2.21.1is used).It is an alpine image, but also on my arch based system I receive the same error with that small test. Hmmm maybe the hostname?
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.
aha! maybe the hostname is the issue. Related to https://cli.github.com/manual/gh_help_environment
GH_TOKEN, GITHUB_TOKEN (in order of precedence): an authentication token for github.com API requests. Setting this avoids being prompted to authenticate and takes precedence over previously stored credentials.It states there explicitly
github.amrom.workers.dev.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.
UPDATE
confirmed! It is the
hostnamevariableThere 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.
@msiebeneicher with the changes I just made, the tests are working within github.com. Can you please test them in your env?
Hopefully finally it is a working solution!
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.
The last solution works also in my environment 🥳
good catch! Do you want to clean up the code before merge?
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.
think the code is cleaned up, but I will check.
That was a funny and hard issue...