This works by having a GitHub repository with a GitHub Action YML file configured to run on every single commit, as the first time the repository is created from the template repository it will automatically run the GitHub Action for us.
However to avoid the GitHub Action running again and again after the initial commit to create the repository, we use the GitHub CLI to disable the action like so:
# We only ever to want to run this once for the repo created from this template so we disable the workflow
- name: Disable this workflow now we are done
run: gh workflow disable Repo-Creation
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
For this step in our GitHub action to work, we need to ensure the Action run has the correct permissions like so, in order for it to update the GitHub Action and the contents permission in order to do a git commit with the command line in a later on step.
# Reference https://docs.github.com/en/actions/security-guides/automatic-token-authentication
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
# Need to set the permissions to disable this action once we are done
# So its only ever run one time
permissions:
actions: write
contents: write
One final piece of the puzzle is that to add a conditional if statement to part of the GitHub Action in order to ensure only the child repositories created from the template run the action and the main template repository does not also trigger it, which is done like so:
# We will only run this action when this repository isn't the
# template repository
if: >-
${{ !github.event.repository.is_template }}
So go forth and make your own GitHub template repositories or use this one to kick start your next Umbraco package/project idea.
Hello 👋 It’s been a while since I blogged, but I wanted to share with you what I worked on over the Hacktoberfest period.
For those who don’t know Hacktoberfest is where Open Source repositories and communities who are participating ask for contributions be it in the form of code pull requests, documentation, design or anything else to help that project.
For me I wanted to challenge myself a little and work on a new project or codebase that I have never worked with before, but also by contributing something that I would like to use myself day to day.
For my main Hacktoberfest contribution I wanted to build a custom segment for the open source project Oh My Posh to show the current version of Umbraco found in the current folder within my terminal prompt. As I regularly switch between different projects and different versions of Umbraco, I thought this would be a useful addition for myself and potentially any other Umbraco developers.
After deciding this is what I wanted to do, I cloned the GitHub project locally on my machine and tried to get straight to work by opening the project up in VSCode, however I soon realised that the Oh My Posh was written with Go and that I have never used or written anything with the Go language. This was problematic as I was unsure on what tooling and dependencies I needed installed on my machine.
I almost gave up on the idea of contributing and remembered what I saw in the video with Scott and Jan. The Oh My Posh project has a custom DevContainer configuration to help support new contributors such as myself and that I could easily create a GitHub CodeSpace.
Creating the GitHub CodeSpace was as simple as clicking the green Code button on the GitHub repository page and clicking the Codespaces tab to Create a new codespace.
In doing so, the GitHub CodeSpace (DevContainer) configuration would configure a machine in the cloud and open up the project inside Visual Studio Code within the browser. What it had done for me magically behind the scenes was ensure I had the tooling and dependencies for writing with Go.
So now all I had to do was read the detailed Contributing documentation in the project and watch the video back of Scott and Jan to get some pointers on what files I needed to create.
The next stumbling part of the project for me was that I was unfamiliar with the Go language and its syntax but another GitHub product to help save the day. With the GitHub Codespace I was able to install and use GitHub Copilot the AI assistant who understands code. So I was able to ask Copilot how to generate a loop or read and parse contents of an XML file, it was enough to get me started and going in the right direction with what I wanted to do.
Lots of reading, trial and error and feedback and discussions on the PR from the maintainer Jan and I managed to finally achieve what I set out to do 🎉
So I present to you my Hacktoberfest contribution…
Here you can see the new Umbraco segment telling us the version of the Umbraco site in this folder is 12.0.1
Already use Oh My Posh?
Below is the JSON needed to add the Umbraco segment into your own Oh My Posh theme file in order to display the Umbraco segment. The below snippet is in the same style as my favourite theme jandedobbeleer which is the default theme that comes from Oh My Posh.
{
"type": "umbraco",
"template": " \udb81\udd49 {{ .Version }} ",
"powerline_symbol": "\ue0b0",
"style": "powerline",
"background_templates": [
"{{ if (.Modern) }}#3544B1{{ end }}",
"{{ if not (.Modern) }}#F79C37{{ end }}"
],
"foreground_templates": [
"{{ if (.Modern) }}#ffffff{{ end }}",
"{{ if not (.Modern) }}#000000{{ end }}"
]
},
How do I get my own terminal like that?
If you are like me and prefer to learn by watching than reading, then have no fear. I have got you covered with this video below, if not then carry on reading to see the steps needed to get your terminal looking a lot prettier.
VIDEO COMING SOON...
Note the following steps for this tutorial are intended for Windows users
Install Windows Terminal
If you are on Windows 11, then Windows Terminal is now part of the operating system, but if you are running Windows 10 you may need to install it from the Microsoft Store.
Install Oh My Posh
The next step is to install the prompt Oh My Posh for your chosen shell which is most likely to be Powershell as it comes with Windows.
You can install Oh My Posh from the Microsoft Store or using the command line with winget.
If it complains of an error of the file not existing then you can run this command to create the file before running the above command again.
New-Item -Path $PROFILE -Type File -Force
With the file now open in Notepad, we need to add the following to the file and save it. After doing so restart Windows terminal and all has gone well we now have a prettier prompt in our terminal.
# Run oh-my-posh when a new powershell instance starts using the default oh-my-posh theme that ships
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/jandedobbeleer.omp.json" | Invoke-Expression
Adding the Umbraco Segment
You will need to make a copy of the jandedobbeleer.omp.json theme and add in the Umbraco segment to the new copy. You can do this by running the command which will create the file jandedobbeleer.umbraco.omp.json at the root of your C drive.
Using a text editor such as VSCode, we can modify this JSON file and add in our custom Umbraco segment. For me I placed the new segment after the AWS segment. If you prefer you can simply copy and paste my configuration below.
After restarting Windows terminal you should now have a lovely pretty prompt in your terminal that can display the Umbraco version if it finds it in the current folder.
Conclusion
For me this was a fun Hacktoberfest, where I was able to challenge myself and learn a new programming language and build a useful utility to a tool I use every day.
I hope you found this useful and if you use Umbraco, I highly recommend you install and configure your terminal to make your life that bit easier.