Skip to content

Commit ca2ebda

Browse files
committed
ci: generate gh-release based feature with template
1 parent da84b31 commit ca2ebda

1 file changed

Lines changed: 134 additions & 0 deletions

File tree

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
name: Generate Feature from gh-release Template
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
ID:
7+
description: 'Feature identifier (e.g., akamai-cli)'
8+
required: true
9+
type: string
10+
Description:
11+
description: 'Feature description'
12+
required: true
13+
type: string
14+
Repository:
15+
description: 'GitHub repository in format "owner/repo" (e.g., akamai/cli)'
16+
required: true
17+
type: string
18+
BinaryNames:
19+
description: 'Binary names (comma-separated if multiple)'
20+
required: true
21+
type: string
22+
BinaryVersionCommands:
23+
description: 'Version check commands (comma-separated if multiple)'
24+
required: false
25+
type: string
26+
default: '--version'
27+
BinaryNonLatestVersions:
28+
description: 'Non-latest versions for testing (comma-separated if multiple)'
29+
required: true
30+
type: string
31+
32+
jobs:
33+
generate:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: Checkout repository
37+
uses: actions/checkout@v6
38+
with:
39+
token: ${{ secrets.ARCHIVE_TOKEN }}
40+
41+
- name: Check if feature already exists
42+
run: |
43+
if [ -d "src/${{ inputs.ID }}" ] || [ -d "test/${{ inputs.ID }}" ]; then
44+
echo "❌ Feature '${{ inputs.ID }}' already exists!"
45+
echo "Please use a different feature ID or remove the existing feature first."
46+
exit 1
47+
fi
48+
echo "✅ Feature ID is available"
49+
50+
- name: Validate GitHub repository exists
51+
env:
52+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
run: |
54+
if gh api repos/${{ inputs.Repository }} > /dev/null 2>&1; then
55+
echo "✅ Repository '${{ inputs.Repository }}' exists and is accessible"
56+
else
57+
echo "⚠️ Warning: Could not verify repository '${{ inputs.Repository }}'"
58+
echo "The repository might be private, not exist, or you don't have access to it."
59+
echo "Continuing with feature generation..."
60+
fi
61+
62+
- name: Download boilerplate
63+
run: |
64+
wget -q https://github.com/gruntwork-io/boilerplate/releases/download/v0.10.1/boilerplate_linux_amd64
65+
chmod +x boilerplate_linux_amd64
66+
67+
- name: Create vars.yml
68+
run: |
69+
cat > vars.yml << 'EOF'
70+
ID: ${{ inputs.ID }}
71+
Description: ${{ inputs.Description }}
72+
Repository: ${{ inputs.Repository }}
73+
BinaryNames: ${{ inputs.BinaryNames }}
74+
BinaryVersionCommands: ${{ inputs.BinaryVersionCommands }}
75+
BinaryNonLatestVersions: ${{ inputs.BinaryNonLatestVersions }}
76+
EOF
77+
echo "📝 Created vars.yml:"
78+
cat vars.yml
79+
80+
- name: Create branch for new feature
81+
run: |
82+
git config user.name "github-actions[bot]"
83+
git config user.email "github-actions[bot]@users.noreply.github.com"
84+
git checkout -b feature/${{ inputs.ID }}-init
85+
86+
- name: Generate feature files
87+
run: |
88+
echo "🔧 Generating feature files from templates/gh-release..."
89+
./boilerplate_linux_amd64 \
90+
--template-url templates/gh-release/ \
91+
--output-folder src/${{ inputs.ID }} \
92+
--var-file vars.yml \
93+
--non-interactive
94+
95+
- name: Generate test files
96+
run: |
97+
echo "🧪 Generating test files from templates/test..."
98+
./boilerplate_linux_amd64 \
99+
--template-url templates/test/ \
100+
--output-folder test/${{ inputs.ID }} \
101+
--var-file vars.yml \
102+
--non-interactive
103+
104+
- name: Commit changes
105+
run: |
106+
git add -A
107+
git commit -m "feat(${{ inputs.ID }}): init
108+
109+
Generated using boilerplate templates."
110+
111+
- name: Push changes
112+
run: git push origin feature/${{ inputs.ID }}-init
113+
114+
- name: Create Pull Request
115+
env:
116+
GH_TOKEN: ${{ secrets.ARCHIVE_TOKEN }}
117+
run: |
118+
gh pr create \
119+
--title "feat(${{ inputs.ID }}): init" \
120+
--body "## New Feature: \`${{ inputs.ID }}\`
121+
122+
**Description:** ${{ inputs.Description }}
123+
124+
**Repository:** [${{ inputs.Repository }}](https://github.com/${{ inputs.Repository }})
125+
126+
**Binaries:** \`${{ inputs.BinaryNames }}\`
127+
128+
**Version Commands:** \`${{ inputs.BinaryVersionCommands }}\`
129+
130+
**Test Versions:** \`${{ inputs.BinaryNonLatestVersions }}\`
131+
132+
---
133+
134+
This PR was automatically generated using the boilerplate templates.

0 commit comments

Comments
 (0)