|
1 | | -# see https://github.com/actions/starter-workflows/blob/main/pages/jekyll.yml |
| 1 | +# .github/workflows/site.yml |
2 | 2 | name: site |
| 3 | + |
3 | 4 | on: |
4 | | - push: {branches: [main], tags-ignore: ['**']} |
| 5 | + push: |
| 6 | + branches: [main] |
| 7 | + tags-ignore: ['**'] |
5 | 8 | pull_request: |
6 | | - schedule: [{cron: '0 10 * * 6'}] # M H d m w (Sat 10:00) |
| 9 | + schedule: |
| 10 | + - cron: '0 10 * * 6' # Runs at 10:00 UTC every Saturday |
| 11 | + |
7 | 12 | permissions: |
8 | | - # allow GITHUB_TOKEN to deploy to GitHub Pages |
9 | 13 | contents: read |
10 | 14 | pages: write |
11 | 15 | id-token: write |
12 | | -concurrency: {group: "${{ github.ref }}-pages", cancel-in-progress: true} |
| 16 | + |
| 17 | +concurrency: |
| 18 | + group: "${{ github.ref }}-pages" |
| 19 | + cancel-in-progress: true |
| 20 | + |
13 | 21 | env: |
14 | 22 | SITE_PREFIX: state-of-open-source-ai |
| 23 | + |
15 | 24 | jobs: |
16 | 25 | check: |
17 | 26 | runs-on: ubuntu-latest |
18 | 27 | steps: |
19 | | - - uses: actions/checkout@v4 |
20 | | - with: {fetch-depth: 0} |
21 | | - - uses: actions/setup-python@v4 |
22 | | - with: {python-version: '3.11'} |
23 | | - - run: pip install -r requirements.txt pyyaml |
24 | | - - name: check CITATION.cff & .zenodo.json |
25 | | - run: | |
26 | | - python <<EOF |
27 | | - import json, yaml |
28 | | - cff = yaml.safe_load(open("CITATION.cff")) |
29 | | - zen = json.load(open(".zenodo.json")) |
30 | | -
|
31 | | - assert cff['title'] == zen['title'] + " Book" |
32 | | - assert len(cff['authors']) - 1 == len(zen['creators']) |
33 | | - for cauth, zauth in zip(cff['authors'][:-1], zen['creators']): |
34 | | - assert zauth['name'] == f"{cauth['family-names']}, {cauth['given-names']}" |
35 | | - assert zauth.get('affiliation', "") == cauth.get('affiliation', "") |
36 | | - assert zauth.get('orcid', "") == cauth.get('orcid', "").rsplit("/", 1)[-1] |
37 | | - assert [{'name': cff['authors'][-1]['name'], 'type': "Other"}] == zen['contributors'] |
38 | | - assert cff['abstract'] == zen['description'] |
39 | | - assert cff['url'] == zen['related_identifiers'][0]['identifier'] |
40 | | - assert cff['keywords'] == zen['keywords'] |
41 | | - EOF |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + fetch-depth: 0 |
| 31 | + |
| 32 | + - uses: actions/setup-python@v4 |
| 33 | + with: |
| 34 | + python-version: '3.11' |
| 35 | + |
| 36 | + - run: pip install -r requirements.txt pyyaml |
| 37 | + |
| 38 | + - name: Check CITATION.cff & .zenodo.json |
| 39 | + run: | |
| 40 | + python <<EOF |
| 41 | + import json, yaml |
| 42 | + cff = yaml.safe_load(open("CITATION.cff")) |
| 43 | + zen = json.load(open(".zenodo.json")) |
| 44 | +
|
| 45 | + assert cff['title'] == zen['title'] + " Book" |
| 46 | + assert len(cff['authors']) - 1 == len(zen['creators']) |
| 47 | + for cauth, zauth in zip(cff['authors'][:-1], zen['creators']): |
| 48 | + assert zauth['name'] == f"{cauth['family-names']}, {cauth['given-names']}" |
| 49 | + assert zauth.get('affiliation', "") == cauth.get('affiliation', "") |
| 50 | + assert zauth.get('orcid', "") == cauth.get('orcid', "").rsplit("/", 1)[-1] |
| 51 | + assert [{'name': cff['authors'][-1]['name'], 'type': "Other"}] == zen['contributors'] |
| 52 | + assert cff['abstract'] == zen['description'] |
| 53 | + assert cff['url'] == zen['related_identifiers'][0]['identifier'] |
| 54 | + assert cff['keywords'] == zen['keywords'] |
| 55 | + EOF |
| 56 | +
|
42 | 57 | build: |
43 | 58 | runs-on: ubuntu-latest |
44 | 59 | steps: |
45 | | - - uses: actions/checkout@v4 |
46 | | - with: {fetch-depth: 0} |
47 | | - - uses: actions/setup-python@v4 |
48 | | - with: {python-version: '3.11'} |
49 | | - - id: pages |
50 | | - uses: actions/configure-pages@v3 |
51 | | - - run: pip install -r requirements.txt |
52 | | - - name: jupyter-book build |
53 | | - run: | |
54 | | - sudo apt update -qq |
55 | | - sudo apt install -qq ghostscript fonts-freefont-otf # https://stackoverflow.com/a/69012150 |
56 | | - sed -ri 's#^(\s*baseurl:).*#\1 ${{ steps.pages.outputs.base_url }}/'$SITE_PREFIX'#g' _config.yml |
57 | | - jupyter-book build --builder dirhtml --warningiserror --nitpick --keep-going . |
58 | | - # fix https://github.com/executablebooks/jupyter-book/issues/2066 |
59 | | - sed -ri 's#(.*link rel="canonical" href=".*)\.html(".*)#\1/\2#' _build/dirhtml/*/index.html |
60 | | - - uses: xu-cheng/latex-action@v3 |
61 | | - with: |
62 | | - working_directory: _build/latex |
63 | | - root_file: book.tex |
64 | | - args: -pdf -dvi- -ps- -file-line-error -f -interaction=nonstopmode |
65 | | - latexmk_use_xelatex: true |
66 | | - env: |
67 | | - XINDYOPTS: -L english -C utf8 -M sphinx.xdy |
68 | | - continue-on-error: true |
69 | | - - name: prepare _site pages |
70 | | - run: | |
71 | | - mkdir _site |
72 | | - mv _build/dirhtml _site/$SITE_PREFIX |
73 | | - sed "s#DESTINATION#${{ steps.pages.outputs.base_url }}/$SITE_PREFIX#g" .redirect-template.html > _site/index.html |
74 | | - - uses: actions/upload-pages-artifact@v2 |
| 60 | + - uses: actions/checkout@v4 |
| 61 | + with: |
| 62 | + fetch-depth: 0 |
| 63 | + |
| 64 | + - uses: actions/setup-python@v4 |
| 65 | + with: |
| 66 | + python-version: '3.11' |
| 67 | + |
| 68 | + - id: pages |
| 69 | + uses: actions/configure-pages@v3 |
| 70 | + |
| 71 | + - run: pip install -r requirements.txt |
| 72 | + |
| 73 | + - name: Jupyter Book Build |
| 74 | + run: | |
| 75 | + sudo apt update -qq |
| 76 | + sudo apt install -qq ghostscript fonts-freefont-otf # Install necessary packages |
| 77 | +
|
| 78 | + # Build the book in dirhtml format, treating warnings as errors |
| 79 | + jupyter-book build --builder dirhtml --warningiserror --nitpick --keep-going . |
| 80 | +
|
| 81 | + # Fix canonical links to remove .html suffix |
| 82 | + sed -ri 's#(.*link rel="canonical" href=".*)\.html(".*)#\1/\2#' _build/dirhtml/*/index.html |
| 83 | +
|
| 84 | + # Removed LaTeX build step to prevent 'book.tex' not found error |
| 85 | + |
| 86 | + - name: Prepare _site Pages |
| 87 | + run: | |
| 88 | + mkdir _site |
| 89 | + mv _build/dirhtml _site/$SITE_PREFIX |
| 90 | +
|
| 91 | + # Create a minimal root redirect (optional) |
| 92 | + echo '<!DOCTYPE html> |
| 93 | +<html> |
| 94 | + <head> |
| 95 | + <meta http-equiv="refresh" content="0; url=https://book.premai.io/state-of-open-source-ai/"> |
| 96 | + <title>Redirecting…</title> |
| 97 | + </head> |
| 98 | + <body> |
| 99 | + <p>Redirecting to <a href="https://book.premai.io/state-of-open-source-ai/">State of Open Source AI</a>.</p> |
| 100 | + </body> |
| 101 | +</html>' > _site/index.html |
| 102 | + |
| 103 | + - uses: actions/upload-pages-artifact@v2 |
| 104 | + |
75 | 105 | deploy: |
76 | 106 | if: github.ref == 'refs/heads/main' |
77 | 107 | environment: |
|
80 | 110 | runs-on: ubuntu-latest |
81 | 111 | needs: [check, build] |
82 | 112 | steps: |
83 | | - - id: deployment |
84 | | - uses: actions/deploy-pages@v2 |
| 113 | + - id: deployment |
| 114 | + uses: actions/deploy-pages@v2 |
0 commit comments