-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (61 loc) · 2.36 KB
/
cleanup.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
name: Cleanup Template
on:
push:
branches:
- main
jobs:
# Run a cleaning process only if the workflow is triggered by the non-"starter-ts" repository.
cleanup-template:
name: Cleanup Template
runs-on: ubuntu-latest
if: github.repository != 'yjl9903/starter-ts'
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Get GitHub username
uses: actions/github-script@v7
id: gh
with:
result-encoding: string
script: |
const { GITHUB_ACTOR } = process.env
const user = await github.rest.users.getByUsername({
username: GITHUB_ACTOR
})
return user.data.name
- name: Update repo info
run: |
YEAR="$(date +'%Y')"
REPO="${GITHUB_REPOSITORY##*/}"
ACTOR=$(echo $GITHUB_ACTOR | tr '[:upper:]' '[:lower:]')
USERNAME="${{ steps.gh.outputs.result }}"
SAFE_REPO=$(echo $REPO | sed 's/[^a-zA-Z0-9\-_.]//g' | tr '[:upper:]' '[:lower:]')
SAFE_ACTOR=$(echo $ACTOR | sed 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]')
find . -name "package.json" -not -path "./node_modules/*" -exec sed -i "s/\[repo\]/$REPO/g" {} +
find . -name "package.json" -not -path "./node_modules/*" -exec sed -i "s/\[actor\]/$ACTOR/g" {} +
find . -name "package.json" -not -path "./node_modules/*" -exec sed -i "s/\[username\]/$USERNAME/g" {} +
sed -i "s/\[year\]/$YEAR/g" ./.github/template/*
sed -i "s/\[repo\]/$REPO/g" ./.github/template/*
sed -i "s/\[actor\]/$ACTOR/g" ./.github/template/*
sed -i "s/\[username\]/$USERNAME/g" ./.github/template/*
cp .github/template/LICENSE LICENSE
cp .github/template/README.md README.md
rm .github/workflows/cleanup.yml
rm -rf .github/template
- name: Setup pnpm
uses: pnpm/[email protected]
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: pnpm
- name: Install
run: pnpm install
- name: Commit and push
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add .
git commit -m "chore: cleanup template"
git push