-
-
Notifications
You must be signed in to change notification settings - Fork 1
220 lines (191 loc) · 8.69 KB
/
bootstrap.yml
File metadata and controls
220 lines (191 loc) · 8.69 KB
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
name: Boostrap
run-name: "${{ github.event.repository.name }} | Bootstrap | ${{ github.run_id }} | ${{ github.event_name }}"
# This will run every time we create push a commit to `main`.
# Reference: https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
on:
workflow_dispatch:
push:
branches:
- main
# Reference: https://docs.github.com/en/actions/security-guides/automatic-token-authentication
permissions:
# Need `contents: read` to checkout the repository.
# Need `contents: write` to update the step metadata.
contents: write
jobs:
get_repo_state:
name: Get repository state
if: ${{ !github.event.repository.is_template }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Determine current state
id: current_state
run: |
if [ -f ./PSScriptModule.build.ps1 ]; then
echo "state=BOOTSTRAP_NEW_REPO" >> "$GITHUB_OUTPUT"
fi
- name: Read repository description
uses: actions/github-script@v8
id: repo
with:
script: |
const repo = await github.rest.repos.get({
owner: context.repo.owner,
repo: context.repo.repo,
});
core.setOutput('description', repo.data.description || '');
outputs:
current_state: ${{ steps.current_state.outputs.state }}
description: ${{ steps.repo.outputs.description }}
bootstrap:
name: Bootstrap
needs: get_repo_state
# We will only run this action when:
# The repository isn't the template repository.
if: >-
${{ !github.event.repository.is_template
&& needs.get_repo_state.outputs.current_state == 'BOOTSTRAP_NEW_REPO'}}
runs-on: ubuntu-latest
env:
LABELS_JSON: |
[
{"name": "dependencies", "color": "ededed", "description": "Dependency updates"},
{"name": "documentation", "color": "0075ca", "description": "Improvements or additions to documentation"},
{"name": "tests", "color": "d876e3", "description": "Related to tests"},
{"name": "devcontainer", "color": "0e8a16", "description": "Related to development container"},
{"name": "vscode", "color": "1d76db", "description": "Related to Visual Studio Code settings"},
{"name": "ci-cd", "color": "bfdadc", "description": "Related to GitHub Actions CI"},
{"name": "build", "color": "5319e7", "description": "Build related changes"},
{"name": "github", "color": "6e5494", "description": "GitHub configuration changes"},
{"name": "breaking", "color": "ff0000", "description": "Breaking changes"},
{"name": "feature", "color": "0e8a16", "description": "New feature or enhancement"},
{"name": "bugfix", "color": "d73a4a", "description": "Bug fix"},
{"name": "performance", "color": "5319e7", "description": "Performance improvements"}
]
steps:
# We'll need to check out the repository so that we can edit the README.
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0 # Let's get all the branches.
# Renane PSScriptModule.build.ps1 to MODULE_NAME.build.ps1
- name: Rename build file to match module name
run: |
MODULE_NAME=${{ github.event.repository.name }}
git mv PSScriptModule.build.ps1 "$MODULE_NAME.build.ps1"
sed -i "s/PSScriptModule/$MODULE_NAME/g" "$MODULE_NAME.build.ps1"
- name: Generate new module manifest
shell: pwsh
run: |
# Remove existing module manifest
[void] (Remove-Item "src/PSScriptModule.psd1")
# Create new module manifest
$Params = @{
Path = "src/${{ github.event.repository.name }}.psd1"
Guid = [guid]::NewGuid().ToString()
Author = "${{ github.repository_owner }}"
CompanyName = "${{ github.repository_owner }}"
Copyright = "(c) ${{ github.repository_owner }}. All rights reserved."
RootModule = "${{ github.event.repository.name }}.psm1"
Description = "${{ needs.get_repo_state.outputs.description }}"
ProjectUri = "https://github.com/${{ github.repository }}"
LicenseUri = "https://github.com/${{ github.repository }}/blob/main/LICENSE"
ReleaseNotes = "https://github.com/${{ github.repository }}/releases"
}
[void] (New-ModuleManifest @Params)
- name: Update README.md
run: |
OWNER=${{ github.repository_owner }}
MODULE_NAME=${{ github.event.repository.name }}
MODULE_DESCRIPTION="${{ needs.get_repo_state.outputs.description }}"
MODULE_PATH=${{ github.repository }}
rm README.md
mv .github/DOCS_TEMPLATE/README_template.md README.md
sed -i "s|PSScriptModule|$MODULE_NAME|g" README.md
sed -i "s|{MODULE_NAME}|$MODULE_NAME|g" README.md
sed -i "s|{MODULE_DESCRIPTION}|$MODULE_DESCRIPTION|g" README.md
sed -i "s|{MODULE_PATH}|$MODULE_PATH|g" README.md
sed -i "s|{OWNER}|$OWNER|g" README.md
- name: Update SUPPORT.md
run: |
MODULE_NAME=${{ github.event.repository.name }}
sed -i "s/PSScriptModule/$MODULE_NAME/g" .github/SUPPORT.md
- name: Update SECURITY.md
run: |
MODULE_NAME=${{ github.event.repository.name }}
sed -i "s/PSScriptModule/$MODULE_NAME/g" .github/SECURITY.md
- name: Update CONTRIBUTING.md
run: |
MODULE_NAME=${{ github.event.repository.name }}
sed -i "s/PSScriptModule/$MODULE_NAME/g" CONTRIBUTING.md
- name: Update LICENSE
run: |
OWNER=${{ github.repository_owner }}
sed -i "s/Warehouse Finds/$OWNER/g" LICENSE
- name: Update CODEOWNERS
run: |
MODULE_NAME=${{ github.event.repository.name }}
sed -i "s/PSScriptModule/$MODULE_NAME/g" .github/CODEOWNERS
- name: Remove FUNDING.yml
run: |
rm .github/FUNDING.yml
- name: Update config.yml in ISSUE_TEMPLATE
run: |
MODULE_PATH=${{ github.repository }}
sed -i "s|WarehouseFinds/PSScriptModule|$MODULE_PATH|g" .github/ISSUE_TEMPLATE/config.yml
- name: Update devcontainer.json
run: |
MODULE_NAME=${{ github.event.repository.name }}
sed -i "s/PSScriptModule/$MODULE_NAME/g" .devcontainer/devcontainer.json
- name: Update copilot-instructions.md
run: |
MODULE_NAME=${{ github.event.repository.name }}
sed -i "s/PSScriptModule/$MODULE_NAME/g" .github/copilot-instructions.md
- name: Update getting-started.md
run: |
rm docs/getting-started.md
mv .github/DOCS_TEMPLATE/getting-started_template.md docs/getting-started.md
MODULE_NAME=${{ github.event.repository.name }}
MODULE_DESCRIPTION="${{ needs.get_repo_state.outputs.description }}"
sed -i "s/{MODULE_NAME}/$MODULE_NAME/g" docs/getting-started.md
sed -i "s/{MODULE_DESCRIPTION}/$MODULE_DESCRIPTION/g" docs/getting-started.md
- name: Update integration test file
run: |
MODULE_NAME=${{ github.event.repository.name }}
sed -i "s/PSScriptModule/$MODULE_NAME/g" tests/Integration/Module.Integration.Tests.ps1
- name: Remove this workflow file
run: |
rm .github/workflows/bootstrap.yml
- name: Commit changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -am "chore: bootstrap repository for ${{ github.event.repository.name }}"
git push
- name: Create repository labels
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd #v8.0.0
with:
script: |
const labels = JSON.parse(process.env.LABELS_JSON);
for (const label of labels) {
try {
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: label.name,
description: label.description || '',
color: label.color
});
} catch (error) {
// Check if the error is because the label already exists
if (error.status === 422) {
console.log(`Label '${label.name}' already exists. Skipping.`);
} else {
// Log other errors
console.error(`Error creating label '${label.name}': ${error}`);
}
}
}