mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2025-06-29 18:47:38 +00:00
Add worflow to crawl APP verisons (#3192)
* Add worflow to crawl verisons * Update Test
This commit is contained in:
committed by
GitHub
parent
64d5caae15
commit
7cc4fee48b
113
.github/workflows/crawl-versions.yaml
vendored
Normal file
113
.github/workflows/crawl-versions.yaml
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
name: Crawl Versions from newreleases.io
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
# Runs at 12:00 AM and 12:00 PM UTC
|
||||
- cron: "0 0,12 * * *"
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
move-to-main-repo:
|
||||
runs-on: runner-cluster-htl-set
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: community-scripts/ProxmoxVED
|
||||
ref: main
|
||||
|
||||
- name: Generate a token
|
||||
id: generate-token
|
||||
uses: actions/create-github-app-token@v1
|
||||
with:
|
||||
app-id: ${{ vars.APP_ID }}
|
||||
private-key: ${{ secrets.APP_PRIVATE_KEY }}
|
||||
|
||||
- name: Crawl from newreleases.io
|
||||
env:
|
||||
token: ${{ secrets.NEWRELEASES_TOKEN }}
|
||||
run: |
|
||||
page=1
|
||||
projects_file="project_json"
|
||||
output_file="frontend/public/json/versions.json"
|
||||
|
||||
echo "[]" > $output_file
|
||||
|
||||
while true; do
|
||||
|
||||
echo "Start loop on page: $page"
|
||||
|
||||
projects=$(curl -s -H "X-Key: $token" "https://api.newreleases.io/v1/projects?page=$page")
|
||||
total_pages=$(echo "$projects" | jq -r '.total_pages')
|
||||
|
||||
if [ -z "$total_pages" ] || [ "$total_pages" -eq 0 ]; then
|
||||
echo "No pages available. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
if [ $page == $total_pages ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
if [ -z "$projects" ] || ! echo "$projects" | jq -e '.projects' > /dev/null; then
|
||||
echo "No more projects or invalid response. Exiting."
|
||||
break
|
||||
fi
|
||||
|
||||
echo "$projects" > "$projects_file"
|
||||
|
||||
jq -r '.projects[] | "\(.id) \(.name)"' "$projects_file" | while read -r id name; do
|
||||
version=$(curl -s -H "X-Key: $token" "https://api.newreleases.io/v1/projects/$id/latest-release")
|
||||
version_data=$(echo "$version" | jq -r '.version // empty')
|
||||
if [ -n "$version_data" ]; then
|
||||
jq --arg name "$name" --arg version "$version_data" \
|
||||
'. += [{"name": $name, "version": $version}]' "$output_file" > "$output_file.tmp" && mv "$output_file.tmp" "$output_file"
|
||||
fi
|
||||
done
|
||||
((page++))
|
||||
done
|
||||
|
||||
- name: Commit JSON
|
||||
env:
|
||||
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
|
||||
run: |
|
||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git config --global user.name "GitHub Actions[bot]"
|
||||
git checkout -b update_versions || git checkout update_versions
|
||||
git add frontend/public/json/versions.json
|
||||
if git diff --cached --quiet; then
|
||||
echo "No changes detected."
|
||||
echo "changed=false" >> "$GITHUB_ENV"
|
||||
exit 0
|
||||
else
|
||||
echo "Changes detected:"
|
||||
git diff --stat --cached
|
||||
echo "changed=true" >> "$GITHUB_ENV"
|
||||
fi
|
||||
git commit -m "Update versions.json"
|
||||
git push origin update_versions --force
|
||||
gh pr create --title "[AUTOMATIC PR]Update versions.json" --body "Update versions.json, crawled from newreleases.io" --base main --head update_versions
|
||||
|
||||
- name: Approve pull request
|
||||
if: env.changed == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
PR_NUMBER=$(gh pr list --head "update_versions" --json number --jq '.[].number')
|
||||
if [ -n "$PR_NUMBER" ]; then
|
||||
gh pr review $PR_NUMBER --approve
|
||||
fi
|
||||
|
||||
- name: Re-approve pull request after update
|
||||
if: env.changed == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
PR_NUMBER=$(gh pr list --head "update_versions" --json number --jq '.[].number')
|
||||
if [ -n "$PR_NUMBER" ]; then
|
||||
gh pr review $PR_NUMBER --approve
|
||||
fi
|
Reference in New Issue
Block a user