-
Notifications
You must be signed in to change notification settings - Fork 1
282 lines (242 loc) · 12.9 KB
/
repo-creation.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
name: Repo-Creation
on:
push:
branches: [ "**" ]
# 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
jobs:
Init_Creation:
name: Inital Creation
runs-on: ubuntu-latest
# We will only run this action when this repository isn't the
# template repository
if: >-
${{ !github.event.repository.is_template }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup .NET CLI tool
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
- name: Setup Node & NPM
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Setup Project Name and Path Variables
shell: pwsh
run: |
$Repo = $env:GITHUB_REPOSITORY # warrenbuckley/my-awesome-idea
$Repo = $Repo.Split("/")[1] # my-awesome-idea
$ProjectName = $Repo.Replace(" ", ".").Replace("-", ".").Replace("_", ".")
$ProjectNameLower = $ProjectName.ToLower()
$WebsiteProjectName = $ProjectName + '.Website'
$WebsiteProjectCSProj = $WebsiteProjectName + '.csproj'
$RCLProjectName = $ProjectName
$RCLProjectCSProj = $RCLProjectName + '.csproj'
$ClientProjectName = $ProjectName + '.Client'
$ClientProjectNameLower = $ClientProjectName.ToLower()
## Folder Paths
$RootFolder = $env:GITHUB_WORKSPACE
$WebsiteProjectPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $WebsiteProjectName
$WebsiteCSProjPath = Join-Path -Path $WebsiteProjectPath -ChildPath $WebsiteProjectCSProj
$RCLProjectPath = Join-Path -Path $RootFolder -ChildPath $RCLProjectName
$RCLCSProjPath = Join-Path -Path $RCLProjectPath -ChildPath $RCLProjectCSProj
$ClientProjectPath = Join-Path -Path $RootFolder -ChildPath $ClientProjectNameLower
## Set the environment variables for the rest of the workflow
"UMBRACO_PROJECT_NAME=$ProjectName" | Out-File -FilePath $env:GITHUB_ENV -Append
"UMBRACO_PROJECT_NAME_LOWER=$ProjectNameLower" | Out-File -FilePath $env:GITHUB_ENV -Append
"UMBRACO_WEBSITE_PROJECT_NAME=$WebsiteProjectName" | Out-File -FilePath $env:GITHUB_ENV -Append
"UMBRACO_WEBSITE_PROJECT_CSPROJ=$WebsiteProjectCSProj" | Out-File -FilePath $env:GITHUB_ENV -Append
"UMBRACO_RCL_PROJECT_NAME=$RCLProjectName" | Out-File -FilePath $env:GITHUB_ENV -Append
"UMBRACO_RCL_PROJECT_CSPROJ=$RCLProjectCSProj" | Out-File -FilePath $env:GITHUB_ENV -Append
"UMBRACO_CLIENT_PROJECT_NAME=$ClientProjectName" | Out-File -FilePath $env:GITHUB_ENV -Append
"UMBRACO_CLIENT_PROJECT_NAME_LOWER=$ClientProjectNameLower" | Out-File -FilePath $env:GITHUB_ENV -Append
"UMBRACO_PATH_ROOT_FOLDER=$RootFolder" | Out-File -FilePath $env:GITHUB_ENV -Append
"UMBRACO_PATH_WEBSITE=$WebsiteProjectPath" | Out-File -FilePath $env:GITHUB_ENV -Append
"UMBRACO_PATH_WEBSITE_CSPROJ=$WebsiteCSProjPath" | Out-File -FilePath $env:GITHUB_ENV -Append
"UMBRACO_PATH_RCL=$RCLProjectPath" | Out-File -FilePath $env:GITHUB_ENV -Append
"UMBRACO_PATH_RCL_CSPROJ=$RCLCSProjPath" | Out-File -FilePath $env:GITHUB_ENV -Append
"UMBRACO_PATH_CLIENT=$ClientProjectPath" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Verify Variables can be read from further steps
shell: pwsh
run: |
Write-Output "UMBRACO_PROJECT_NAME: $env:UMBRACO_PROJECT_NAME"
Write-Output "UMBRACO_PROJECT_NAME_LOWER: $env:UMBRACO_PROJECT_NAME_LOWER"
Write-Output "UMBRACO_WEBSITE_PROJECT_NAME: $env:UMBRACO_WEBSITE_PROJECT_NAME"
Write-Output "UMBRACO_WEBSITE_PROJECT_CSPROJ: $env:UMBRACO_WEBSITE_PROJECT_CSPROJ"
Write-Output "UMBRACO_RCL_PROJECT_NAME: $env:UMBRACO_RCL_PROJECT_NAME"
Write-Output "UMBRACO_RCL_PROJECT_CSPROJ: $env:UMBRACO_RCL_PROJECT_CSPROJ"
Write-Output "UMBRACO_CLIENT_PROJECT_NAME: $env:UMBRACO_CLIENT_PROJECT_NAME"
Write-Output "UMBRACO_CLIENT_PROJECT_NAME_LOWER: $env:UMBRACO_CLIENT_PROJECT_NAME_LOWER"
Write-Output "UMBRACO_PATH_ROOT_FOLDER: $env:UMBRACO_PATH_ROOT_FOLDER"
Write-Output "UMBRACO_PATH_WEBSITE: $env:UMBRACO_PATH_WEBSITE"
Write-Output "UMBRACO_PATH_WEBSITE_CSPROJ: $env:UMBRACO_PATH_WEBSITE_CSPROJ"
Write-Output "UMBRACO_PATH_RCL: $env:UMBRACO_PATH_RCL"
Write-Output "UMBRACO_PATH_RCL_CSPROJ: $env:UMBRACO_PATH_RCL_CSPROJ"
Write-Output "UMBRACO_PATH_CLIENT: $env:UMBRACO_PATH_CLIENT"
- name: Create .gitignore
shell: pwsh
run: dotnet new gitignore
- name: Create Solution
shell: pwsh
run: dotnet new sln -n $env:UMBRACO_PROJECT_NAME
- name: Install Umbraco dotnet new Templates
shell: pwsh
run: dotnet new install Umbraco.Templates
- name: Create Umbraco Website
shell: pwsh
run: dotnet new umbraco -n $env:UMBRACO_WEBSITE_PROJECT_NAME
- name: Create Umbraco RCL
shell: pwsh
run: dotnet new umbracopackage-rcl -n $env:UMBRACO_RCL_PROJECT_NAME
- name: Add Website to Solution
shell: pwsh
run: dotnet sln add $env:UMBRACO_PATH_WEBSITE_CSPROJ
- name: Add RCL to Solution
shell: pwsh
run: dotnet sln add $env:UMBRACO_PATH_RCL_CSPROJ
## Delete the wwwroot/umbraco-package.json file
## The Vite setup will add this file from the client folder stuff
- name: Remove RCL wwwroot/umbraco-package.json
shell: pwsh
run: Remove-Item -Path "$env:UMBRACO_PATH_RCL/wwwroot/umbraco-package.json"
- name: Add RCL project reference to Website project
shell: pwsh
run: dotnet add $env:UMBRACO_PATH_WEBSITE_CSPROJ reference $env:UMBRACO_PATH_RCL_CSPROJ
## For vite to be happy it needs to be lowercase
- name: Create Vite TypeScript & Lit setup
shell: pwsh
run: npx create-vite@latest $env:UMBRACO_CLIENT_PROJECT_NAME_LOWER --template lit-ts
- name: Remove uneeded files from Vite setup
shell: pwsh
run: |
Remove-Item -Path "$env:UMBRACO_PATH_CLIENT/public/vite.svg"
Remove-Item -Path "$env:UMBRACO_PATH_CLIENT/src/assets" -Recurse
Remove-Item -Path "$env:UMBRACO_PATH_CLIENT/src/index.css"
Remove-Item -Path "$env:UMBRACO_PATH_CLIENT/src/my-element.ts"
Remove-Item -Path "$env:UMBRACO_PATH_CLIENT/index.html"
- name: Create vite.config.ts
shell: pwsh
run: |
$viteConfig = @"
import { defineConfig } from 'vite';
export default defineConfig({
build: {
lib: {
entry: "src/index.ts", // Entrypoint file (registers other manifests)
formats: ["es"],
fileName: '$env:UMBRACO_PROJECT_NAME_LOWER',
},
outDir: '../$env:UMBRACO_RCL_PROJECT_NAME/wwwroot', // your web component will be saved to the RCL project location and the RCL sets the path as App_Plugins/$env:UMBRACO_RCL_PROJECT_NAME
emptyOutDir: true,
sourcemap: true,
rollupOptions: {
external: [/^@umbraco/],
},
},
});
"@
$viteConfig | Out-File -FilePath "$env:UMBRACO_PATH_CLIENT/vite.config.ts" -Encoding utf8
- name: Create umbraco-package.json
shell: pwsh
run: |
$UmbracoPackageJson = @"
{
"`$schema": "../../$env:UMBRACO_WEBSITE_PROJECT_NAME/umbraco-package-schema.json",
"id": "$env:UMBRACO_PROJECT_NAME_LOWER",
"name": "$env:UMBRACO_PROJECT_NAME",
"allowPackageTelemetry": true,
"version": "1.0.0",
"extensions": [
{
"name": "$env:UMBRACO_PROJECT_NAME EntryPoint",
"alias": "$env:UMBRACO_PROJECT_NAME_LOWER.entrypoint",
"type": "backofficeEntryPoint",
"js": "/App_Plugins/$env:UMBRACO_RCL_PROJECT_NAME/$env:UMBRACO_PROJECT_NAME_LOWER.js"
}
]
}
"@
$UmbracoPackageJson | Out-File -FilePath "$env:UMBRACO_PATH_CLIENT/public/umbraco-package.json" -Encoding utf8
- name: Create index.ts entrypoint
shell: pwsh
run: |
$IndexTs = @"
import { UmbEntryPointOnInit } from '@umbraco-cms/backoffice/extension-api';
export const onInit: UmbEntryPointOnInit = (_host, _extensionRegistry) => {
console.log('Hello from $env:UMBRACO_PROJECT_NAME');
// We can register many manifests at once via code
// as opposed to a long umbraco-package.json file
// _extensionRegistry.registerMany([
// ...entityActionManifests,
// ...modalManifests
// ]);
};
"@
$IndexTs | Out-File -FilePath "$env:UMBRACO_PATH_CLIENT/src/index.ts" -Encoding utf8
- name: Add .vscode folder and recommended lit extension
shell: pwsh
run: |
New-Item -Path "$env:UMBRACO_PATH_CLIENT/.vscode" -ItemType Directory
$ExtensionsJson = @"
{
"recommendations": [
"runem.lit-plugin"
]
}
"@
$ExtensionsJson | Out-File -FilePath "$env:UMBRACO_PATH_CLIENT/.vscode/extensions.json" -Encoding utf8
- name: Update package.json scripts with watch and remove dev and 'preview'
shell: pwsh
run: |
$PackageJsonPath = Join-Path -Path $env:UMBRACO_PATH_CLIENT -ChildPath "package.json"
$PackageJson = Get-Content -Path $PackageJsonPath | ConvertFrom-Json
$PackageJson.scripts.PSObject.Properties.Remove("dev")
$PackageJson.scripts.PSObject.Properties.Remove("preview")
$PackageJson.scripts | Add-Member -MemberType NoteProperty -Name "watch" -Value "vite build --watch" -Force
$PackageJson | ConvertTo-Json | Out-File -FilePath $PackageJsonPath -Encoding utf8
- name: Add @umbraco-cms/backoffice from npm as dev-dependency
shell: pwsh
working-directory: ${{ env.UMBRACO_PATH_CLIENT }}
run: npm install --save-dev @umbraco-cms/backoffice
# Compile the TS to JS & it will copy it out to the RCL project in the wwwroot folder
- name: Inital build of client project
shell: pwsh
working-directory: ${{ env.UMBRACO_PATH_CLIENT }}
run: npm run build
# Build the VS solution (building will generate the JSON schema for umbraco-package.json that we reference)
- name: Build the VS Solution
shell: pwsh
run: dotnet build
# 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 }}
- name: Commit code changes
shell: pwsh
run: |
git config --global user.email "[email protected]"
git config --global user.name "Warren Buckley"
git add .
git commit -m "Umbraco Project Scaffolded & Vite setup added"
git push
# Write Markdown Job Summary
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-of-multiline-markdown-content
- name: Write to Job Summary
shell: pwsh
run: |
"# :rocket: Project Created" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append
"The following has been setup for you @$env:GITHUB_ACTOR" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append
"" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append # this is a blank line
"| Project | Notes |" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append
"|--------|--------|" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append
"| $env:UMBRACO_WEBSITE_PROJECT_NAME | This project is an sample Umbraco site that allows you to easily test the site |" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append
"| $env:UMBRACO_RCL_PROJECT_NAME | This is an RCL that the client project will copy files into wwwroot. This projects can be used to write any C# code such as APIControllers |" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append
"| $env:UMBRACO_CLIENT_PROJECT_NAME | Open this folder with VSCode editor and start working with the TypeScript files to extend Umbraco backoffice |" | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Append