Require at least the default lang to exist before deploying to Pages

This commit is contained in:
object-Object 2023-08-28 23:39:55 -04:00
parent 03f702a477
commit 9edd7d8874
2 changed files with 40 additions and 2 deletions

View file

@ -126,12 +126,27 @@ jobs:
needs: generate needs: generate
steps: steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Download hexdoc artifact
uses: actions/download-artifact@v3
with:
name: hexdoc-build
- name: Download temporary Pages artifact - name: Download temporary Pages artifact
uses: actions/download-artifact@v3 uses: actions/download-artifact@v3
with: with:
name: github-pages-tmp name: github-pages-tmp
path: _site/ path: _site/
- name: Check default lang
run: $HEXDOC --check-default-lang _site
- name: Fix permissions - name: Fix permissions
run: | run: |
chmod -c -R +rX "_site/" | while read line; do chmod -c -R +rX "_site/" | while read line; do

View file

@ -42,6 +42,7 @@ class Args(HexdocModel):
output_dir: Path | None output_dir: Path | None
export_only: bool export_only: bool
list_langs: bool list_langs: bool
check_default_lang: Path | None
@classmethod @classmethod
def parse_args(cls, args: Sequence[str] | None = None) -> Self: def parse_args(cls, args: Sequence[str] | None = None) -> Self:
@ -56,12 +57,18 @@ class Args(HexdocModel):
group = parser.add_mutually_exclusive_group(required=True) group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("--output_dir", "-o", type=Path) group.add_argument("--output_dir", "-o", type=Path)
group.add_argument("--check-default-lang", type=Path)
group.add_argument("--export-only", action="store_true") group.add_argument("--export-only", action="store_true")
group.add_argument("--list-langs", action="store_true") group.add_argument("--list-langs", action="store_true")
return cls.model_validate(vars(parser.parse_args(args))) return cls.model_validate(vars(parser.parse_args(args)))
@field_validator("properties_file", "output_dir", mode="after") @field_validator(
"properties_file",
"output_dir",
"check_default_lang",
mode="after",
)
def _resolve_path(cls, value: Path | None): def _resolve_path(cls, value: Path | None):
# make paths absolute because we're cd'ing later # make paths absolute because we're cd'ing later
match value: match value:
@ -76,7 +83,13 @@ class Args(HexdocModel):
self.verbose = True self.verbose = True
# exactly one of these must be truthy (should be enforced by group above) # exactly one of these must be truthy (should be enforced by group above)
assert bool(self.output_dir) + self.export_only + self.list_langs == 1 assert (
bool(self.output_dir)
+ self.export_only
+ self.list_langs
+ bool(self.check_default_lang)
== 1
)
return self return self
@ -112,6 +125,16 @@ def main(args: Args | None = None) -> None:
props = Properties.load(args.properties_file) props = Properties.load(args.properties_file)
if args.check_default_lang:
dir_path = args.check_default_lang
for path in [
dir_path / "index.html",
dir_path / props.default_lang / "index.html",
]:
if not path.is_file():
raise FileNotFoundError(path)
return
# just list the languages and exit # just list the languages and exit
if args.list_langs: if args.list_langs:
with ModResourceLoader.load_all(props, export=False) as loader: with ModResourceLoader.load_all(props, export=False) as loader: