| name | publish-exercise |
| description | Publish a GitHub Skills exercise repository safely to GitHub. Use when asked to create the remote repository, prepare repository settings, and publish an exercise after review is complete. |
Publish Exercise
-
Check the exercise repository for a remote. If it already has one, do nothing.
- Only consider repositories in the
/workspaces/repos/** folder.
-
Try to determine the current user's GitHub account username.
- GitHub CLI authenticated user
gh auth status
- Environment variables
echo $GITHUB_OWNER
- Other repositories in the parent folder
-
Ask the user if they would like to publish the current exercise repository to that location.
-
If they reject, do nothing and exit.
-
If they confirm, create an empty repository in their account with the same name as the current exercise repository. Add the remote but do not publish the exercise repository yet!
gh repo create {owner}/{exercise-name} --private
- Disable Actions on the repository to prevent any of the exercise workflows from accidentally triggering during publishing.
gh api -X PUT repos/{owner}/{exercise-name}/actions/permissions -F enabled=false | cat
-
Before publishing, adjust the following repository settings:
-
Set the repository as template.
gh api -X PATCH /repos/{owner}/{exercise-name} -F is_template=true | cat
- Set the repository description to match the exercise description from the top of the README.
gh api -X PATCH /repos/{owner}/{exercise-name} -f description="{description}" | cat
-
Publish the exercise repository to the user's account.
- If you fail to publish it, there is probably a permissions issue. Ask the user to manually publish.
git push -u origin main
- Do not continue until the repository is successfully published, otherwise the next steps do not make sense.
-
After publishing, disable current workflows and reenable Actions.
-
Check the exercise repository for workflows. Disable all workflows that are found.
gh api -X GET /repos/{owner}/{exercise-name}/actions/workflows | cat
gh api -X PUT /repos/{owner}/{exercise-name}/actions/workflows/{workflow_id}/disable | cat
- Re-enable Actions on the repository, leaving workflows disabled and untriggered.
gh api -X PUT repos/{owner}/{exercise-name}/actions/permissions -F enabled=true | cat
- Update the
template_owner in the "Copy Exercise" button's URL from skills to the new repository owner. Commit and push the change.