Skip to content

Initial commit

Initial commit #1

---
# This workflow is triggered on push events and renames the project from template
# This should be the first workflow to run after the project is created from the 'Use this template' feature
name: Rename Project from Template
on: # yamllint disable-line rule:truthy
push:
branches: [main]
permissions:
contents: write
actions: write
concurrency:
group: "${{ github.head_ref || github.ref }}-${{ github.workflow }}"
cancel-in-progress: true
jobs:
rename-project:
name: Rename Project
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
# by default, it uses a depth of 1
# this fetches all history so that we can read each commit
fetch-depth: 0
ref: ${{ github.head_ref }}
- name: Check Repository is not a Template
uses: actions/github-script@v7
with:
script: |
const repo = await github.rest.repos.get({
owner: context.repo.owner,
repo: context.repo.repo,
});
core.exportVariable("is_template", repo.data.is_template);
- name: Set Environment Variables and Check Visibility
if: env.is_template == 'false'
uses: actions/github-script@v7
with:
script: |
const repoName = context.repo.repo;
const repoOwner = context.repo.owner;
core.exportVariable('REPOSITORY_NAME', repoName);
core.exportVariable('REPOSITORY_OWNER', repoOwner);
const repo = await github.rest.repos.get({
owner: context.repo.owner,
repo: context.repo.repo,
});
const description = repo.data.description;
const visibility = repo.data.visibility;
core.exportVariable('REPOSITORY_DESCRIPTION', description);
core.exportVariable('REPOSITORY_VISIBILITY', visibility);
- name: Rename Repository Check
if: env.is_template == 'false'
run: |
echo "needs_renaming=$(ls .github/workflows/rename-project.yml &> /dev/null && echo true || echo false)" >> "$GITHUB_ENV"
- name: Install Poetry
if: env.is_template == 'false' && env.needs_renaming == 'true'
run: pipx install poetry==1.8.3
- name: Set up Python
if: env.is_template == 'false' && env.needs_renaming == 'true'
uses: actions/setup-python@v5
with:
python-version-file: .python-version
cache: poetry
- name: Install dependencies
if: env.is_template == 'false' && env.needs_renaming == 'true'
run: |
make install
- name: Rename the Project
if: env.is_template == 'false' && env.needs_renaming == 'true'
run: |
# Create a temporary directory
temp_dir=$(mktemp -d)
# Move .git directory to the temporary directory
mv .git "$temp_dir/"
# Run copier
poetry run copier copy "$(pwd)" "$temp_dir" --trust --force --quiet \
--data "repository_name=${{ env.REPOSITORY_NAME }}" \
--data "repository_description=${{ env.REPOSITORY_DESCRIPTION || env.REPOSITORY_NAME }}" \
--data "repository_owner=${{ env.REPOSITORY_OWNER }}" \
--data "repository_visibility=${{ env.REPOSITORY_VISIBILITY }}" \
--data "is_gh_actions=true"
# Remove existing files and directories from the current directory including hidden files
shopt -s dotglob
rm -rf ./*
# Move contents from temporary directory to the current directory
mv -f "$temp_dir"/* .
# Clean up temporary directory
rm -rf "$temp_dir"
- name: Cleanup
if: env.is_template == 'false' && env.needs_renaming == 'true'
run: |
rm .github/workflows/rename-project.yml
- uses: stefanzweifel/git-auto-commit-action@v5
if: env.is_template == 'false' && env.needs_renaming == 'true'
with:
commit_message: ✅ Ready to clone
push_options: --force