Skip to content

Commit 375f0d7

Browse files
PepijnBPepijn Boer (imec)AndreasAugustin
authored
docs(#609): add scope of PAT for target repo (#610)
* some documentation refinements, fixes and addons --------- Signed-off-by: Andy Augustin <[email protected]> Co-authored-by: Pepijn Boer (imec) <[email protected]> Co-authored-by: Andy Augustin <[email protected]>
1 parent c8b01ed commit 375f0d7

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

README.md

+28-10
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,38 @@ jobs:
193193
:warning: when the source repository is private using PATs, also the target repository must be private.
194194
Else it won't work.
195195

196-
[Personal access token][github-pat] is an alternative to using passwords for authentication to GitHub. You can add a kind
197-
of password to your GitHub account. You need to set the scopes.
196+
[Personal access token][github-pat] is an alternative to using passwords for authentication to GitHub.
197+
You can add a kind of password to your GitHub account. The PAT needs a scope.
198+
We need different scopes for the source and target repo.
199+
200+
##### a. Source repo
201+
202+
The workflow needs read access to the source repo.
203+
204+
You need to set the scopes to read the source repo.
198205

199206
* `repo` -> all
200207
* `read:org`
201208

202-
![pat-scopes](docs/assets/pat_needed_scopes.png)
209+
![pat-scopes](docs/assets/pat_needed_scopes_source_repo.png)
203210

204211
Furthermore, you need to set the access within the source repository to allow GitHub actions within the target repository.
205212
As mentioned before (you can see the note in the image) you need to set the target repository to private.
206213
settings -> actions -> general.
207214

208215
![pat-source-repo-access](docs/assets/pat_needed_access_source_repo.png)
209216

217+
##### b. Target repo
218+
219+
When the action detects any changes, it will create a new branch and will push the updates to this branch.
220+
When no files are changed in the `.github/workflows` directory, this works well with the default `${{ github.token }}` token.
221+
This token does however not have `workflow` scope and can therefore not make any changes to these files.
222+
For this purpose a token must be created with the following scope as depicted in the figure below.
223+
224+
* `workflow` -> will also enable `repo`
225+
* `admin:read`
226+
![pat-scopes](docs/assets/pat_needed_scopes_target_repo.png)
227+
210228
example workflow definition
211229

212230
```yml
@@ -603,18 +621,18 @@ The idea is to use the [docker action][action-docker]
603621

604622
## Troubleshooting
605623

606-
* refusing to allow a GitHub App to create or update workflow `.github/workflows/******.yml` without `workflows` permission
607-
608-
This happens because the template repository is trying to overwrite some files inside `.github/workflows/`.
624+
* The error message `refusing to allow a GitHub App to create or update workflow '.github/workflows/<script-name>.yml' without 'workflows' permission)`
625+
is indicating that the PAT in the `target_gh_token` does not have the correct permissions.
626+
This happens because the template repository is trying to overwrite some files inside `.github/workflows/`.
609627

610628
Currently `GITHUB_TOKEN` can't be given `workflow` permission.
611-
You can grant our workflow with `workflows` permission using a PAT following the steps below:
629+
You can grant our workflow with `workflow` permission using a PAT following the steps below:
612630

613-
1. [Create a PAT][github-create-pat] with these repository permissions granted: `contents:write`, `workflows:write`, `metadata:read`.
631+
1. [Create a PAT][github-create-pat] with these repository permissions granted: `workflow`.
614632

615633
2. Copy the generated token and [create a new secret for your target repository][github-create-secret].
616634

617-
3. Configure the `checkout` action to use the token in secrets like this:
635+
3. Configure the `actions-template-sync` step to use the freshly generated token in `target_gh_token` like this:
618636

619637
```yaml
620638
# File: .github/workflows/template-sync.yml
@@ -639,12 +657,12 @@ The idea is to use the [docker action][action-docker]
639657
uses: actions/checkout@v4
640658
with:
641659
# submodules: true
642-
token: ${{ secrets.<secret_name> }}
643660
644661
- name: actions-template-sync
645662
uses: AndreasAugustin/actions-template-sync@v2
646663
with:
647664
source_gh_token: ${{ secrets.GITHUB_TOKEN }}
665+
target_gh_token: ${{ secrets.<secret_name> }}
648666
source_repo_path: <owner/repo>
649667
upstream_branch: <target_branch> # defaults to main
650668
pr_labels: <label1>,<label2>[,...] # optional, no default
59.6 KB
Loading

0 commit comments

Comments
 (0)