Skip to content

Commit 4842be9

Browse files
committed
feat(post): add article on GitHub actions/checkout error messages with images
1 parent 9ed7803 commit 4842be9

File tree

6 files changed

+142
-0
lines changed

6 files changed

+142
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,11 @@ This work is published under [MIT][mit] License.
5454
[use-template]: https://github.com/cotes2020/chirpy-starter/generate
5555
[CD]: https://en.wikipedia.org/wiki/Continuous_deployment
5656
[mit]: https://github.com/cotes2020/chirpy-starter/blob/master/LICENSE
57+
58+
## Working with Drafts
59+
60+
- Create post in the `_drafts` folder
61+
- Can be viewed using the --drafts flag
62+
- Posts in `_drafts` typically don't have the date in the file name
63+
- bundle exec jekyll serve --drafts
64+
- bundel exec jekyll serve --drafts --livereload
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
---
2+
title: GitHub actions/checkout action fails with two possible error messages
3+
Author: Mickey Gousset
4+
date: 2025-05-07 00:00:00 -0006
5+
description: I talk about the error messages, why and when they occur, and how to fix them.
6+
categories: [GitHub, Actions]
7+
tags: [GitHub, Actions]
8+
img_path: /assets/screenshots/2025-05-07-github-actions-checkout-fails-with-two-possible-error-messages
9+
image:
10+
path: splash-image.png
11+
width: 100%
12+
height: 100%
13+
alt: "You may get two different error messages when the checkout action fails"
14+
---
15+
16+
If you are using the GitHub [`actions/checkout`](https://github.com/actions/checkout) action in your [GitHub Actions workflow](https://docs.github.com/en/actions/writing-workflows/about-workflows), you may have run into one of two error messages:
17+
18+
1. **repository 'https://github.com/YourOrgName/YourRepoName/' not found**
19+
2. **could not read Username for 'https://github.com': terminal prompts disabled**
20+
21+
These errors can be frustrating, especially if you are not sure what is causing them. It can be even more frustrating when it starts to happen in a workflow that was previously working. In this post, I will explain the two error messages, why they occur, and how to fix them. But first, we need to talk a little bit about workflow permissions.
22+
23+
## Workflow Permissions
24+
25+
The [GITHUB_TOKEN](https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication) has certain default permissions when running workflows in a repository:
26+
27+
- **Read and write permissions** - workflows have read and write permissions in the repository for all the scopes
28+
- **Read repository contents and packages permissions** - workflows have read permissions in the repository for the contents and packages scopes only
29+
30+
These can be set at the repository, organization, or enterprise level. You can find this settings by going to **Settings > Actions > General** and scrolling down to the **Workflow permissions** section, shown in **Figure 1**.
31+
32+
![Figure 1. Workflow permissions settings](figure-01-workflow-permissions-settings.png){: .shadow }
33+
_Figure 1. Workflow permissions settings_
34+
35+
Notice that it talks about "scopes". Scopes are the permissions that are granted to the GITHUB_TOKEN. You can find out more about the scopes in the [GitHub documentation](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/controlling-permissions-for-github_token). Here is a quick list of all the possible scopes:
36+
37+
- actions
38+
- attestations
39+
- checks
40+
- contents
41+
- deployments
42+
- discussions
43+
- id-token
44+
- issues
45+
- metadata
46+
- models
47+
- packages
48+
- pages
49+
- pull-requests
50+
- security-events
51+
- statuses
52+
53+
Now a scope can be set to one of [three values](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/controlling-permissions-for-github_token#defining-access-for-the-github_token-permissions): `read`, `write`, or `none`. So, in the above settings, if we select **Read and write permissions**, then we are basically giving the GITHUB_TOKEN all the scopes with `read` and `write` permissions. If we select **Read repository contents and packages permissions**, then we are giving the GITHUB_TOKEN `read` permissions on the `contents` and `packages` scopes, and `none` on all the other scopes.
54+
55+
At this point, you may be asking yourself, "What does this have to do with the `actions/checkout` action?" The answer is that the `actions/checkout` action uses the GITHUB_TOKEN to authenticate with GitHub when checking out the repository. If the GITHUB_TOKEN does not have the correct permissions, then you will get one of the two error messages mentioned above. But you are only going to potentially encounter this if you are modifying your permissions in the workflow file itself.
56+
57+
## Using the `permissions` key in the workflow file
58+
59+
You can set the permissions for the GITHUB_TOKEN in your workflow file using the [`permissions` key](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/controlling-permissions-for-github_token#overview). This key can be set at the workflow level or at the job level. Here is an example of how to set it at the workflow level:
60+
61+
```yaml
62+
name: CI
63+
64+
on:
65+
workflow_dispatch:
66+
67+
permissions:
68+
issues: write
69+
pull-requests: write
70+
71+
jobs:
72+
demo-job:
73+
runs-on: ubuntu-latest
74+
steps:
75+
- uses: actions/checkout@v4
76+
...
77+
```
78+
79+
In this example, we are giving the GITHUB_TOKEN `write` permissions on the `issues` and `pull-requests` scopes. BUT, here is the catch: if you do not specify a permission for a scope, then it will default to `none`. This overrides the default permissions we talked about above.
80+
81+
So, if you do not specify a permission for the `contents` scope, then it will default to `none`, and you will get one of the two error messages mentioned above, because you no longer have permission to read the repository, and therefor the actions/checkout action cannot check out the repository.
82+
83+
Oh yeah, this does NOT apply to `public` repositories, it only applies to `internal` and `private` repositories. Public repositories always have `read` permissions for the `contents` scope.
84+
85+
Let's see how this relates to the two error messages above.
86+
87+
## Error Message: repository 'https://github.com/YourOrgName/YourRepoName/' not found
88+
89+
If you are using [GitHub Enterprise Cloud](https://docs.github.com/en/enterprise-cloud@latest/admin/overview/about-github-enterprise-cloud) and you run the workflow listed above, then you will get this error message, shown in **Figure 2**.
90+
91+
![Figure 2. Repository not found error message](figure-02-repository-not-found.png){: .shadow }
92+
_Figure 2. Repository not found error message_
93+
94+
## Error Message: could not read Username for 'https://github.com': terminal prompts disabled
95+
96+
If you are using [GitHub Enterprise Managed Users](https://docs.github.com/en/enterprise-cloud@latest/admin/managing-iam/understanding-iam-for-enterprises/about-enterprise-managed-users) and you run the workflow listed above, then you will get this error message, shown in **Figure 3**.
97+
98+
![Figure 3. Could not read Username for 'https://github.com'](figure-03-could-not-read-username.png){: .shadow }
99+
_Figure 3. Could not read Username for 'https://github.com'_
100+
101+
Now, as to why you are getting one error message over the other, I'm not completely sure, but I suspect it has to do with the slightly different authentication methods used by GitHub Enterprise Cloud and GitHub Enterprise Managed Users.
102+
103+
## Fixing the error messages
104+
105+
Fixing this is easy. Just add the `contents` scope to the `permissions` key in your workflow file, and set it to `read`. Here is an example:
106+
107+
```yaml
108+
name: CI
109+
110+
on:
111+
workflow_dispatch:
112+
113+
permissions:
114+
contents: read
115+
issues: write
116+
pull-requests: write
117+
118+
jobs:
119+
demo-job:
120+
runs-on: ubuntu-latest
121+
steps:
122+
- uses: actions/checkout@v4
123+
...
124+
```
125+
126+
This will give the GITHUB_TOKEN `read` permissions on the `contents` scope, and you will no longer get the error messages.
127+
128+
## Summary
129+
130+
In this post, we talked about the two error messages you may get when using the `actions/checkout` action in your GitHub Actions workflow. We also talked about the permissions for the GITHUB_TOKEN and how to set them in your workflow file. Finally, we showed you how to fix the error messages by adding the `contents` scope to the `permissions` key in your workflow file.
131+
132+
If you are still having issues, please feel free to reach out to me on [X](https://x.com/mickey_gousset) or [LinkedIn](https://www.linkedin.com/in/mickeygousset/).
133+
134+
Thanks for reading!
Loading
276 KB
Loading
Loading
381 KB
Loading

0 commit comments

Comments
 (0)