-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
21 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,47 @@ | ||
name: Create Guide from ChatGPT | ||
name: Generate Guide and Create Pull Request | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
title: | ||
description: "The title of the guide" | ||
description: 'Title of the Guide' | ||
required: true | ||
type: string | ||
description: | ||
description: "The description for the guide" | ||
description: 'Description of the Guide' | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
generate_and_create_pr: | ||
generate_guide: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js environment | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '16' | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install dependencies | ||
run: npm install axios | ||
|
||
- name: Create generateGuide.js script | ||
run: | | ||
cat << 'EOF' > generateGuide.js | ||
const axios = require('axios'); | ||
const fs = require('fs'); | ||
const title = process.env.TITLE; | ||
const description = process.env.DESCRIPTION; | ||
const prompt = `Create a guide for Port (docs.getport.io) titled "${title}" with the following description: ${description}. Format the guide in markdown.`; | ||
(async () => { | ||
try { | ||
const response = await axios.post('https://api.openai.com/v1/chat/completions', { | ||
model: 'gpt-3.5-turbo', | ||
messages: [{ role: 'user', content: prompt }] | ||
}, { | ||
headers: { | ||
'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`, | ||
'Content-Type': 'application/json' | ||
} | ||
}); | ||
npm install axios | ||
const guideMarkdown = response.data.choices[0].message.content; | ||
fs.writeFileSync('guide.md', guideMarkdown); | ||
} catch (error) { | ||
console.error("Error generating guide:", error); | ||
process.exit(1); | ||
} | ||
})(); | ||
EOF | ||
- name: Run generateGuide.js script | ||
- name: Generate Guide Content | ||
env: | ||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | ||
TITLE: ${{ github.event.inputs.title }} | ||
DESCRIPTION: ${{ github.event.inputs.description }} | ||
run: node generateGuide.js | ||
|
||
- name: Create new branch | ||
GOOGLE_GEMINI_API_KEY: ${{ secrets.GOOGLE_GEMINI_API_KEY }} | ||
run: | | ||
BRANCH_NAME="guide/${{ github.event.inputs.title }}-$(date +%Y%m%d%H%M%S)" | ||
git checkout -b $BRANCH_NAME | ||
echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV | ||
node generateGuide.js "${{ github.event.inputs.title }}" "${{ github.event.inputs.description }}" | ||
- name: Add guide file and commit | ||
- name: Commit and Push Guide | ||
run: | | ||
git config --global user.name "github-actions[bot]" | ||
git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
git checkout -b "add-guide-${{ github.event.inputs.title }}" | ||
git add guide.md | ||
git commit -m "Add guide: ${{ github.event.inputs.title }}" | ||
- name: Push branch to origin | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
git push -u origin ${{ env.branch_name }} | ||
- name: Create pull request | ||
uses: peter-evans/create-pull-request@v4 | ||
git push origin "add-guide-${{ github.event.inputs.title }}" | ||
- name: Create Pull Request | ||
uses: actions/create-pull-request@v1 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
branch: ${{ env.branch_name }} | ||
branch: "add-guide-${{ github.event.inputs.title }}" | ||
title: "Add guide: ${{ github.event.inputs.title }}" | ||
body: "This pull request adds a new guide generated by ChatGPT." | ||
base: main | ||
body: "This pull request adds a new guide for ${{ github.event.inputs.title }}." |