-
Notifications
You must be signed in to change notification settings - Fork 0
204 lines (196 loc) · 7.37 KB
/
Copy pathpipeline.yml
File metadata and controls
204 lines (196 loc) · 7.37 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
name: Init New Repo with Template
on:
workflow_dispatch:
inputs:
repo_name:
description: "Name of the new GitHub repo"
required: true
brief_description:
description: "Short description of the repository"
required: true
select_template:
description: "Select template"
type: choice
options:
- node
select_category_topic:
description: "Select category topic"
type: choice
options:
- specifications
- reference-apps
- automation-testing
- mock-sandbox
- adaptors
- sdks
- infrastructure
- documentation
- logs
select_subcategory_topic:
description: "Select subcategory topic"
type: choice
options:
- buyer-apps
- seller-apps
- logistics-apps
- ecommerce
- core-framework
- services
- mock-servers
select_domain_topic:
description: "Select domain topic"
type: choice
options:
- retail
- logistics
- agriculture
- healthcare
- financial
- mobility
- education
select_type_topic:
description: "Select type topic"
type: choice
options:
- frontend
- backend
- mobile
- api
- library
- tool
- documentation
jobs:
create-repo:
runs-on: ubuntu-latest
steps:
- name: Set Organization Variable
run: echo "ORG=nmonga26" >> $GITHUB_ENV
- name: Check if organization exists and create repo
run: |
ORG="${ORG}"
REPO="${{ github.event.inputs.repo_name }}"
echo "Checking org..."
ORG_CHECK=$(curl -s -o /dev/null -w "%{http_code}" \
-H "Authorization: token ${{ secrets.PAT_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/orgs/$ORG)
if [ "$ORG_CHECK" -ne 200 ]; then
echo " Org '$ORG' not found or no access."
exit 1
fi
echo " Org exists."
echo "Checking repo..."
REPO_CHECK=$(curl -s -o /dev/null -w "%{http_code}" \
-H "Authorization: token ${{ secrets.PAT_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/$ORG/$REPO)
if [ "$REPO_CHECK" -eq 200 ]; then
echo " Repo '$REPO' already exists."
exit 1
fi
DESC="${REPO}: [${{ github.event.inputs.select_category_topic }}/${{ github.event.inputs.select_subcategory_topic }}] ${{ github.event.inputs.brief_description }} | domain: ${{ github.event.inputs.select_domain_topic }}"
CREATE_RESP=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
-H "Authorization: token ${{ secrets.PAT_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/orgs/$ORG/repos \
-d "{\"name\":\"$REPO\",\"private\":false,\"description\":\"$DESC\"}")
if [ "$CREATE_RESP" -eq 201 ]; then
echo " Repo created: $ORG/$REPO"
else
echo " Failed with status $CREATE_RESP"
exit 1
fi
- name: Add Topics to Repository
run: |
ORG="${ORG}"
REPO="${{ github.event.inputs.repo_name }}"
TOPICS="[\"category-${{ github.event.inputs.select_category_topic }}\",\"subcategory-${{ github.event.inputs.select_subcategory_topic }}\",\"type-${{ github.event.inputs.select_type_topic }}\",\"domain-${{ github.event.inputs.select_domain_topic }}\"]"
curl -X PUT \
-H "Authorization: token ${{ secrets.PAT_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/$ORG/$REPO/topics \
-d "{\"names\": $TOPICS}"
echo " Topics added: $TOPICS"
- name: Install Yeoman
run: npm install -g yo
- name: Clone Template Repo
run: |
ORG="${ORG}"
git clone https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/$ORG/node-template.git template-repo
- name: Prepare Yeoman Generator
run: |
mkdir -p generator-ondc-nodets/generators/app/templates
cp -r template-repo/* generator-ondc-nodets/generators/app/templates/
cp -r template-repo/.[!.]* generator-ondc-nodets/generators/app/templates/ || true
# package.json for generator
cat > generator-ondc-nodets/package.json <<'EOF'
{
"name": "generator-ondc-nodets",
"version": "1.0.0",
"description": "Yeoman generator wrapping ONDC Node TS template",
"main": "generators/app/index.js",
"dependencies": {
"yeoman-generator": "^5.9.0"
}
}
EOF
# index.js for generator
mkdir -p generator-ondc-nodets/generators/app
cat > generator-ondc-nodets/generators/app/index.js <<'EOF'
const Generator = require('yeoman-generator');
module.exports = class extends Generator {
writing() {
this.fs.copyTpl(
this.templatePath('**/*'),
this.destinationPath('.'),
{},
{},
{ globOptions: { dot: true } }
);
}
}
EOF
cd generator-ondc-nodets
npm install
npm link
- name: Generate Project with Yeoman
run: |
mkdir -p ${{ github.event.inputs.repo_name }}
cd ${{ github.event.inputs.repo_name }}
yo ondc-nodets --skip-install --force --no-insight
- name: Update Project Files with Repo Name
run: |
cd ${{ github.event.inputs.repo_name }}
REPO_NAME="${{ github.event.inputs.repo_name }}"
sed -i "s/test55-node-backend/$REPO_NAME/g" package.json || true
sed -i "s/test55-node-backend/$REPO_NAME/g" package-lock.json || true
sed -i "s/test55-node-backend/$REPO_NAME/g" README.md || true
sed -i "s/test55-node-backend/$REPO_NAME/g" docker-compose.yml || true
sed -i "s/test55-node-backend/$REPO_NAME/g" docker-compose.production.yml || true
- name: Push Initial Code
run: |
cd ${{ github.event.inputs.repo_name }}
rm -rf .git
git init
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git branch -M main
git remote add origin https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/${ORG}/${{ github.event.inputs.repo_name }}.git
git add .
git commit -m "[skip ci]"
git push origin main
- name: Setup Husky and Commit Hooks
run: |
cd ${{ github.event.inputs.repo_name }}
npm install husky@9 --save-dev
npx husky init
npx husky add .husky/commit-msg 'npx commitlint --edit $1'
npx husky add .husky/pre-commit 'npx lint-staged'
git add .
git commit -m "[skip ci]" || true
git push origin main
- name: Create Develop Branch
run: |
cd ${{ github.event.inputs.repo_name }}
git checkout -b develop
git push origin develop