How to trigger a workflow when a repo is created from a template #52965
-
Select Topic AreaQuestion BodyI have looked at the list of events documented in events that trigger workflows and none of these seem to be appropriate for what I need. I have defined a golang template repo that is designed to enable a user to quickly create a cli app with various features without going through the laborious process of implementing boilerplate functionality. Currently when the template is instantiated into a new repo, there are multiple references in the new repo that need to be modified. To ease this process, I have also defined various shell functions (zsh/bash) that perform these updates. But it is still a manual process. I had the idea of automating this via an event so that when the instantiation occurs, the script could be invoked. (Clearly, the event should only be triggered in the new repo, not the template). This means that when the use clones the repo, it is ready to work on immediately. Is there a way to do this? Perhaps even via a web hook? If not, I'll try and raise a feature request to get a new event defined. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
|
Looking at how the GitHub Skills templates do it: They use the |
Beta Was this translation helpful? Give feedback.
-
|
Just for documentation purposes, I'm posting how I fixed this issue with the info gleaned from the GitHub Skills templates do it: name: Initialise Repo
on:
workflow_dispatch:
push:
branches:
- master
permissions:
contents: write
jobs:
run-script:
name: run script
# We will only run this action when this repository isn't the
# template repository
#
if: >-
${{ !github.event.repository.is_template }}
runs-on: ubuntu-latest
steps:
- name: Configure Git
run: |
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR_EMAIL}"
shell: bash
- name: Checkout
uses: actions/checkout@v3
- name: Run script
run: |
. ./scripts/create-version-file.sh
create-version-file
# TODO: delete this workflow file
- name: Add files and commit changes
run: |
git add .
git commit -m "Automated changes"
git push -u origin master
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
The script invoked, create-version-file simply creates an initial VERSION file, which is checked in by the subsequent steps. I suppose the only thing I could do to improve the workflow would be to find a way to get the branch name dynamically, as it is currently hardcoded to master, which clearly wont work if the default branch is main. |
Beta Was this translation helpful? Give feedback.
This comment was marked as spam.
This comment was marked as spam.
-
|
A bin store finder is a helpful tool or search resource designed to connect shoppers with nearby liquidation and discount bin stores, where products—often sourced from returns or excess inventory of major retailers like Amazon—are sold at significantly reduced prices. These tools simplify the process of discovering local bargain spots by organizing store locations, basic details, and sometimes customer insights in one place, making it easier for users to explore “treasure hunt” style shopping without spending time searching across multiple platforms. Overall, a bin store finder enhances convenience and helps deal-seekers quickly locate affordable shopping opportunities in their area. |
Beta Was this translation helpful? Give feedback.
-
|
GitHub currently does not provide any event that triggers when a repository is created from a template. When a user clicks “Use this template”, a new repo is created, but no workflow runs automatically, and there is no event like template_instantiated. Also, GitHub does not allow auto-executing scripts on clone for security reasons. The best practical solution is to include a setup script (setup.sh) in your template that updates all references (like module name, repo name, etc.). Users can run it once after creating the repo. You can also optionally add a Makefile shortcut or a manual GitHub Action (workflow_dispatch) for convenience. For a more advanced and fully automated approach, tools like Cookiecutter can generate a ready-to-use project with user inputs, avoiding post-processing entirely. 💻 Code (Setup Script + Makefile) echo "🚀 Running setup..." REPO_NAME=$(basename "$(pwd)") echo "📦 Repo: $REPO_NAME" Update go.mod[ -f go.mod ] && sed -i "s/$TEMPLATE_NAME/$REPO_NAME/g" go.mod Replace all referencesfind . -type f -not -path "/.git/" -exec sed -i "s/$TEMPLATE_NAME/$REPO_NAME/g" {} + echo "✅ Setup complete!" </>makefile 👉 Run: make init |
Beta Was this translation helpful? Give feedback.
Looking at how the GitHub Skills templates do it: They use the
pushevent, with one job that checks if the push is actually the one on repository creation, and another that runs only if that first job confirmed it is. You could do something similar, and recommend people delete the workflow after.