-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (122 loc) · 4.8 KB
/
template-use.yml
File metadata and controls
145 lines (122 loc) · 4.8 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
# This workflow runs, if this repo is used as template
name: Template Cleanup
on:
push:
branches:
- main
jobs:
# Inspect the information that is accessible in each context
# https://docs.github.com/en/actions/learn-github-actions/contexts#example-printing-context-information-to-the-log-file
# You can delete this section
jobinfo:
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump job context
env:
JOB_CONTEXT: ${{ toJSON(job) }}
run: echo "$JOB_CONTEXT"
- name: Dump steps context
env:
STEPS_CONTEXT: ${{ toJSON(steps) }}
run: echo "$STEPS_CONTEXT"
- name: Dump runner context
env:
RUNNER_CONTEXT: ${{ toJSON(runner) }}
run: echo "$RUNNER_CONTEXT"
- name: Dump strategy context
env:
STRATEGY_CONTEXT: ${{ toJSON(strategy) }}
run: echo "$STRATEGY_CONTEXT"
- name: Dump matrix context
env:
MATRIX_CONTEXT: ${{ toJSON(matrix) }}
run: echo "$MATRIX_CONTEXT"
cleanup:
runs-on: ubuntu-latest
if: github.event.repository.name != 'python-starter'
name: "Cleanup & Prepare repository"
steps:
- name: Checkout
uses: actions/checkout@v3.1.0
- name: Prepare files
run: |
# Prepare variables
NAME="${GITHUB_REPOSITORY##*/}"
ACTOR="${{ github.repository_owner }}"
SAFE_NAME=$(echo $NAME | sed 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]')
SAFE_ACTOR=$(echo $ACTOR | sed 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]')
# Print variables to console
echo "NAME: $NAME"
echo "ACTOR: $ACTOR"
echo "SAFE_NAME: $SAFE_NAME"
echo "SAFE_ACTOR: $SAFE_ACTOR"
# Replace placeholders in the template files
find .github/template/ -type f -exec sed -i "s/%NAME%/$NAME/g" {} +
find .github/template/ -type f -exec sed -i "s/%SAFE_NAME%/$SAFE_NAME/g" {} +
find .github/template/ -type f -exec sed -i "s/%ACTOR%/$ACTOR/g" {} +
find .github/template/ -type f -exec sed -i "s/%REPOSITORY%/${GITHUB_REPOSITORY/\//\\/}/g" {} +
find .github/template/ -type f -exec sed -i "s/counter/$SAFE_NAME/g" {} +
# Replace variables within example python project
find counter -type f -exec sed -i "s/%NAME%/$NAME/g" {} +
find counter -type f -exec sed -i "s/%SAFE_NAME%/$SAFE_NAME/g" {} +
find counter -type f -exec sed -i "s/counter/$SAFE_NAME/g" {} +
find counter -type f -exec sed -i "s/V3lop5/$ACTOR/g" {} +
# Rename project folder
mv counter $SAFE_NAME
# Move contents
cp -R .github/template/* .
# Update github workflows
sed -i "s/counter/$SAFE_NAME/g" .github/workflows/*
# Update tests
find tests -type f -exec sed -i "s/counter/$SAFE_NAME/g" {} +
find tests -type f -exec sed -i "s/Counter/$SAFE_NAME/g" {} +
# Update scripts
sed -i "s/counter/$SAFE_NAME/g" scripts/*
# Update requirements
sed -i "s/Counter/$NAME/g" requirements*.txt
# Update first issue body
sed -i "s/%REPOSITORY%/${GITHUB_REPOSITORY/\//\\/}/g" .github/FIRST_ISSUE.md
- name: Create Issue
uses: peter-evans/create-issue-from-file@v4
with:
title: "Complete repository setup"
content-filepath: ./.github/FIRST_ISSUE.md
- name: Remove template files
run: |
rm -rf \
.github/template \
.github/workflows/template-use.yml \
.github/FIRST_ISSUE.md \
LICENSE
- name: Commit files
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .
git commit -m "Completed project setup"
- name: Push changes
uses: ad-m/github-push-action@master
with:
branch: main
github_token: ${{ github.token }}
branch_gh_pages:
name: "Create gh-pages branch"
runs-on: ubuntu-latest
if: github.event.repository.name != 'python-starter'
steps:
- name: Checkout
uses: actions/checkout@v3.1.0
- name: Prepare files
run: |
git checkout --orphan gh-pages
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git rm -rf .
git commit --allow-empty -m "Create gh-pages branch"
git push origin gh-pages