-
Notifications
You must be signed in to change notification settings - Fork 43
133 lines (118 loc) · 6 KB
/
create_component.yaml
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: Create New Component from Feature Request
on:
issues:
types:
- opened
jobs:
create-component:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Parse Issue Body
env:
ISSUE_BODY: ${{ github.event.issue.body }}
run: |
# Parse the issue body using awk for each field
package_name=$(echo "$ISSUE_BODY" | awk '/^### Package Name$/ {getline; getline; print $0}' | xargs)
resource_kind=$(echo "$ISSUE_BODY" | awk '/^### Resource Kind$/ {getline; getline; print $0}' | xargs)
package_scope=$(echo "$ISSUE_BODY" | awk '/^### Package Scope$/ {getline; getline; print $0}' | xargs)
generate_content=$(echo "$ISSUE_BODY" | awk '/^### Generate Content$/ {getline; getline; print $0}' | xargs)
feature_description=$(echo "$ISSUE_BODY" | awk '/^### Feature Description$/ {getline; getline; print $0}' | xargs)
motivation=$(echo "$ISSUE_BODY" | awk '/^### Motivation$/ {getline; getline; print $0}' | xargs)
potential_solution=$(echo "$ISSUE_BODY" | awk '/^### Potential Solution$/ {getline; getline; print $0}' | xargs)
# Update the package_scope based on its value
if [[ "$package_scope" == "core" || "$package_scope" == "experimental" || "$package_scope" == "community" ]]; then
package_scope="${package_scope}/swarmauri_${package_scope}"
else
package_scope="${package_scope}/${package_scope}"
fi
# New Branch Name
branch_name="$package_scope"
# Clean the package_name and convert to concatenated PascalCase
package_name=$(echo "$package_name" | sed 's/^ *//;s/ *$//' | awk '{for (i=1; i<=NF; i++) printf toupper(substr($i,1,1)) substr($i,2)} END {print ""}')
# Export parsed values as environment variables
echo "PACKAGE_NAME=$package_name" >> $GITHUB_ENV
echo "RESOURCE_KIND=$resource_kind" >> $GITHUB_ENV
echo "PACKAGE_SCOPE=$package_scope" >> $GITHUB_ENV
echo "BRANCH_NAME=$branch_name" >> $GITHUB_ENV
echo "GENERATE_CONTENT=$generate_content" >> $GITHUB_ENV
echo "FEATURE_DESCRIPTION=$feature_description" >> $GITHUB_ENV
echo "MOTIVATION=$motivation" >> $GITHUB_ENV
echo "POTENTIAL_SOLUTION=$potential_solution" >> $GITHUB_ENV
- name: Create Component Folder
env:
PACKAGE_NAME: ${{ env.PACKAGE_NAME }}
AUTHOR_NAME: ${{ github.event.issue.user.login }}
AUTHOR_EMAIL: ${{ github.event.issue.user.login }}@example.com
RESOURCE_KIND: ${{ env.RESOURCE_KIND }}
PACKAGE_SCOPE: ${{ env.PACKAGE_SCOPE }}
GENERATE_CONTENT: ${{ env.GENERATE_CONTENT }}
FEATURE_DESCRIPTION: ${{ env.FEATURE_DESCRIPTION }}
MOTIVATION: ${{ env.MOTIVATION }}
POTENTIAL_SOLUTION: ${{ env.POTENTIAL_SOLUTION }}
run: |
python scripts/create_component.py \
--template .config/component_generator/templates/component \
--output pkgs \
--placeholders \
package_name="${{ env.PACKAGE_NAME }}" \
resource_kind="${{ env.RESOURCE_KIND }}" \
package_scope="${{ env.PACKAGE_SCOPE }}" \
generate_content="${{ env.GENERATE_CONTENT }}" \
feature_description="${{ env.FEATURE_DESCRIPTION }}" \
motivation="${{ env.MOTIVATION }}" \
potential_solution="${{ env.POTENTIAL_SOLUTION }}" \
author_name="${{ env.AUTHOR_NAME }}" \
author_email="${{ env.AUTHOR_EMAIL }}" \
year=$(date +%Y)
- name: Create New Git Branch
env:
BRANCH_NAME: ${{ env.BRANCH_NAME }}
PACKAGE_NAME: ${{ env.PACKAGE_NAME }}
run: |
# Create and switch to the new branch
git checkout -b ${BRANCH_NAME}/${PACKAGE_NAME}
echo "Created and switched to branch ${BRANCH_NAME}/${PACKAGE_NAME}"
- name: Configure Git User
run: |
git config user.name "Create Component Bot"
git config user.email "[email protected]"
- name: Commit Changes
env:
BRANCH_NAME: ${{ env.BRANCH_NAME }}
PACKAGE_NAME: ${{ env.PACKAGE_NAME }}
run: |
# Stage all changes and commit
git add .
git commit -m "feat: add new component - ${PACKAGE_NAME}"
echo "Committed changes to branch ${BRANCH_NAME}/${PACKAGE_NAME}"
- name: Push Branch to GitHub
env:
BRANCH_NAME: ${{ env.BRANCH_NAME }}
PACKAGE_NAME: ${{ env.PACKAGE_NAME }}
run: |
# Push the new branch to GitHub
git push origin ${BRANCH_NAME}/${PACKAGE_NAME}
echo "Pushed branch ${BRANCH_NAME}/${PACKAGE_NAME} to GitHub"
- name: Create Pull Request
env:
BRANCH_NAME: ${{ env.BRANCH_NAME }}
PACKAGE_NAME: ${{ env.PACKAGE_NAME }}
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
run: |
# Create a pull request from the new branch to the master branch
PR_TITLE="feat: add new component - ${PACKAGE_NAME}"
PR_BODY="This pull request introduces a new component created from the feature request.\n\n### Feature Description\n${{ env.FEATURE_DESCRIPTION }}\n\n### Motivation\n${{ env.MOTIVATION }}\n\n### Potential Solution\n${{ env.POTENTIAL_SOLUTION }}\n\nCloses #${ISSUE_NUMBER}"
curl -X POST -H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
-d '{"title": "'"${PR_TITLE}"'", "head": "${BRANCH_NAME}/'"${PACKAGE_NAME}"'", "base": "master", "body": "'"${PR_BODY}"'"}' \
https://api.github.com/repos/${{ github.repository }}/pulls