Repository navigation
42 lines (38 loc) · 1.6 KB
/
Copy pathinit.yml
File metadata and controls
42 lines (38 loc) · 1.6 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
name: Initialize Template Repo
on:
- push
permissions:
contents: write
jobs:
cleanup:
name: "Initialize Repo"
runs-on: ubuntu-24.04
if: github.event.repository.name != 'LegacyMinecraftModTemplate'
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Initialize repository
shell: bash
run: |
set -euo pipefail
if [ ! -f init.sh ]; then
echo "Repository is already initialized."
exit 0
fi
repository_owner="${GITHUB_REPOSITORY%%/*}"
repository_name="${GITHUB_REPOSITORY#*/}"
owner="${repository_owner,,}"
package_owner=$(printf '%s' "$owner" | tr -cd 'a-z0-9_')
modid=$(printf '%s' "${repository_name,,}" | tr -cd 'a-z0-9_')
project_name=$(printf '%s' "$repository_name" | tr -cd 'A-Za-z0-9_')
if [[ "$package_owner" =~ ^[0-9] ]]; then package_owner="user${package_owner}"; fi
if [[ "$modid" =~ ^[0-9] ]]; then modid="mod${modid}"; fi
if [[ "$project_name" =~ ^[0-9] ]]; then project_name="Mod${project_name}"; fi
package_name="com.github.${package_owner}.${modid}"
git config --local user.email "action@github.com"
git config --local user.name "GitHub Actions"
./init.sh "$package_name" "$project_name" "$modid" "$repository_owner"
git add --all
git commit -m "Initialize template repository" \
-m "Set package name to ${package_name}, project name to ${project_name}, and mod id to ${modid}."
git push origin "HEAD:${GITHUB_REF_NAME}"