Skip to content
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

Use GitHub's built-in template repo system #1197

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/template-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# File: .github/workflows/template-sync.yml
name: Sync Template Updates

on:
# cronjob trigger
schedule:
- cron: "0 0 * * *"
# manual trigger
workflow_dispatch:
jobs:
repo-sync:
runs-on: ubuntu-latest
# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
permissions:
contents: write
pull-requests: write

steps:
# To use this repository's private action, you must check out the repository
- name: Checkout
uses: actions/checkout@v4
# https://github.com/actions/checkout#usage
# uncomment if you use submodules within the repository
# with:
# submodules: true

- name: actions-template-sync
uses: AndreasAugustin/actions-template-sync@v2
with:
source_repo_path: ebetancourt/full-stack-fastapi-template
upstream_branch: master
68 changes: 10 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,77 +53,29 @@

## How To Use It

You can **just fork or clone** this repository and use it as is.
Click the "Use this template" button in the top right corner, and select "Create a new repository"

![Click the "use this template" button](img/use-this-template.png)

✨ It just works. ✨

### How to Use a Private Repository

If you want to have a private repository, GitHub won't allow you to simply fork it as it doesn't allow changing the visibility of forks.

But you can do the following:

- Create a new GitHub repo, for example `my-full-stack`.
- Clone this repository manually, set the name with the name of the project you want to use, for example `my-full-stack`:

```bash
git clone [email protected]:tiangolo/full-stack-fastapi-template.git my-full-stack
```

- Enter into the new directory:

```bash
cd my-full-stack
```

- Set the new origin to your new repository, copy it from the GitHub interface, for example:

```bash
git remote set-url origin [email protected]:octocat/my-full-stack.git
```

- Add this repo as another "remote" to allow you to get updates later:

```bash
git remote add upstream [email protected]:tiangolo/full-stack-fastapi-template.git
```
Just select "Private" for the visibility of your repo when creating it from the template.

- Push the code to your new repository:

```bash
git push -u origin master
```
![Creating a private Repo is easy](img/create-private-repo.png)

### Update From the Original Template

After cloning the repository, and after doing changes, you might want to get the latest changes from this original template.

- Make sure you added the original repository as a remote, you can check it with:

```bash
git remote -v

origin [email protected]:octocat/my-full-stack.git (fetch)
origin [email protected]:octocat/my-full-stack.git (push)
upstream [email protected]:tiangolo/full-stack-fastapi-template.git (fetch)
upstream [email protected]:tiangolo/full-stack-fastapi-template.git (push)
```

- Pull the latest changes without merging:

```bash
git pull --no-commit upstream master
```
This repo comes with a "Sync Template Updates" action that runs once a day that checks for updates in the template repo and creates a pull request automatically in your repo if anything has updated

This will download the latest changes from this template without committing them, that way you can check everything is right before committing.
![Screenshot of an automated template update PR](img/automated-template-update-prs.png)

- If there are conflicts, solve them in your editor.
- If there are conflicts, you will need to check out the branch locally, or resolve them in the GitHub web interface.

- Once you are done, commit the changes:
#### For This Action to Work, You Must Allow Actions to Create and Approve PRs

```bash
git merge --continue
```
![You need to grant GitHub Actions privileges to PRs](img/gh-actions-pr-perms.png)

### Configure

Expand Down
Binary file added img/automated-template-update-prs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/create-private-repo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/gh-actions-pr-perms.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/use-this-template.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.