generated from Shifu-Engineer/fastpages
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 42bdbf8
Showing
70 changed files
with
3,377 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,195 @@ | ||
name: Chatops | ||
on: [issue_comment] | ||
|
||
jobs: | ||
trigger-chatops: | ||
if: github.event.issue.pull_request != null && contains(github.event.comment.body, '/preview') | ||
env: | ||
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | ||
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | ||
CHECK_RUN_NAME: "Draft-Site-Build" | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: see payload | ||
run: | | ||
echo "FULL PAYLOAD:\n${PAYLOAD}\n" | ||
echo "PR_PAYLOAD PAYLOAD:\n${PR_PAYLOAD}" | ||
env: | ||
PAYLOAD: ${{ toJSON(github.event) }} | ||
PR_PAYLOAD: ${{ github.event.pull_request }} | ||
|
||
- name: verify env exists | ||
id: get_status | ||
run: | | ||
if [ -z ${NETLIFY_AUTH_TOKEN} ]; then echo "::set-output name=status::public"; else echo "::set-output name=status::private"; fi | ||
- name: make comment on PR if env does not exist | ||
if: steps.get_status.outputs.status == 'public' | ||
run: | | ||
./_action_files/pr_comment.sh "Was not able to generate site preview due to absent credentials." | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
ISSUE_NUMBER: ${{ github.event.issue.number }} | ||
|
||
- name: Fetch context about the PR that has been commented on | ||
id: chatops | ||
uses: machine-learning-apps/actions-chatops@master | ||
with: | ||
TRIGGER_PHRASE: "/preview" | ||
env: # you must supply GITHUB_TOKEN | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.6 | ||
|
||
- name: install requests | ||
run: pip3 install requests | ||
|
||
- name: add check run | ||
id: create_check | ||
if: steps.get_status.outputs.status == 'private' | ||
shell: python | ||
run: | | ||
import os, requests | ||
sha = os.getenv('SHA') | ||
token = os.getenv('GITHUB_TOKEN') | ||
nwo = os.getenv('GITHUB_REPOSITORY') | ||
name = os.getenv('CHECK_RUN_NAME') | ||
url = f'https://api.github.com/repos/{nwo}/check-runs' | ||
headers = {'authorization': f'token {token}', | ||
'accept': 'application/vnd.github.antiope-preview+json'} | ||
payload = { | ||
'name': f'{name}', | ||
'head_sha': f'{sha}', | ||
'status': 'in_progress', | ||
'output':{ | ||
'title': f'Building preview of site for {sha}.', | ||
'summary': ' ', | ||
'text': ' ' | ||
}, | ||
} | ||
response = requests.post(url=url, headers=headers, json=payload) | ||
print(response) | ||
id = response.json()['id'] | ||
print(f"::set-output name=id::{id}") | ||
env: | ||
SHA: ${{ steps.chatops.outputs.SHA }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: add label | ||
if: steps.get_status.outputs.status == 'private' | ||
run: | | ||
import os, requests | ||
nwo = os.getenv('GITHUB_REPOSITORY') | ||
token = os.getenv('GITHUB_TOKEN') | ||
pr_num = os.getenv('PR_NUM') | ||
headers = {'Accept': 'application/vnd.github.symmetra-preview+json', | ||
'Authorization': f'token {token}'} | ||
url = f"https://api.github.com/repos/{nwo}/issues/{pr_num}/labels" | ||
data = {"labels": ["draft build pending"]} | ||
result = requests.post(url=url, headers=headers, json=data) | ||
# assert response.status_code == 201, f"Received status code of {response.status_code}" | ||
print(result) | ||
shell: python | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
PR_NUM: ${{ steps.chatops.outputs.PULL_REQUEST_NUMBER }} | ||
GITHUB_REPOSITORY: $GITHUB_REPOSITORY | ||
|
||
- name: Copy The PR's Branch Repository Contents | ||
uses: actions/checkout@master | ||
if: steps.get_status.outputs.status == 'private' | ||
with: | ||
ref: ${{ steps.chatops.outputs.SHA }} | ||
|
||
- name: convert notebooks and word docs to posts | ||
uses: ./ # use the code in this repo to instead of fastai/fastpages@master | ||
|
||
- name: setup directories for Jekyll build | ||
if: steps.get_status.outputs.status == 'private' | ||
run: | | ||
rm -rf _site | ||
sudo chmod -R 777 . | ||
- name: Jekyll build with baseurl as root for netifly | ||
if: steps.get_status.outputs.status == 'private' | ||
uses: docker://jekyll/jekyll | ||
with: | ||
args: jekyll build --baseurl / | ||
|
||
- name: deploy to netlify | ||
if: steps.get_status.outputs.status == 'private' | ||
id: py | ||
run: | | ||
sudo npm install netlify-cli -g | ||
netlify deploy --dir _site | tee _netlify_logs.txt | ||
cat _netlify_logs.txt | python _action_files/parse_netlify.py | ||
- name: make comment on PR | ||
if: steps.get_status.outputs.status == 'private' | ||
run: | | ||
MSG="A preview build of this branch has been generated for SHA: $SHA and can be viewed **live** at: ${URL}\n\nThe current fastpages site built from master can be viewed for comparison [here](https://fastpages.fast.ai/)" | ||
echo "$MSG" | ||
./_action_files/pr_comment.sh "${MSG}" | ||
env: | ||
URL: ${{ steps.py.outputs.draft_url }} | ||
SHA: ${{ steps.chatops.outputs.SHA }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
ISSUE_NUMBER: ${{ github.event.issue.number }} | ||
|
||
- name: remove label | ||
if: always() | ||
run: | | ||
import os, requests | ||
nwo = os.getenv('GITHUB_REPOSITORY') | ||
token = os.getenv('GITHUB_TOKEN') | ||
pr_num = os.getenv('PR_NUM') | ||
headers = {'Accept': 'application/vnd.github.symmetra-preview+json', | ||
'Authorization': f'token {token}'} | ||
url = f"https://api.github.com/repos/{nwo}/issues/{pr_num}/labels/draft%20build%20pending" | ||
result = requests.delete(url=url, headers=headers) | ||
print(result) | ||
shell: python | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
PR_NUM: ${{ steps.chatops.outputs.PULL_REQUEST_NUMBER }} | ||
GITHUB_REPOSITORY: $GITHUB_REPOSITORY | ||
|
||
# defensively clear check run each time | ||
- name: clear check run | ||
if: always() | ||
continue-on-error: true | ||
shell: python | ||
run: | | ||
import os, requests | ||
sha = os.getenv('SHA') | ||
conclusion = os.getenv('WORKFLOW_CONCLUSION').lower() | ||
token = os.getenv('GITHUB_TOKEN') | ||
nwo = os.getenv('GITHUB_REPOSITORY') | ||
check_run_id = os.getenv('CHECK_RUN_ID') | ||
if not check_run_id: | ||
quit() | ||
url = f'https://api.github.com/repos/{nwo}/check-runs/{check_run_id}' | ||
headers = {'authorization': f'token {token}', | ||
'accept': 'application/vnd.github.antiope-preview+json'} | ||
data = { | ||
'conclusion': f'{conclusion}', | ||
} | ||
response = requests.patch(url=url, headers=headers, json=data) | ||
print(response) | ||
env: | ||
SHA: ${{ steps.chatops.outputs.SHA }} | ||
WORKFLOW_CONCLUSION: ${{ job.status }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
CHECK_RUN_ID: ${{ steps.create_check.outputs.id }} | ||
|
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,48 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- master # need to filter here so we only deploy when there is a push to master | ||
# no filters on pull requests, so intentionally left blank | ||
pull_request: | ||
|
||
jobs: | ||
build-site: | ||
if: ( github.event.commits[0].message != 'Initial commit' ) || github.run_number > 1 | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Copy Repository Contents | ||
uses: actions/checkout@master | ||
with: | ||
persist-credentials: false | ||
|
||
- name: fastpages repo only - convert notebooks and word docs to posts | ||
if: github.repository == 'fastai/fastpages' | ||
uses: ./ # use code in this repo instead of fastai/fastpages@master, for testing. | ||
|
||
- name: convert notebooks and word docs to posts | ||
if: github.repository != 'fastai/fastpages' | ||
uses: fastai/fastpages@master # templates will use what is in fastai/fastpages | ||
|
||
- name: setup directories for Jekyll build | ||
run: | | ||
rm -rf _site | ||
sudo chmod -R 777 . | ||
- name: Jekyll build | ||
uses: docker://jekyll/jekyll | ||
with: | ||
args: jekyll build -V | ||
|
||
- name: copy CNAME file into _site if CNAME exists | ||
run: | | ||
sudo chmod -R 777 _site/ | ||
cp CNAME _site/ 2>/dev/null || : | ||
- name: Deploy | ||
if: github.event_name == 'push' | ||
uses: peaceiris/actions-gh-pages@v3 | ||
with: | ||
deploy_key: ${{ secrets.SSH_DEPLOY_KEY }} | ||
publish_dir: ./_site |
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,17 @@ | ||
name: GH-Pages Status | ||
on: | ||
page_build | ||
|
||
jobs: | ||
see-page-build-payload: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: check status | ||
run: | | ||
import os | ||
status, errormsg = os.getenv('STATUS'), os.getenv('ERROR') | ||
assert status == 'built', 'There was an error building the page on GitHub pages.\n\nStatus: {}\n\nError messsage: {}'.format(status, errormsg) | ||
shell: python | ||
env: | ||
STATUS: ${{ github.event.build.status }} | ||
ERROR: ${{ github.event.build.error.message }} |
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,80 @@ | ||
name: Setup | ||
on: push | ||
|
||
jobs: | ||
setup: | ||
if: (github.event.commits[0].message == 'Initial commit') && (github.run_number == 1) | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.6 | ||
|
||
- name: Copy Repository Contents | ||
uses: actions/checkout@v2 | ||
|
||
- name: modify files | ||
run: | | ||
import re, os | ||
from pathlib import Path | ||
nwo = os.getenv('GITHUB_REPOSITORY') | ||
username, repo_name = nwo.split('/') | ||
readme_template_path = Path('README_TEMPLATE.md') | ||
readme_path = Path('README.md') | ||
config_path = Path('_config.yml') | ||
pr_msg_path = Path('_setup_pr_template.md') | ||
assert readme_template_path.exists(), 'Did not find README_TEMPLATE.md in the current directory!' | ||
assert readme_path.exists(), 'Did not find README.md in the current directory!' | ||
assert config_path.exists(), 'Did not find _config.yml in the current directory!' | ||
assert pr_msg_path.exists(), 'Did not find _setup_pr_template.md in the current directory!' | ||
# replace content of README with template | ||
readme = readme_template_path.read_text().replace('{_username_}', username).replace('{_repo_name_}', repo_name) | ||
readme_path.write_text(readme) | ||
# update _config.yml | ||
cfg = config_path.read_text() | ||
cfg = re.sub(r'^(github_username: )(fastai)', r'\1{}'.format(username), cfg, flags=re.MULTILINE) | ||
cfg = re.sub(r'^(baseurl: )("")', r'\1"/{}"'.format(repo_name), cfg, flags=re.MULTILINE) | ||
cfg = re.sub(r'^(github_repo: ")(fastpages)', r'\1{}'.format(repo_name), cfg, flags=re.MULTILINE) | ||
cfg = re.sub(r'^(url: "https://)(fastpages.fast.ai)(")', r'\1{}.github.io\3'.format(username), cfg, flags=re.MULTILINE) | ||
config_path.write_text(cfg) | ||
# prepare the pr message | ||
pr = pr_msg_path.read_text().replace('{_username_}', username).replace('{_repo_name_}', repo_name) | ||
pr_msg_path.write_text(pr) | ||
shell: python | ||
|
||
- name: commit changes | ||
run: | | ||
git config --global user.email "${GH_EMAIL}" | ||
git config --global user.name "${GH_USERNAME}" | ||
git checkout -B fastpages-automated-setup | ||
git rm README_TEMPLATE.md CONTRIBUTING.md CNAME action.yml _checkbox.png | ||
git rm .github/workflows/chatops.yaml | ||
git add _config.yml README.md _setup_pr_template.md | ||
git commit -m'setup repo' | ||
git push -f --set-upstream origin fastpages-automated-setup | ||
env: | ||
GH_EMAIL: ${{ github.event.commits[0].author.email }} | ||
GH_USERNAME: ${{ github.event.commits[0].author.username }} | ||
|
||
- name: Open a PR | ||
uses: actions/github-script@0.5.0 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
var fs = require('fs'); | ||
var contents = fs.readFileSync('_setup_pr_template.md', 'utf8'); | ||
github.pulls.create({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
title: 'Initial Setup', | ||
head: 'fastpages-automated-setup', | ||
base: 'master', | ||
body: `${contents}` | ||
}) |
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,12 @@ | ||
*.swp | ||
~* | ||
*~ | ||
_site | ||
.sass-cache | ||
.jekyll-cache | ||
.jekyll-metadata | ||
vendor | ||
_notebooks/.ipynb_checkpoints | ||
# Local Netlify folder | ||
.netlify | ||
__pycache__ |
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,24 @@ | ||
--- | ||
permalink: /404.html | ||
layout: default | ||
--- | ||
|
||
<style type="text/css" media="screen"> | ||
.container { | ||
margin: 10px auto; | ||
max-width: 600px; | ||
text-align: center; | ||
} | ||
h1 { | ||
margin: 30px 0; | ||
font-size: 4em; | ||
line-height: 1; | ||
letter-spacing: -1px; | ||
} | ||
</style> | ||
|
||
<div class="container"> | ||
<h1>404</h1> | ||
<p><strong>Page not found :(</strong></p> | ||
<p>The requested page could not be found.</p> | ||
</div> |
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 @@ | ||
fastpages.fast.ai |
Oops, something went wrong.