Skip to content

Commit 9bbb839

Browse files
committed
upgrade configure_project script
1 parent a0be1ed commit 9bbb839

2 files changed

Lines changed: 64 additions & 22 deletions

File tree

.github/workflows/configure-project

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Configure Project
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
new_project_name:
7+
description: 'The new name for the project.'
8+
required: true
9+
default: 'New Project Name'
10+
project_description:
11+
description: 'A short description of the project.'
12+
required: true
13+
default: 'A new awesome project.'
14+
project_homepage_url:
15+
description: 'The URL for the project's homepage.'
16+
required: true
17+
default: 'https://github.com/username/repo'
18+
cpack_package_contact:
19+
description: 'The contact email for the project.'
20+
required: true
21+
default: 'user@example.com'
22+
23+
jobs:
24+
configure_project:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
30+
- name: Configure Git
31+
run: |
32+
git config user.name "github-actions"
33+
git config user.email "github-actions@github.com"
34+
35+
- name: Set project name variables
36+
id: set-variables
37+
run: |
38+
# Convert the project name to snake_case for use in filenames and other contexts.
39+
PROJECT_NAME_LOWER=$(echo "${{ github.event.inputs.new_project_name }}" | tr '[:upper:]' '[:lower:]' | tr ' ' '_')
40+
echo "project_name_lower=$PROJECT_NAME_LOWER" >> $GITHUB_OUTPUT
41+
42+
- name: Replace project name placeholders
43+
run: |
44+
# This command finds all files and uses 'sed' to replace all the placeholders.
45+
# The sed delimiter is changed from '/' to '|' to safely handle path names.
46+
find . -type f -not -path './.git/*' -exec sed -i \
47+
-e "s|{{PROJECT_NAME}}|${{ github.event.inputs.new_project_name }}|g" \
48+
-e "s|{{PROJECT_NAME_LOWER}}|${{ steps.set-variables.outputs.project_name_lower }}|g" \
49+
-e "s|{{PROJECT_DESCRIPTION}}|${{ github.event.inputs.project_description }}|g" \
50+
-e "s|{{PROJECT_HOMEPAGE_URL}}|${{ github.event.inputs.project_homepage_url }}|g" \
51+
-e "s|{{CPACK_PACKAGE_CONTACT}}|${{ github.event.inputs.cpack_package_contact }}|g" \
52+
-e "s|{{USERNAME}}|${{ github.actor }}|g" \
53+
{} +
54+
55+
- name: Create a pull request with the new name
56+
uses: peter-evans/create-pull-request@v6
57+
with:
58+
title: 'Update project name to "${{ github.event.inputs.new_project_name }}"'
59+
commit-message: 'feat: Update project name to ${{ github.event.inputs.new_project_name }}'
60+
body: |
61+
This pull request automatically updates all instances of the project name
62+
placeholder (`{{PROJECT_NAME}}`) and other related placeholders with the new information you provided.
63+
branch: update-project-name-${{ github.run_number }}
64+
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)