Skip to content

Commit

Permalink
Fix specialization workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeLyon committed Mar 7, 2024
1 parent c2cb1a3 commit a6712d5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/specialize-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ jobs:
- name: Specialize Template Parameters
run: |
# Replacement Variables
NEW_PROJECT_NAME="${GITHUB_REPOSITORY_NAME}"
NEW_PROJECT_BUNDLE_ID_PREFIX="com.github.$(echo "$GITHUB_REPOSITORY_OWNER" | sed 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]')"
NEW_PROJECT_NAME="${{ github.event.repository.name }}"
echo "New project name: $NEW_PROJECT_NAME"
NEW_PROJECT_BUNDLE_ID_PREFIX="com.github.$(echo "${{ github.event.repository.owner.name }}" | sed 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]')"
echo "New project bundle ID prefix: $NEW_PROJECT_BUNDLE_ID_PREFIX"
# Run specialization script (requires variables defined above)
./specialize-template.sh
./specialize-template.sh "$NEW_PROJECT_NAME" "$NEW_PROJECT_BUNDLE_ID_PREFIX"
rm -rf \
.github/workflows/specialize-template.yml \
Expand Down
20 changes: 15 additions & 5 deletions specialize-template.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
#!/bin/bash

set -euo pipefail
set -eo pipefail

NEW_PROJECT_NAME=$1
if [[ -z "${NEW_PROJECT_NAME}" ]]; then
echo "NEW_PROJECT_NAME is not set"
exit 1
fi

NEW_PROJECT_BUNDLE_ID_PREFIX=$2
if [[ -z "${NEW_PROJECT_BUNDLE_ID_PREFIX}" ]]; then
echo "NEW_PROJECT_BUNDLE_ID_PREFIX is not set"
exit 1
fi

# `find` returns folders before their children, so this will always rename the parent folder first.
# We re-run `find` every iteration so that the path is correct after renaming a parent folder.
echo "Moving files..."
while FILE=$(find . -name '*SwiftProjectTemplate*' | head -n1) && [ -n "$FILE" ]; do
NEW_FILE=$(echo $FILE | sed -e "s/SwiftProjectTemplate/$NEW_PROJECT_NAME/")
echo "mv \"$FILE\" \"$NEW_FILE\""
mv "$FILE" "$NEW_FILE"
done
git add -A
echo "Files moved."

# Replace references to `SwiftProjectTemplate`
echo "Replacing references to SwiftProjectTemplate..."
git ls-files --cached --modified --others --exclude-standard -z |
xargs -0 sed -i '' -e "s/SwiftProjectTemplate/$NEW_PROJECT_NAME/g"
xargs -0 -I {} sed -i.template-specialization-backup "s/SwiftProjectTemplate/$NEW_PROJECT_NAME/g" {}

# Replace bundle identifier
echo "Replacing bundle identifier..."
git ls-files --cached --modified --others --exclude-standard -z |
xargs -0 sed -i '' -e "s/com.github.georgelyon/$NEW_PROJECT_BUNDLE_ID_PREFIX/g"
xargs -0 -I {} sed -i.template-specialization-backup "s/com.github.georgelyon/$NEW_PROJECT_BUNDLE_ID_PREFIX/g" {}

echo "Removing backup files..."
find . -name '*.template-specialization-backup' -exec rm {} \;
git add -A

echo "Done."

0 comments on commit a6712d5

Please sign in to comment.