Skip to content

Commit 297d252

Browse files
committed
update setup repo
1 parent 788498d commit 297d252

File tree

2 files changed

+125
-31
lines changed

2 files changed

+125
-31
lines changed

.github/workflows/UpdateReadme.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
assignee: ${{ steps.config.outputs.assignee }}
2323
steps:
2424
- name: Checkout repo
25-
uses: actions/checkout@v5
25+
uses: actions/checkout@v6
2626

2727
- name: Compute repository metadata
2828
id: meta

.github/workflows/setup-repo.yml

Lines changed: 124 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ name: Setup Repository
33
on:
44
workflow_dispatch:
55

6+
permissions:
7+
contents: write
8+
pull-requests: write
9+
610
jobs:
711
setup:
812
runs-on: ubuntu-latest
913
steps:
1014
- name: Checkout repository
11-
uses: actions/checkout@v4
15+
uses: actions/checkout@v6
1216

1317
- name: Check if running on the template repository
1418
if: github.repository == 'control-toolbox/CTAppTemplate.jl'
@@ -28,63 +32,153 @@ jobs:
2832
- name: Get author info
2933
id: author
3034
run: |
35+
set -e
3136
USER_INFO=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/users/${{ github.actor }}")
3237
USER_NAME=$(echo "$USER_INFO" | jq -r '.name // ""')
3338
USER_EMAIL=$(echo "$USER_INFO" | jq -r '.email // ""')
39+
40+
# Construct author string with proper escaping and compact format
3441
if [[ -n "$USER_NAME" && -n "$USER_EMAIL" ]]; then
35-
AUTHOR_STRING="[\"$USER_NAME <$USER_EMAIL>\"]"
42+
AUTHOR_STRING=$(jq -nc --arg name "$USER_NAME" --arg email "$USER_EMAIL" '["\($name) <\($email)>"]')
3643
elif [[ -n "$USER_NAME" ]]; then
37-
AUTHOR_STRING="[\"$USER_NAME\"]"
44+
AUTHOR_STRING=$(jq -nc --arg name "$USER_NAME" '["\($name)"]')
3845
else
39-
AUTHOR_STRING="[\"${{ github.actor }}\"]"
46+
AUTHOR_STRING=$(jq -nc --arg actor "${{ github.actor }}" '["\($actor)"]')
4047
fi
48+
49+
# Output as a single line without leading spaces
4150
echo "author_string=$AUTHOR_STRING" >> $GITHUB_OUTPUT
4251
4352
- name: Run setup script
4453
run: |
45-
# 1. Replace repo name and package name
54+
set -e
55+
56+
# Variables
4657
OLD_REPO="control-toolbox/CTAppTemplate.jl"
4758
NEW_REPO="${{ steps.meta.outputs.repo_name }}"
4859
OLD_PACKAGE="CTAppTemplate"
4960
NEW_PACKAGE="${{ steps.meta.outputs.package_name }}"
61+
ACTOR="${{ steps.meta.outputs.actor }}"
62+
AUTHOR_STRING='${{ steps.author.outputs.author_string }}'
63+
64+
echo "=== Repository Setup ==="
65+
echo "Old repo: $OLD_REPO"
66+
echo "New repo: $NEW_REPO"
67+
echo "Old package: $OLD_PACKAGE"
68+
echo "New package: $NEW_PACKAGE"
69+
echo "Actor: $ACTOR"
70+
echo "Author: $AUTHOR_STRING"
5071
51-
echo "Replacing '$OLD_REPO' with '$NEW_REPO'"
52-
find . -type f -not -path "./.git/*" -exec sed -i "s|$OLD_REPO|$NEW_REPO|g" {} +
72+
# 1. Replace repo name in files (excluding .git and setup-repo.yml)
73+
echo "Step 1: Replacing repository name..."
74+
find . -type f \
75+
-not -path "./.git/*" \
76+
-not -path "./.github/workflows/setup-repo.yml" \
77+
-exec grep -l "$OLD_REPO" {} \; 2>/dev/null | while read -r file; do
78+
sed -i "s|$OLD_REPO|$NEW_REPO|g" "$file"
79+
echo " Updated: $file"
80+
done
5381
54-
echo "Replacing '$OLD_PACKAGE' with '$NEW_PACKAGE'"
55-
find . -type f -not -path "./.git/*" -exec sed -i "s|$OLD_PACKAGE|$NEW_PACKAGE|g" {} +
82+
# 2. Replace control-toolbox.org URLs with GitHub Pages URLs for non-control-toolbox repos
83+
echo "Step 2: Updating documentation URLs..."
84+
REPO_OWNER=$(echo "$NEW_REPO" | cut -d'/' -f1)
85+
if [[ "$REPO_OWNER" != "control-toolbox" ]]; then
86+
OLD_DOC_URL="control-toolbox.org/CTAppTemplate.jl"
87+
NEW_DOC_URL="${REPO_OWNER}.github.io/${NEW_PACKAGE}.jl"
88+
find . -type f \
89+
-not -path "./.git/*" \
90+
-not -path "./.github/workflows/setup-repo.yml" \
91+
-exec grep -l "$OLD_DOC_URL" {} \; 2>/dev/null | while read -r file; do
92+
sed -i "s|$OLD_DOC_URL|$NEW_DOC_URL|g" "$file"
93+
echo " Updated: $file"
94+
done
95+
fi
96+
97+
# 3. Replace package name in files
98+
echo "Step 3: Replacing package name..."
99+
find . -type f \
100+
-not -path "./.git/*" \
101+
-not -path "./.github/workflows/setup-repo.yml" \
102+
-exec grep -l "$OLD_PACKAGE" {} \; 2>/dev/null | while read -r file; do
103+
sed -i "s|$OLD_PACKAGE|$NEW_PACKAGE|g" "$file"
104+
echo " Updated: $file"
105+
done
56106
57-
# 2. Rename source file
58-
echo "Renaming src/$OLD_PACKAGE.jl to src/$NEW_PACKAGE.jl"
107+
# 4. Rename source file
108+
echo "Step 4: Renaming source file..."
59109
if [ -f "src/$OLD_PACKAGE.jl" ]; then
60-
mv src/$OLD_PACKAGE.jl src/$NEW_PACKAGE.jl
110+
mv "src/$OLD_PACKAGE.jl" "src/$NEW_PACKAGE.jl"
111+
echo " Renamed: src/$OLD_PACKAGE.jl -> src/$NEW_PACKAGE.jl"
61112
else
62-
echo "Warning: src/$OLD_PACKAGE.jl not found, skipping rename."
113+
echo " Warning: src/$OLD_PACKAGE.jl not found, skipping rename."
63114
fi
64115
65-
# 3. Update metadata in Project.toml
66-
echo "Updating Project.toml"
67-
NEW_UUID=$(uuidgen)
116+
# 5. Update Project.toml
117+
echo "Step 5: Updating Project.toml..."
118+
if [ ! -f "Project.toml" ]; then
119+
echo " Error: Project.toml not found"
120+
exit 1
121+
fi
122+
123+
# Generate new UUID using Python
124+
NEW_UUID=$(python3 -c "import uuid; print(str(uuid.uuid4()))")
125+
echo " New UUID: $NEW_UUID"
126+
127+
# Update UUID
68128
sed -i "s/^uuid = .*/uuid = \"$NEW_UUID\"/" Project.toml
69-
sed -i "s|^authors = .*|authors = ${{ steps.author.outputs.author_string }}|" Project.toml
70129
71-
# 4. Update assignees
72-
echo "Updating default assignees to '${{ steps.meta.outputs.actor }}'"
73-
find .github/ISSUE_TEMPLATE -type f -name "*.md" -exec sed -i 's/assignees: ocots/assignees: ${{ steps.meta.outputs.actor }}/g' {} +
74-
sed -i 's/assignees: ocots/assignees: ${{ steps.meta.outputs.actor }}/g' .github/workflows/AutoAssign.yml
130+
# Update authors using a temporary file to handle special characters safely
131+
TEMP_FILE=$(mktemp)
132+
awk -v authors="$AUTHOR_STRING" '
133+
/^authors = / { print "authors = " authors; next }
134+
{ print }
135+
' Project.toml > "$TEMP_FILE"
136+
mv "$TEMP_FILE" Project.toml
137+
138+
echo " Updated UUID and authors in Project.toml"
139+
140+
# 6. Update assignees
141+
echo "Step 6: Updating assignees..."
142+
if [ -d ".github/ISSUE_TEMPLATE" ]; then
143+
find .github/ISSUE_TEMPLATE -type f -name "*.md" -exec sed -i "s|assignees: ocots|assignees: $ACTOR|g" {} +
144+
echo " Updated assignees in issue templates"
145+
fi
146+
147+
if [ -f ".github/workflows/AutoAssign.yml" ]; then
148+
sed -i "s|assignees: ocots|assignees: $ACTOR|g" .github/workflows/AutoAssign.yml
149+
echo " Updated assignees in AutoAssign.yml"
150+
fi
151+
152+
echo "=== Setup Complete ==="
75153
76154
- name: Create Pull Request
77-
uses: peter-evans/create-pull-request@v7
155+
uses: peter-evans/create-pull-request@v8
78156
with:
157+
token: ${{ secrets.GITHUB_TOKEN }}
79158
commit-message: "feat: automate repository setup"
80159
branch: "chore/auto-setup"
81160
delete-branch: true
82-
title: "Automate repository setup"
161+
title: "🔧 Automate repository setup"
83162
body: |
84-
This PR automates the initial setup of the repository by:
85-
- Replacing template names (`CTAppTemplate`, `control-toolbox/CTAppTemplate.jl`) with the new repository's name.
86-
- Renaming the main source file.
87-
- Generating a new UUID and updating the author in `Project.toml`.
88-
- Setting the default assignee to the user who triggered this workflow.
89-
90-
Please review the changes and merge this PR to finalize the setup.
163+
## Repository Setup Automation
164+
165+
This PR automates the initial setup of the repository from the template.
166+
167+
### Changes made:
168+
- ✅ Replaced template names with new repository name
169+
- `CTAppTemplate` → `${{ steps.meta.outputs.package_name }}`
170+
- `control-toolbox/CTAppTemplate.jl` → `${{ steps.meta.outputs.repo_name }}`
171+
- ✅ Renamed main source file
172+
- `src/CTAppTemplate.jl` → `src/${{ steps.meta.outputs.package_name }}.jl`
173+
- ✅ Generated new UUID for the package
174+
- ✅ Updated author information in `Project.toml`
175+
- ✅ Set default assignee to `${{ steps.meta.outputs.actor }}`
176+
177+
### Next steps:
178+
1. Review the changes carefully
179+
2. Verify that all files have been updated correctly
180+
3. Merge this PR to finalize the setup
181+
4. Delete the `setup-repo.yml` workflow file (optional)
182+
183+
---
184+
*This PR was automatically created by the repository setup workflow.*

0 commit comments

Comments
 (0)