Crawl Versions from newreleases.io #667
This file contains hidden or 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
| 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: | |
| crawl-versions: | |
| if: github.repository == 'community-scripts/ProxmoxVED' | |
| runs-on: ubuntu-latest | |
| 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@v2 | |
| with: | |
| app-id: ${{ vars.APP_ID }} | |
| private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
| owner: community-scripts | |
| repositories: ProxmoxVED | |
| - name: Generate a token for PR approval and merge | |
| id: generate-token-merge | |
| uses: actions/create-github-app-token@v2 | |
| with: | |
| app-id: ${{ secrets.APP_ID_APPROVE_AND_MERGE }} | |
| private-key: ${{ secrets.APP_KEY_APPROVE_AND_MERGE }} | |
| owner: community-scripts | |
| repositories: ProxmoxVED | |
| - 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 | |
| echo "Ensuring $name has exclude_prereleases=true" | |
| curl -s -X POST -H "X-Key: $token" -H "Content-Type: application/json" \ | |
| -d '{"exclude_prereleases": true}' \ | |
| "https://api.newreleases.io/v1/projects/$id" > /dev/null | |
| version=$(curl -s -H "X-Key: $token" "https://api.newreleases.io/v1/projects/$id/latest-release") | |
| version_data=$(echo "$version" | jq -r '.version // empty') | |
| date=$(echo "$version" | jq -r '.date // empty') | |
| if [ -n "$version_data" ]; then | |
| jq --arg name "$name" --arg version "$version_data" --arg date "$date" \ | |
| '. += [{"name": $name, "version": $version, "date": $date}]' "$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: Approve pull request and merge | |
| if: env.changed == 'true' | |
| env: | |
| GH_TOKEN: ${{ steps.generate-token-merge.outputs.token }} | |
| run: | | |
| git config --global user.name "github-actions-automege[bot]" | |
| git config --global user.email "github-actions-automege[bot]@users.noreply.github.com" | |
| PR_NUMBER=$(gh pr list --head "${BRANCH_NAME}" --json number --jq '.[0].number') | |
| if [ -n "$PR_NUMBER" ]; then | |
| gh pr review "$PR_NUMBER" --approve | |
| gh pr merge "$PR_NUMBER" --squash --admin | |
| fi |