Skip to content

Commit

Permalink
Deploy website from GitHub actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpratt committed Jan 31, 2024
0 parents commit fa56417
Show file tree
Hide file tree
Showing 10 changed files with 331 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yaml]
indent_size = 2
132 changes: 132 additions & 0 deletions .github/workflows/build-website.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: Build website

on:
workflow_call:
workflow_dispatch:

jobs:
build-docs:
name: Build docs (${{ matrix.kind }})
runs-on: ubuntu-latest
strategy:
matrix:
kind: [internal, public]

steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: time-rs/time

- name: Cache cargo output
uses: Swatinem/rust-cache@v2

- name: Install toolchain
uses: dtolnay/rust-toolchain@nightly

- name: Generate documentation
run: cargo doc -p time --all-features ${{ matrix.kind == 'internal' && '--document-private-items' || '' }}
env:
RUSTDOCFLAGS: --cfg __time_03_docs ${{ matrix.kind == 'internal' && '--document-hidden-items' || '' }} -Zunstable-options --generate-link-to-definition

- name: Upload artifact
uses: actions/upload-artifact@v4
id: docs-upload
with:
name: ${{ matrix.kind }}-docs
path: target/doc/
retention-days: 1
if-no-files-found: error
compression-level: 9

build-book:
name: Build book
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: time-rs/book

- name: Check for typos
uses: crate-ci/typos@master

- name: Install mdbook
uses: taiki-e/install-action@mdbook

- name: Build diagrams
run: |
pip install -r diagrams/requirements.txt
mkdir src/diagrams
python diagrams/diagrams.py
- name: Build book
run: mdbook build

- name: Upload artifact
uses: actions/upload-artifact@v4
id: book-upload
with:
name: book
path: book/
retention-days: 1
if-no-files-found: error
compression-level: 9

deploy:
name: Deploy
runs-on: ubuntu-latest
needs: [build-docs, build-book]
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: |
website
- name: Download internal docs
uses: actions/download-artifact@v4
with:
name: internal-docs
path: website/internal-api

- name: Download public docs
uses: actions/download-artifact@v4
with:
name: public-docs
path: website/api

- name: Download book
uses: actions/download-artifact@v4
with:
name: book
path: website/book

- name: Upload website
uses: actions/upload-pages-artifact@v3
with:
path: website

- name: Deploy
id: deployment
uses: actions/deploy-pages@v4

- name: Delete artifacts
uses: geekyeggo/delete-artifact@v4
with:
name: |
internal-docs
public-docs
book
github-pages
failOnError: false
if: always()
continue-on-error: true
28 changes: 28 additions & 0 deletions .github/workflows/trigger-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Deploy

env:
REPO: time-rs/time-rs.github.io
WORKFLOW: build-website.yaml
GH_TOKEN: ${{ secrets.WEBSITE_PUBLISHING }}

on:
workflow_call:
workflow_dispatch:

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
permissions:
actions: write

steps:
- name: Trigger deploy
id: trigger
run: |
gh workflow run --repo ${{ env.REPO }} ${{ env.WORKFLOW }}
sleep 3 # Let the run be created
echo "RUN_ID=$(gh run list --repo ${{ env.REPO }} --json databaseId --workflow ${{ env.WORKFLOW }} --limit 1 | jq -r '.[0].databaseId')" >> "$GITHUB_OUTPUT"
- name: Wait for deployment
run: gh run watch --repo ${{ env.REPO }} ${{ steps.trigger.outputs.RUN_ID }} --interval 1 --exit-status
1 change: 1 addition & 0 deletions website/icons/book.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions website/icons/code.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions website/icons/cogs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions website/icons/github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions website/icons/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions website/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang='en'>

<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>time-rs</title>
<link rel='stylesheet' href='styles.css'>
</head>

<body>

<header>
<div class='branding'>
<img src='icons/logo.svg'>
time-rs
</div>

<div class='right-box'>
<a href='https://github.com/time-rs/time'>
<img src='icons/github.svg' alt='GitHub'>
</a>
</div>
</header>

<main>
<a href='book'>
<img src='icons/book.svg'>
<div class='hover-underline'>Book</div>
</a>
<a href='api/time'>
<img src='icons/code.svg'>
<div class='hover-underline'>Public API</div>
</a>
<a href='internal-api/time'>
<img src='icons/cogs.svg'>
<div class='hover-underline'>Internal API</div>
</a>
</main>

</body>

</html>
111 changes: 111 additions & 0 deletions website/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}

:root {
--foreground: #000;
--background: #eee;

color: var(--foreground);
background-color: var(--background);

height: 100%;
width: 100%;
padding: 1.5rem;
}

@media screen and (prefers-color-scheme: dark) {
:root {
--foreground: #fff;
--background: #000;
}

img:not(.no-invert) {
filter: invert(1);
}
}

body {
height: 100%;
width: 100%;
font-size: 2rem;
font-family: monospace;
text-align: center;

display: grid;
grid-template: auto / repeat(3, 1fr);
grid-auto-rows: 1fr;
gap: 2rem;
}

header,
main {
display: contents;
}

.branding {
grid-row: 1;
grid-column: 1 / -1;
}

a {
color: unset;
text-decoration: none;
transition: 150ms;
}

a .hover-underline::after {
content: '';
display: block;
width: 0;
margin: 0 auto;
border-bottom: 1px solid var(--foreground);
transition: width 200ms;
}

a:hover .hover-underline::after {
width: 100%;
transition: width 200ms;
}

header img {
height: 2.5rem;
vertical-align: text-bottom;
}

header .right-box {
grid-row: 1;
grid-column: -2 / -1;
text-align: right;
font-size: 0;
}

header .right-box a:not(:first-of-type) {
margin-left: 2rem;
}

main a {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 1rem;
}

main img {
max-height: 8rem;
max-width: min(8rem, 25vw);
}

@media (max-width: 800px) {
body {
grid-template: auto auto / 1fr;
}

header .right-box {
grid-row: 2;
text-align: center;
}
}

0 comments on commit fa56417

Please sign in to comment.