Skip to content

Commit 8ec046b

Browse files
authored
Add PAT explanation
1 parent 600c205 commit 8ec046b

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

readme.md

+41
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,47 @@ Reasons for a centralized workflow repository:
99
- reusability of course: no need to update dozens of repository where 95% of workflows are the same
1010
- centralize all dependencies pertaining to automation: think of the point-release of an action that triggers dependabot upgrade to all your repositories depending on it
1111

12+
## Permissions and token
13+
14+
This repository updates itself via GitHub actions. It particularly updates its own YAML files in `.github/workflows`. That's forbidden by default. So we need extra permissions.
15+
16+
Usually, to grant special permissions to some jobs, you use the [`permissions` parameter in workflow](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions) files. It looks like this:
17+
18+
```yaml
19+
on:
20+
(...)
21+
22+
jobs:
23+
24+
my-job:
25+
runs-on: ubuntu-latest
26+
permissions:
27+
contents: write
28+
pull-requests: write
29+
30+
steps:
31+
(...)
32+
```
33+
34+
But the `contents: write` permission doesn't allow write access to the workflow files in the `.github` subfolder. There is `actions: write`, but it only covers workflow runs, not their YAML source file. Even a `permissions: write-all` doesn't work. So you cannot use the `permissions` parameter to allow a repository's workflow update its own workflow files.
35+
36+
You will always end up with this kind or errors:
37+
```text
38+
! [remote rejected] branch_xxx -> branch_xxx (refusing to allow a GitHub App to create or update workflow `.github/workflows/my_workflow.yaml` without `workflows` permission)
39+
40+
error: failed to push some refs to 'https://github.com/kdeldycke/my-repo'
41+
```
42+
43+
> [!NOTE]
44+
> That's also why the Settings > Actions > General > Workflow permissions parameter on your repository has no effect on this issue, even with the `Read and write permissions` set:
45+
>
46+
47+
To bypass the limitation, we rely on a custom access token. By convention, we call it `WORKFLOW_UPDATE_GITHUB_PAT`. It will be used, [in place of the default `secrets.GITHUB_TOKEN`](https://github.com/search?q=repo%3Akdeldycke%2Fworkflows%20WORKFLOW_UPDATE_GITHUB_PAT&type=code), in steps in which we need to change the workflow YAML files.
48+
49+
To create this custom `WORKFLOW_UPDATE_GITHUB_PAT`:
50+
- Go to your GitHub user's profile via the `Developer Settings` > `Personal Access Tokens` UI
51+
52+
1253
## Release management
1354

1455
It turns out [Release Engineering is a full-time job, and full of edge-cases](https://blog.axo.dev/2023/02/cargo-dist).

0 commit comments

Comments
 (0)