-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement HTML output and deployment to GitHub Pages
* Add first version of HTML template * feat: added html export added html export based on jinja according to hte inputed template * fix: imporved readme * feat: documentation for workflow * fix: fixed table header Co-authored-by: Marián Hlaváč <[email protected]>
- Loading branch information
1 parent
a855a4b
commit 6c0c64e
Showing
10 changed files
with
432 additions
and
65 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,80 +7,145 @@ on: | |
branches: [master] | ||
|
||
permissions: | ||
contents: read | ||
contents: write | ||
pages: write | ||
deployments: write | ||
id-token: write | ||
|
||
jobs: | ||
convert_and_release: | ||
name: Convert CSV to files | ||
convert_to_json: | ||
name: Convert CSV to JSON files | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: checkout repo content | ||
uses: actions/checkout@v2 # checkout the repository content to github runner. | ||
|
||
- name: setup python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: execute py script # run the run.py to get the latest data | ||
run: | | ||
python convertors/json_convertor.py | ||
- name: Upload converted files # Upload 3 JSON files outputted from py script | ||
uses: actions/upload-artifact@v1 | ||
with: | ||
name: json | ||
path: ./out | ||
|
||
convert_to_html: | ||
name: Convert CSV to HTML template | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
steps: | ||
- name: checkout repo content | ||
uses: actions/checkout@v2 # checkout the repository content to github runner. | ||
|
||
- name: setup python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Install Jinja2 # For putting data into HTML template | ||
run: | | ||
pip install Jinja2 | ||
- name: execute py script # run the run.py to get the latest data | ||
run: | | ||
python convertors/convertor.py | ||
# - name: Get current date | ||
# id: date | ||
# run: echo "::set-output name=date::$(date +'%Y%m%d-%H%M')" | ||
# - name: Release | ||
# uses: actions/create-release@v1 | ||
# id: create_release | ||
# with: | ||
# draft: false | ||
# prerelease: false | ||
# release_name: ${{ steps.date.outputs.date }} | ||
# tag_name: ${{ steps.date.outputs.date }} | ||
# body: "Expanded drone manufacturer and drone models database" | ||
# env: | ||
# GITHUB_TOKEN: ${{ github.token }} | ||
|
||
# - name: Upload manufacturers artifact | ||
# uses: actions/upload-release-asset@v1 | ||
# env: | ||
# GITHUB_TOKEN: ${{ github.token }} | ||
# with: | ||
# upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
# asset_path: ./out/manufacturers.json | ||
# asset_name: manufacturers.json | ||
# asset_content_type: application/json | ||
|
||
# - name: Upload manufacturers with models artifacts | ||
# uses: actions/upload-release-asset@v1 | ||
# env: | ||
# GITHUB_TOKEN: ${{ github.token }} | ||
# with: | ||
# upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
# asset_path: ./out/manufacturersWithModels.json | ||
# asset_name: manufacturersWithModels.json | ||
# asset_content_type: application/json | ||
|
||
# - name: Upload models artifacts | ||
# uses: actions/upload-release-asset@v1 | ||
# env: | ||
# GITHUB_TOKEN: ${{ github.token }} | ||
# with: | ||
# upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
# asset_path: ./out/models.json | ||
# asset_name: models.json | ||
# asset_content_type: application/json | ||
python convertors/html_convertor.py | ||
- name: Upload converted files # Upload html and CSS + fonts outputted from py script | ||
uses: actions/upload-artifact@v1 | ||
with: | ||
name: html | ||
path: ./out | ||
|
||
release: | ||
name: Create a release | ||
needs: [convert_to_html, convert_to_json] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Download JSON artifact | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: json | ||
path: ./json | ||
|
||
- name: Get current date # Get formatted date for release tag creation | ||
id: date | ||
run: echo "::set-output name=date::$(date +'%Y%m%d-%H%M')" | ||
|
||
- name: Release # Create a release | ||
uses: actions/create-release@v1 | ||
id: create_release | ||
with: | ||
draft: false | ||
prerelease: false | ||
release_name: ${{ steps.date.outputs.date }} | ||
tag_name: ${{ steps.date.outputs.date }} | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
|
||
- name: Upload manufacturers artifact # Attach manufacturers JSON to release | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./json/manufacturers.json | ||
asset_name: manufacturers.json | ||
asset_content_type: application/json | ||
|
||
- name: Upload manufacturers with models artifacts # Attach manufacturers with models JSON to release | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./json/manufacturersWithModels.json | ||
asset_name: manufacturersWithModels.json | ||
asset_content_type: application/json | ||
|
||
- name: Upload models artifacts # Attach models JSON to release | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./json/models.json | ||
asset_name: models.json | ||
asset_content_type: application/json | ||
|
||
deploy: | ||
name: Deploy to Github pages | ||
needs: [convert_to_html, convert_to_json] | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
steps: | ||
- name: Download JSON artifact # Download JSON out file | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: json | ||
path: ./json | ||
- name: Download HTML artifact # Download HTML out file | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: html | ||
path: ./html | ||
- name: Merge artifacts for upload # Merging the two artifacts into one, which is then uploaded to pages | ||
run: | | ||
mkdir out | ||
cp -a ./json/. ./out/ | ||
cp -a ./html/. ./out/ | ||
- name: Upload converted files | ||
uses: actions/[email protected] | ||
with: | ||
name: github-pages | ||
path: ./out | ||
- name: Deploy Github Pages | ||
- name: Deploy Github Pages # Deploy to pages | ||
uses: actions/deploy-pages@v1 | ||
id: deployment | ||
with: | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import csv | ||
import os | ||
from jinja2 import Environment, PackageLoader | ||
import shutil | ||
|
||
env = Environment(loader=PackageLoader('html_convertor', 'templates')) | ||
|
||
template = env.get_template("template.html.jinja") | ||
|
||
dir_path = 'out' | ||
|
||
os.makedirs(dir_path, exist_ok=True) | ||
with open('list.csv') as csv_file: | ||
# Read csv - maybe input as a arg | ||
csv_reader = csv.reader(csv_file, delimiter=',') | ||
line_count = 0 # For iterating through lines | ||
manufacturers = dict() # Initialize manufacturers as a Dict | ||
models = list() # Initialize models as a list | ||
parameters = dict() # Initialize parameters as a dict | ||
|
||
for row in csv_reader: | ||
for param in row: # only first row with parameters is necessary | ||
parameters[param] = row.index(param) | ||
break | ||
|
||
# Reset for second iteration | ||
line_count = 0 | ||
csv_file.seek(0) | ||
|
||
# Second iteration of CSV for two JSON | ||
for row in csv_reader: | ||
if line_count == 0: | ||
line_count += 1 | ||
continue | ||
|
||
manufacturer = row[parameters.get('manufacturer')] | ||
name = row[parameters.get('name')] | ||
uas_class = row[parameters.get('class')] | ||
weight = row[parameters.get('weight')] | ||
max_takeoff = row[parameters.get('max_takeoff')] | ||
endurance = row[parameters.get('endurance')] | ||
has_camera = row[parameters.get('has_camera')] | ||
is_toy = row[parameters.get('is_toy')] | ||
|
||
models.append({'manufacturer': manufacturer, 'name': name, 'uas_class': uas_class, | ||
"weight": weight, 'max_takeoff': max_takeoff, 'endurance': endurance, 'has_camera': has_camera, 'is_toy': is_toy}) | ||
|
||
line_count += 1 | ||
|
||
with open(os.path.join(dir_path, 'index.html'), 'w') as outfile: | ||
outfile.write(template.render(models=models)) | ||
try: # throws an error of file being in the folder, even in case of empty folder, nevertheless, the files are copied | ||
shutil.copy('templates/styles.css', 'out/styles.css') | ||
shutil.copytree('templates/fonts', 'out/fonts') | ||
except: | ||
pass |
File renamed without changes.
Oops, something went wrong.