Skip to content

Adding CSS to new domain #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# GLOBAL OWNER
* @ProjectPythiaTutorials/infrastructure
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
# - package-ecosystem: pip
# directory: "/"
# schedule:
# interval: daily
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
# Check for updates once a week
interval: 'weekly'
55 changes: 55 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: deploy-site
on:
push:
pull_request:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
if: github.repository == 'ProjectPythiaTutorials/projectpythiatutorials.github.io'
steps:
- name: Cancel previous runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v2

- uses: conda-incubator/setup-miniconda@master
with:
channels: conda-forge,nodefaults
channel-priority: strict
activate-environment: pythia
auto-update-conda: false
python-version: 3.9
environment-file: ci/environment.yml
mamba-version: '*'
use-mamba: true

- name: Build
run: |
conda env list
cd site
make -j4 html
- name: Zip the site
run: |
set -x
set -e
if [ -f site.zip ]; then
rm -rf site.zip
fi
zip -r site.zip ./site/_build/html
- uses: actions/upload-artifact@v2
with:
name: site-zip
path: ./site.zip

- name: Deploy
if: github.ref == 'refs/heads/main'
uses: peaceiris/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./site/_build/html
cname: tutorials.projectpythia.org
84 changes: 84 additions & 0 deletions .github/workflows/collect-user-submission.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import json
import os
import typing

import frontmatter
import pydantic
from markdown_it import MarkdownIt


class Author(pydantic.BaseModel):
name: str = 'anonymous'
affiliation: str = None
affiliation_url: typing.Union[str, pydantic.HttpUrl] = None
email: typing.Union[str, pydantic.EmailStr] = None


class Submission(pydantic.BaseModel):
title: str
description: str
url: pydantic.HttpUrl
thumbnail: typing.Union[str, pydantic.HttpUrl] = None
authors: typing.List[Author] = None
tags: typing.Dict[str, typing.List[str]] = None


@pydantic.dataclasses.dataclass
class IssueInfo:
gh_event_path: pydantic.FilePath
submission: Submission = pydantic.Field(default=None)

def __post_init_post_parse__(self):
with open(self.gh_event_path) as f:
self.data = json.load(f)

def create_submission(self):
self._get_inputs()
self._create_submission_input()
return self

def _get_inputs(self):
self.author = self.data['issue']['user']['login']
self.title = self.data['issue']['title']
self.body = self.data['issue']['body']

def _create_submission_input(self):
md = MarkdownIt()
inputs = None
for token in md.parse(self.body):
if token.tag == 'code':
inputs = frontmatter.loads(token.content).metadata
break
name = inputs.get('name')
title = inputs.get('title')
description = inputs.get('description')
url = inputs.get('url')
thumbnail = inputs.get('thumbnail')
_authors = inputs.get('authors')
authors = []
if _authors:
for item in _authors:
authors.append(
Author(
name=item.get('name', 'anyonymous'),
affiliation=item.get('affiliation'),
affiliation_url=item.get('affiliation_url'),
email=item.get('email', ''),
)
)
else:
authors = [Author(name='anyonymous')]
_tags = inputs.get(
'tags', {'packages': ['unspecified'], 'formats': ['unspecified'], 'domains': ['unspecified']}
)
self.submission = Submission(
name=name, title=title, description=description, url=url, thumbnail=thumbnail, authors=authors, tags=_tags
)


if __name__ == '__main__':

issue = IssueInfo(gh_event_path=os.environ['GITHUB_EVENT_PATH']).create_submission()
inputs = issue.submission.dict()
with open('gallery-submission-input.json', 'w') as f:
json.dump(inputs, f)
130 changes: 130 additions & 0 deletions .github/workflows/preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: preview-site
on:
workflow_run:
workflows:
- deploy-site
types:
- requested
- completed
jobs:
deploy:
if: github.repository == 'ProjectPythiaTutorials/projectpythiatutorials.github.io'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v2
- name: Set message value
run: |
echo "comment_message=This pull request is being automatically built with [GitHub Actions](https://github.com/features/actions) and [Netlify](https://www.netlify.com/). To see the status of your deployment, click below." >> $GITHUB_ENV
- name: Find Pull Request
uses: actions/github-script@v4
id: find-pull-request
with:
script: |
let pullRequestNumber = ''
let pullRequestHeadSHA = ''
core.info('Finding pull request...')
const pullRequests = await github.pulls.list({owner: context.repo.owner, repo: context.repo.repo})
for (let pullRequest of pullRequests.data) {
if(pullRequest.head.sha === context.payload.workflow_run.head_commit.id) {
pullRequestHeadSHA = pullRequest.head.sha
pullRequestNumber = pullRequest.number
break
}
}
core.setOutput('number', pullRequestNumber)
core.setOutput('sha', pullRequestHeadSHA)
if(pullRequestNumber === '') {
core.info(
`No pull request associated with git commit SHA: ${context.payload.workflow_run.head_commit.id}`
)
}
else{
core.info(`Found pull request ${pullRequestNumber}, with head sha: ${pullRequestHeadSHA}`)
}
- name: Find Comment
uses: peter-evans/find-comment@v1
if: steps.find-pull-request.outputs.number != ''
id: fc
with:
issue-number: '${{ steps.find-pull-request.outputs.number }}'
comment-author: 'github-actions[bot]'
body-includes: '${{ env.comment_message }}'
- name: Create comment
if: |
github.event.workflow_run.conclusion != 'success'
&& steps.find-pull-request.outputs.number != ''
&& steps.fc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ steps.find-pull-request.outputs.number }}
body: |
${{ env.comment_message }}

🚧 Deployment in progress for git commit SHA: ${{ steps.find-pull-request.outputs.sha }}
- name: Update comment
if: |
github.event.workflow_run.conclusion != 'success'
&& steps.find-pull-request.outputs.number != ''
&& steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
body: |
${{ env.comment_message }}

🚧 Deployment in progress for git commit SHA: ${{ steps.find-pull-request.outputs.sha }}
- name: Download Artifact site
if: |
github.event.workflow_run.conclusion == 'success'
&& steps.find-pull-request.outputs.number != ''
&& steps.fc.outputs.comment-id != ''
uses: dawidd6/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
workflow: ci.yaml
run_id: ${{ github.event.workflow_run.id }}
name: site-zip
- name: Unzip site
if: |
github.event.workflow_run.conclusion == 'success'
&& steps.find-pull-request.outputs.number != ''
&& steps.fc.outputs.comment-id != ''
run: |
rm -rf ./site/_build/html
unzip site.zip
rm -f site.zip
# Push the site's HTML to Netlify and get the preview URL
- name: Deploy to Netlify
if: |
github.event.workflow_run.conclusion == 'success'
&& steps.find-pull-request.outputs.number != ''
&& steps.fc.outputs.comment-id != ''
id: netlify
uses: nwtgck/[email protected]
with:
publish-dir: ./site/_build/html
production-deploy: false
github-token: ${{ secrets.GITHUB_TOKEN }}
enable-commit-comment: false
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
timeout-minutes: 5
- name: Update site Preview comment
if: |
github.event.workflow_run.conclusion == 'success'
&& steps.find-pull-request.outputs.number != ''
&& steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
body: |
${{ env.comment_message }}

🔍 Git commit SHA: ${{ steps.find-pull-request.outputs.sha }}
✅ Deployment Preview URL: ${{ steps.netlify.outputs.deploy-url }}
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
site/_build/
dist/
49 changes: 49 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-docstring-first
- id: check-json
- id: check-yaml
- id: double-quote-string-fixer

- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black

- repo: https://github.com/keewis/blackdoc
rev: v0.3.4
hooks:
- id: blackdoc

- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8

- repo: https://github.com/asottile/seed-isort-config
rev: v2.2.0
hooks:
- id: seed-isort-config
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort

# - repo: https://github.com/prettier/pre-commit
# rev: 57f39166b5a5a504d6808b87ab98d41ebf095b46
# hooks:
# - id: prettier

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.3.1
hooks:
- id: nbqa-black
additional_dependencies: [black==20.8b1]
- id: nbqa-pyupgrade
additional_dependencies: [pyupgrade==2.7.3]
# - id: nbqa-isort
# additional_dependencies: [isort==5.6.4]
14 changes: 14 additions & 0 deletions ci/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pythia-tutorial-dev
channels:
- conda-forge
- nodefaults
dependencies:
- matplotlib
- myst-nb
- pandas
- pip
- pyyaml
- pre-commit
- sphinx-panels
- pip:
- sphinx-pythia-theme
16 changes: 16 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[flake8]
exclude =
ignore =E501
max-line-length = 120
max-complexity = 18
select = B,C,E,F,W,T4,B9

[isort]
known_first_party=
known_third_party=frontmatter,gallery_generator,markdown_it,pydantic,truncatehtml,yaml
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
combine_as_imports=True
line_length=120
skip=
Loading