Skip to content

Merge pull request #63 from IvanHanloth/IvanHanloth-patch-1 #56

Merge pull request #63 from IvanHanloth/IvanHanloth-patch-1

Merge pull request #63 from IvanHanloth/IvanHanloth-patch-1 #56

name: Update Releases and Pages
on:
push:
branches: ["main"]
release:
types: [published, edited, deleted]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
fetch-and-sort-releases:
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests
- name: Create Python script
run: |
cat << 'EOF' > fetch_releases.py
import requests
import json
import os
repo = os.getenv('GITHUB_REPOSITORY')
url = f'https://api.github.com/repos/{repo}/releases'
headers = {
'Authorization': f'Bearer {os.getenv("GITHUB_TOKEN")}',
'Accept': 'application/vnd.github.v3+json'
}
response = requests.get(url, headers=headers)
if response.status_code != 200:
raise Exception(f"Failed to fetch releases: {response.status_code} - {response.text}")
releases = response.json()
filtered_releases = []
for release in releases:
filtered_release = {
"tag_name": release["tag_name"],
"published_at": release["published_at"],
"body": release["body"],
"assets": [
{
"name": asset["name"],
"browser_download_url": asset["browser_download_url"]
}
for asset in release["assets"]
]
}
filtered_releases.append(filtered_release)
sorted_releases = sorted(filtered_releases, key=lambda x: x['published_at'])
with open('releases.json', 'w') as f:
json.dump(sorted_releases, f, indent=2, ensure_ascii=False)
print("Releases saved to releases.json")
EOF
- name: Run Python script
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python fetch_releases.py
- name: Upload releases.json as artifact
uses: actions/upload-artifact@v4
with:
name: releases-json
path: releases.json
build:
runs-on: ubuntu-latest
needs: fetch-and-sort-releases
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Download releases.json artifact
uses: actions/download-artifact@v4
with:
name: releases-json
path: ./
- name: list
run: ls -AlR ./
- name: Build with Jekyll
uses: actions/jekyll-build-pages@v1
with:
source: ./
destination: dest
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: dest
- name: Upload final to airfact
uses: actions/upload-artifact@v4
with:
name: build
path: dest
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4