v0.1.5: fix: remove private/ directory from template repo #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Initialize from template | |
| # This workflow runs once when a new repo is created from this template. | |
| # It replaces $PLACEHOLDER variables with values derived from the repo, | |
| # commits the changes, then deletes itself. | |
| on: | |
| push: | |
| branches: [main] | |
| permissions: | |
| contents: write | |
| jobs: | |
| setup: | |
| name: Replace template placeholders | |
| runs-on: ubuntu-latest | |
| # Only run if this is NOT the template repo itself | |
| if: github.repository != 'DazzleTools/git-repokit-template' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Derive project variables | |
| id: vars | |
| run: | | |
| # Extract from repo name: DazzleTools/my-cool-tool -> my-cool-tool | |
| REPO_NAME="${{ github.event.repository.name }}" | |
| REPO_OWNER="${{ github.repository_owner }}" | |
| REPO_FULL="${{ github.repository }}" | |
| # Convert project-name to package_name (hyphens to underscores) | |
| PACKAGE_NAME=$(echo "$REPO_NAME" | tr '-' '_') | |
| # Default CLI command (same as package name) | |
| CLI_CMD=$(echo "$REPO_NAME" | tr '_' '-') | |
| # Get owner info | |
| AUTHOR="${{ github.actor }}" | |
| AUTHOR_EMAIL="${AUTHOR}@users.noreply.github.com" | |
| echo "PROJECT_NAME=$REPO_NAME" >> $GITHUB_OUTPUT | |
| echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_OUTPUT | |
| echo "GITHUB_ORG=$REPO_OWNER" >> $GITHUB_OUTPUT | |
| echo "GITHUB_USER=$AUTHOR" >> $GITHUB_OUTPUT | |
| echo "AUTHOR_EMAIL=$AUTHOR_EMAIL" >> $GITHUB_OUTPUT | |
| echo "CLI_COMMAND=$CLI_CMD" >> $GITHUB_OUTPUT | |
| echo "REPO_URL=https://github.com/$REPO_FULL" >> $GITHUB_OUTPUT | |
| echo "Derived variables:" | |
| echo " PROJECT_NAME=$REPO_NAME" | |
| echo " PACKAGE_NAME=$PACKAGE_NAME" | |
| echo " GITHUB_ORG=$REPO_OWNER" | |
| echo " GITHUB_USER=$AUTHOR" | |
| echo " CLI_COMMAND=$CLI_CMD" | |
| - name: Replace placeholders in all files | |
| env: | |
| PROJECT_NAME: ${{ steps.vars.outputs.PROJECT_NAME }} | |
| PACKAGE_NAME: ${{ steps.vars.outputs.PACKAGE_NAME }} | |
| GITHUB_ORG: ${{ steps.vars.outputs.GITHUB_ORG }} | |
| GITHUB_USER: ${{ steps.vars.outputs.GITHUB_USER }} | |
| AUTHOR_EMAIL: ${{ steps.vars.outputs.AUTHOR_EMAIL }} | |
| CLI_COMMAND: ${{ steps.vars.outputs.CLI_COMMAND }} | |
| DESCRIPTION: "A new project created from git-repokit-template" | |
| run: | | |
| # Find all text files (exclude .git/ and binary files) | |
| find . -type f \ | |
| -not -path './.git/*' \ | |
| -not -path './.github/workflows/*' \ | |
| -not -name '*.png' -not -name '*.jpg' -not -name '*.gif' \ | |
| -not -name '*.ico' -not -name '*.woff*' \ | |
| | while read file; do | |
| # Only process text files | |
| if file "$file" | grep -q text; then | |
| sed -i \ | |
| -e "s|\\\$PROJECT_NAME|${PROJECT_NAME}|g" \ | |
| -e "s|\\\$PACKAGE_NAME|${PACKAGE_NAME}|g" \ | |
| -e "s|\\\$GITHUB_ORG|${GITHUB_ORG}|g" \ | |
| -e "s|\\\$GITHUB_USER|${GITHUB_USER}|g" \ | |
| -e "s|\\\$AUTHOR_EMAIL|${AUTHOR_EMAIL}|g" \ | |
| -e "s|\\\$CLI_COMMAND|${CLI_COMMAND}|g" \ | |
| -e "s|\\\$DESCRIPTION|${DESCRIPTION}|g" \ | |
| "$file" | |
| fi | |
| done | |
| - name: Create package directory | |
| env: | |
| PACKAGE_NAME: ${{ steps.vars.outputs.PACKAGE_NAME }} | |
| run: | | |
| # Create the Python package directory with basic files | |
| mkdir -p "$PACKAGE_NAME" | |
| cat > "$PACKAGE_NAME/__init__.py" << PYEOF | |
| """${PACKAGE_NAME} - A new project.""" | |
| from ._version import __version__, __app_name__ | |
| PYEOF | |
| # Trim leading whitespace from heredoc | |
| sed -i 's/^ //' "$PACKAGE_NAME/__init__.py" | |
| cat > "$PACKAGE_NAME/__main__.py" << PYEOF | |
| """Allow running as: python -m ${PACKAGE_NAME}""" | |
| from .cli import main | |
| main() | |
| PYEOF | |
| sed -i 's/^ //' "$PACKAGE_NAME/__main__.py" | |
| - name: Remove template-only files | |
| run: | | |
| # Remove the setup workflow (this file) -- it's a one-time action | |
| rm -f .github/workflows/setup-from-template.yml | |
| # Remove the archetype variant that wasn't chosen | |
| # (Keep .pypi by default -- user can switch manually) | |
| if [ -f pyproject.toml.pypi ]; then | |
| mv pyproject.toml.pypi pyproject.toml | |
| fi | |
| rm -f pyproject.toml.comfyui | |
| # Remove the template variables reference from README | |
| # (the "Template Variables" section at the bottom) | |
| sed -i '/^---$/,/^```$/d' README.md 2>/dev/null || true | |
| - name: Commit changes | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add -A | |
| git commit -m "feat: initialize project from git-repokit-template | |
| Auto-populated template placeholders with: | |
| PROJECT_NAME=${{ steps.vars.outputs.PROJECT_NAME }} | |
| PACKAGE_NAME=${{ steps.vars.outputs.PACKAGE_NAME }} | |
| GITHUB_ORG=${{ steps.vars.outputs.GITHUB_ORG }} | |
| CLI_COMMAND=${{ steps.vars.outputs.CLI_COMMAND }}" | |
| git push |