-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
web: workflow for previewing the website (#256)
Only the prose, though, to get an idea of how things render. Time to write YAML...
- Loading branch information
Showing
12 changed files
with
176 additions
and
75 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
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,76 @@ | ||
name: PR Preview | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- reopened | ||
- synchronize | ||
- closed | ||
|
||
permissions: | ||
pull-requests: write | ||
|
||
jobs: | ||
pr-preview: | ||
runs-on: ubuntu-latest | ||
|
||
env: | ||
mailmap: ${{ secrets.MAILMAP }} | ||
|
||
steps: | ||
- name: Checkout ⬇️ | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 # we need the commit history for authors | ||
|
||
- name: Install Nix ❄️ | ||
uses: cachix/install-nix-action@v20 | ||
|
||
- name: Set up Cachix ♻️ | ||
uses: cachix/cachix-action@v12 | ||
with: | ||
name: 1lab | ||
skipPush: true | ||
|
||
- name: Build the Shakefile 🧰 | ||
run: | | ||
hash=$(nix-build -A shakefile --no-out-link) | ||
hash=${hash#/nix/store/} hash=${hash%%-*} | ||
echo "shake_version=$hash" >> "$GITHUB_ENV" | ||
- name: Cache _build ♻️ | ||
uses: actions/cache@v3 | ||
with: | ||
path: _build | ||
key: prose-4-${{ env.shake_version }}-${{ github.run_id }} | ||
restore-keys: prose-4-${{ env.shake_version }}- | ||
|
||
- name: Build the prose ✍️ | ||
run: | | ||
echo "$mailmap" > .mailmap | ||
nix-shell --arg interactive false --run "$build_command" | ||
env: | ||
NIX_BUILD_SHELL: bash | ||
build_command: | | ||
set -eu | ||
1lab-shake -j all --skip-agda -b "https://plt-amy.github.io/1lab-previews/pr-${{ github.event.number }}" | ||
eval "$installPhase" | ||
cp -rv _build/site pr-${{ github.event.number }} | ||
- name: Upload 📦 | ||
uses: dmnemec/copy_file_to_another_repo_action@main | ||
env: | ||
API_TOKEN_GITHUB: ${{ secrets.PREVIEW_TOKEN }} | ||
with: | ||
source_file: pr-${{ github.event.number }} | ||
destination_repo: 'plt-amy/1lab-previews' | ||
user_email: '[email protected]' | ||
user_name: 'plt-amy' | ||
commit_message: 'Preview of PR #${{ github.event.number }}' | ||
|
||
- name: Inform ℹ️ | ||
uses: marocchino/sticky-pull-request-comment@v2 | ||
with: | ||
message: | | ||
[Rendered preview](https://plt-amy.github.io/1lab-previews/pr-${{ github.event.number }}) |
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
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
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 |
---|---|---|
@@ -1,45 +1,82 @@ | ||
{-# LANGUAGE BlockArguments, ScopedTypeVariables, TupleSections #-} | ||
{-# LANGUAGE DeriveGeneric, TypeFamilies #-} | ||
{-# LANGUAGE DeriveGeneric, TypeFamilies, DerivingStrategies #-} | ||
|
||
-- | Global build options. | ||
module Shake.Options | ||
( Option(..) | ||
( Options(..), _1LabOptDescrs | ||
, defaultOptions | ||
, setOptions | ||
|
||
, getSkipTypes | ||
, getSkipAgda | ||
, getWatching | ||
, getBaseUrl | ||
) where | ||
|
||
import Development.Shake.Classes | ||
import Development.Shake | ||
|
||
import Data.Maybe | ||
|
||
import GHC.Generics (Generic) | ||
|
||
data Option | ||
= SkipTypes -- ^ Skip generating types when emitting HTML. | ||
| SkipAgda -- ^ Skip typechecking Agda, emitting the markdown directly. | ||
| Watching -- ^ Launch in watch mode. Prevents some build tasks running. | ||
import System.Console.GetOpt | ||
|
||
data Options = Options | ||
{ _optSkipTypes :: !Bool | ||
-- ^ Skip generating types when emitting HTML. | ||
, _optSkipAgda :: !Bool | ||
-- ^ Skip typechecking Agda, emitting the markdown directly. | ||
, _optWatching :: Maybe (Maybe String) | ||
-- ^ Launch in watch mode. Prevents some build tasks running. | ||
, _optBaseUrl :: String | ||
-- ^ Base URL for absolute paths | ||
} | ||
deriving (Eq, Show, Typeable, Generic) | ||
|
||
instance Hashable Option where | ||
instance Binary Option where | ||
instance NFData Option where | ||
instance Hashable Options | ||
instance Binary Options | ||
instance NFData Options | ||
|
||
defaultOptions :: Options | ||
defaultOptions = Options | ||
{ _optSkipTypes = False | ||
, _optSkipAgda = False | ||
, _optWatching = Nothing | ||
, _optBaseUrl = "https://1lab.dev" | ||
} | ||
|
||
type instance RuleResult Option = Bool | ||
data GetOptions = GetOptions deriving (Eq, Show, Typeable, Generic) | ||
|
||
instance Hashable GetOptions | ||
instance Binary GetOptions | ||
instance NFData GetOptions | ||
|
||
type instance RuleResult GetOptions = Options | ||
|
||
-- | Set which option flags are enabled. | ||
setOptions :: [Option] -> Rules () | ||
setOptions :: Options -> Rules () | ||
setOptions options = do | ||
_ <- addOracle (pure . getOption) | ||
_ <- addOracle $ \GetOptions -> pure options | ||
pure () | ||
where | ||
getOption SkipTypes = SkipTypes `elem` options | ||
|| SkipAgda `elem` options | ||
|| Watching `elem` options | ||
getOption SkipAgda = SkipAgda `elem` options | ||
getOption Watching = Watching `elem` options | ||
|
||
getSkipTypes, getSkipAgda, getWatching :: Action Bool | ||
getSkipTypes = askOracle SkipTypes | ||
getSkipAgda = askOracle SkipAgda | ||
getWatching = askOracle Watching | ||
getSkipTypes = _optSkipTypes <$> askOracle GetOptions | ||
getSkipAgda = _optSkipAgda <$> askOracle GetOptions | ||
getWatching = isJust . _optWatching <$> askOracle GetOptions | ||
|
||
getBaseUrl :: Action String | ||
getBaseUrl = _optBaseUrl <$> askOracle GetOptions | ||
|
||
_1LabOptDescrs :: [OptDescr (Options -> Options)] | ||
_1LabOptDescrs = | ||
[ Option "w" ["watch"] (OptArg (\s r -> r { _optWatching = Just s, _optSkipTypes = True }) "COMMAND") | ||
"Start 1lab-shake in watch mode. Starts a persistent process which runs a subset of build tasks for \ | ||
\interactive editing. Implies --skip-types.\nOptionally takes a command to run after the build has finished." | ||
, Option [] ["skip-types"] (NoArg (\r -> r { _optSkipTypes = True })) | ||
"Skip generating type tooltips when compiling Agda to HTML." | ||
, Option [] ["skip-agda"] (NoArg (\r -> r { _optSkipAgda = True, _optSkipTypes = True })) | ||
"Skip typechecking Agda. Markdown files are read from src/ directly." | ||
, Option "b" ["base-url"] (ReqArg (\s r -> r { _optBaseUrl = s }) "URL") | ||
"The base URL to use for absolute links. Should include the protocol." | ||
] |
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
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
Oops, something went wrong.