Skip to content

Commit

Permalink
WIP: fixing gh action attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
krzemienski committed May 20, 2024
1 parent 4b1557c commit 9de7a26
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/deploy-ghpages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ siteSource="$1"
if [ ! -d "$siteSource" ]
then
echo "Usage: $0 <site source dir>"

exit 1
fi

Expand Down
2 changes: 1 addition & 1 deletion .github/deploy-readme.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

if [ $CIRCLE_BRANCH != "master" ]
if [ "$GITHUB_REF" != "refs/heads/master" ]
then
exit
fi
Expand Down
87 changes: 87 additions & 0 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: build-deploy

on:
push:
branches:
- master

env:
GH_TOKEN: xxxxd4ef
PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
CUSTOM_DOMAIN: awesome.video
GIT_DISCOVERY_ACROSS_FILESYSTEM: 1

jobs:
awesomebot:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1'

- name: Install awesome_bot
run: gem install awesome_bot

- name: Run awesome_bot
run: awesome_bot contents.json --allow-ssl --allow-redirect -a 403,503

json-validate:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'

- name: Install json-spec
run: pip install json-spec

- name: Run JSON validate
run: json validate --schema-file=.github/schema.json --document-file=contents.json

deploy-awesome-video:
runs-on: ubuntu-latest
needs: [awesomebot, json-validate]
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: '16'

- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1'

- name: Install Python
uses: actions/setup-python@v2
with:
python-version: '3.9'

- name: Run README.md gen
run: ruby .github/convert.rb

- name: Run database.json gen
run: node .github/upgradeDb.js

- name: Copy README to docs for site gen
run: cp README.md docs/index.md

- name: Run static site gen
run: mkdocs build

- name: Deploy new README
run: .github/deploy-readme.sh

- name: Deploy GitHub Pages
run: .github/deploy-ghpages.sh site
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ jobs:
run: node .github/upgradeDb.js
- name: install mkdoc build deps
run: sudo apt-get update && sudo apt-get -y install lsb-release unzip python3-pip python3-dev && pip3 install mkdocs mkdocs-material json-spec
- name: run copy readme to docs for site gen
run: cp README.md docs/index.md
- name: run static site gen
run: mkdocs build
- name: use makefile to install all deps to ensure we have the same versions
run: make site_install
- name: use makefile to install all deps to ensure we have the same versions
run: make site_build
- name: Deploy docs
uses: mhausenblas/mkdocs-deploy-gh-pages@master
106 changes: 106 additions & 0 deletions alm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
from flask import Flask, request, redirect, url_for
from flask_sqlalchemy import SQLAlchemy
from flask_admin import Admin
from flask_admin.contrib.sqla import ModelView
import requests
import json
import base64
from bs4 import BeautifulSoup

# Flask Setup
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///awesomeness.db'
app.config['SECRET_KEY'] = 'mysecret'

# Database Setup
db = SQLAlchemy(app)

# Flask-Admin Setup
admin = Admin(app, name='AwesomeList Admin', template_mode='bootstrap3')

# Models
class Link(db.Model):
id = db.Column(db.Integer, primary_key=True)
url = db.Column(db.String(150), unique=True, nullable=False)
name = db.Column(db.String(100))
description = db.Column(db.String(300))

# Add administrative views
admin.add_view(ModelView(Link, db.session))

def extract_metadata(url):
try:
response = requests.get(url)
if response.status_code == 200:
soup = BeautifulSoup(response.content, 'html.parser')
title = soup.find('title').text if soup.find('title') else 'No Title'
meta_description = soup.find('meta', attrs={'name': 'description'})
og_description = soup.find('meta', attrs={'property': 'og:description'})
if meta_description and meta_description.get('content'):
description = meta_description['content']
elif og_description and og_description.get('content'):
description = og_description['content']
else:
description = 'No Description'
return {
'title': title,
'description': description,
}
except requests.RequestException:
return None

def generate_readme():
links = Link.query.all()
readme_content = "# Awesome Video\\n\\nA curated list of awesome video resources.\\n\\n"
for link in links:
readme_content += f"- [{link.name}]({link.url}) - {link.description}\\n"
return readme_content

def get_repo_contents_sha():
url = f'https://api.github.com/repos/krzemienski/awesome-video/contents/README.md'
headers = {'Authorization': 'token your_github_token'}
response = requests.get(url, headers=headers)
if response.status_code == 200:
return response.json().get('sha')
return None

def update_github_readme(readme_content):
sha = get_repo_contents_sha()
if not sha:
print("Error: Unable to fetch README metadata")
return False
url = f'https://api.github.com/repos/krzemienski/awesome-video/contents/README.md'
headers = {'Authorization': 'token your_github_token'}
data = {
"message": "Update README.md",
"content": base64.b64encode(readme_content.encode()).decode(),
"sha": sha
}
response = requests.put(url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
print("README updated successfully")
return True
else:
print(f"Error: {response.content}")
return False

@app.route('/submit', methods=['POST'])
def submit_url():
data = request.json
url = data.get('url')
metadata = extract_metadata(url)
if not metadata:
return {'message': 'Failed to extract metadata'}, 400
new_link = Link(url=url, name=metadata.get('title', ''), description=metadata.get('description', ''))
db.session.add(new_link)
db.session.commit()
readme_content = generate_readme()
update_github_readme(readme_content)
return {'message': 'URL submitted successfully'}

def main():
db.create_all()
app.run(debug=True)

if __name__ == "__main__":
main()

0 comments on commit 9de7a26

Please sign in to comment.