-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (81 loc) · 3.92 KB
/
Copy pathconfigure_project.yml
File metadata and controls
89 lines (81 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: Configure Project
on:
workflow_dispatch:
inputs:
new_project_name:
description: 'The name for the project.'
required: true
default: 'My Awesome Project'
project_description:
description: 'A short description of the project.'
required: true
default: 'A new awesome project.'
cpack_package_contact:
description: 'The contact email for the project.'
required: true
default: 'user@example.com'
project_homepage_url:
description: "The URL for the project's homepage. Leave empty to use the repository URL."
required: false
default: 'Leave empty to use repository URL'
jobs:
configure_project:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Configure Git
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
- name: Set project variables
id: set-variables
run: |
# Convert the project name to snake_case for use in filenames and other contexts.
PROJECT_NAME_LOWER=$(echo "${{ github.event.inputs.new_project_name }}" | tr '[:upper:]' '[:lower:]' | tr ' ' '_')
echo "project_name_lower=$PROJECT_NAME_LOWER" >> $GITHUB_OUTPUT
# Convert the project name to CamelCase for use in class names.
PROJECT_NAME_CAMEL=$(echo "${{ github.event.inputs.new_project_name }}" | sed -e 's/\b\(.\)/\u\1/g' -e 's/ //g')
echo "project_name_camel=$PROJECT_NAME_CAMEL" >> $GITHUB_OUTPUT
- name: Set homepage URL
id: set-url
run: |
if [ "${{ github.event.inputs.project_homepage_url }}" = "Leave empty to use repository URL" ] || [ -z "${{ github.event.inputs.project_homepage_url }}" ]; then
echo "homepage_url=${{ github.server_url }}/${{ github.repository }}" >> $GITHUB_OUTPUT
else
echo "homepage_url=${{ github.event.inputs.project_homepage_url }}" >> $GITHUB_OUTPUT
fi
- name: Replace project template placeholders
run: |
# This command finds all files and uses 'sed' to replace all the placeholders.
# The sed delimiter is changed from '/' to '|' to safely handle path names.
find . -type f -not -path './.git/*' -not -path './.github/workflows/*' -exec sed -i \
-e "s|{{PROJECT_NAME}}|${{ github.event.inputs.new_project_name }}|g" \
-e "s|{{PROJECT_NAME_LOWER}}|${{ steps.set-variables.outputs.project_name_lower }}|g" \
-e "s|{{PROJECT_NAME_CAMEL}}|${{ steps.set-variables.outputs.project_name_camel }}|g" \
-e "s|{{PROJECT_DESCRIPTION}}|${{ github.event.inputs.project_description }}|g" \
-e "s|{{PROJECT_REPOSITORY_URL}}|${{ github.server_url }}/${{ github.repository }}|g" \
-e "s|{{PROJECT_HOMEPAGE_URL}}|${{ steps.set-url.outputs.homepage_url }}|g" \
-e "s|{{CPACK_PACKAGE_CONTACT}}|${{ github.event.inputs.cpack_package_contact }}|g" \
{} +
- name: Remove template-specific files and instructions
run: |
rm -f UNLICENSE
LINE=$(grep -n -m 1 "^---" README.md | cut -d: -f1)
if [ -n "$LINE" ]; then
if tail -n +$LINE README.md | grep -q "## ⚙️ How to Use This Template"; then
sed -i "$LINE,\$d" README.md
fi
fi
- name: Create a pull request with configured project
uses: peter-evans/create-pull-request@v6
with:
title: 'Configure project from template'
commit-message: 'Configure project from template'
body: |
This pull request configures the project from the template with the information you provided.
branch: configure-project-${{ github.run_number }}
token: ${{ secrets.GITHUB_TOKEN }}