Skip to content

Commit

Permalink
Created github action to collect the data for Whisper.net Helper (#261)
Browse files Browse the repository at this point in the history
* Added more data to collection.

* Fixed star

* Oops

* Tried to fix the repo file path

* a

* python<pwsh

* aa

* Almost there
  • Loading branch information
sandrohanea authored Nov 10, 2024
1 parent 3e10144 commit 76d9239
Showing 1 changed file with 81 additions and 48 deletions.
129 changes: 81 additions & 48 deletions .github/workflows/collect-gpt-data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,100 @@ name: Collect data for ChatGPT assistant

on:
workflow_dispatch:

permissions:
issues: read
contents: read

jobs:
collect-issues:
collect-data:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests
uses: actions/checkout@v4

- name: Collect issues
- name: Collect GitHub issue and release data
shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python <<EOF
import requests
import os
$repo = $env:GITHUB_REPOSITORY
$token = $env:GITHUB_TOKEN
$headers = @{ "Authorization" = "token $token" }
$repoRoot = $env:GITHUB_WORKSPACE
# Collect issues
$issues = @()
$page = 1
do {
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/issues?state=all&page=$page&per_page=100" -Headers $headers
if ($response.Count -eq 0) { break }
$issues += $response
$page++
} while ($true)
Out-File -FilePath "issues.md" -Encoding utf8 -InputObject ""
foreach ($issue in $issues) {
Add-Content -Path "issues.md" -Value "## #$($issue.number) - $($issue.title)`n$($issue.body)`n"
$commentsUrl = $issue.comments_url
$comments = Invoke-RestMethod -Uri $commentsUrl -Headers $headers
if ($comments.Count -gt 0) {
Add-Content -Path "issues.md" -Value "### Comments:`n"
foreach ($comment in $comments) {
Add-Content -Path "issues.md" -Value "- **$($comment.user.login)**: $($comment.body)`n"
}
Add-Content -Path "issues.md" -Value "`n"
}
}
# Collect releases
$releases = @()
$page = 1
do {
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/releases?page=$page&per_page=100" -Headers $headers
if ($response.Count -eq 0) { break }
$releases += $response
$page++
} while ($true)
Out-File -FilePath "releases.md" -Encoding utf8 -InputObject ""
foreach ($release in $releases) {
Add-Content -Path "releases.md" -Value "## $($release.tag_name) - $($release.name)`n$($release.body)`n"
}
# Collect important code snippets
$importantFiles = @(
"Whisper.net/LibraryLoader/NativeLibraryLoader.cs",
"Whisper.net/WhisperProcessorBuilder.cs",
"Whisper.net/WhisperFactory.cs",
"Whisper.net/WhisperProcessor.cs",
"Whisper.net/LibraryLoader/RuntimeOptions.cs",
"examples/Simple/Program.cs",
"examples/NAudioResampleWav/Program.cs",
"examples/ParallelExecution/Program.cs"
)
repo = os.getenv('GITHUB_REPOSITORY')
token = os.getenv('GITHUB_TOKEN')
headers = {'Authorization': f'token {token}'}
issues = []
page = 1
while True:
response = requests.get(f'https://api.github.com/repos/{repo}/issues', headers=headers, params={'state': 'all', 'page': page, 'per_page': 100})
data = response.json()
if not data:
break
issues.extend(data)
page += 1
Out-File -FilePath "code_snippets.md" -Encoding utf8 -InputObject ""
foreach ($filePath in $importantFiles) {
Add-Content -Path "code_snippets.md" -Value "## $filePath`n"
$fullPath = Join-Path -Path $repoRoot -ChildPath $filePath
Write-Output "Checking path: $fullPath" # Debugging
with open('issues.md', 'w') as f:
for issue in issues:
f.write(f"## #{issue['number']} - {issue['title']}\n")
f.write(f"{issue['body']}\n\n")
comments_url = issue['comments_url']
comments_response = requests.get(comments_url, headers=headers)
comments = comments_response.json()
if comments:
f.write("### Comments:\n")
for comment in comments:
f.write(f"- **{comment['user']['login']}**: {comment['body']}\n")
f.write("\n")
EOF
if (Test-Path $fullPath) {
$content = Get-Content -Path $fullPath -Raw | Out-String
Add-Content -Path "code_snippets.md" -Value "``````csharp"
Add-Content -Path "code_snippets.md" -Value $content
Add-Content -Path "code_snippets.md" -Value "``````n"
} else {
Write-Error "File not found: $fullPath" exit 1 # Fail the script if a file is not found
}
}
- name: Upload issues artifact
uses: actions/upload-artifact@v3
- name: Upload data artifact
uses: actions/upload-artifact@v4
with:
name: issues
path: issues.md
name: data
path: "*.md"

0 comments on commit 76d9239

Please sign in to comment.