Skip to content

Commit a3ecbdc

Browse files
authored
Merge pull request #831 from carpentries/frog-slugcheck-1
Add slug check
2 parents 9fd6239 + cc0987e commit a3ecbdc

File tree

4 files changed

+66
-10
lines changed

4 files changed

+66
-10
lines changed

.github/workflows/website.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ jobs:
7979
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
8080
shell: Rscript {0}
8181

82-
8382
- name: Install system dependencies for R packages
8483
if: steps.check-rmd.outputs.count != 0
8584
run: |
@@ -98,6 +97,12 @@ jobs:
9897
ref: gh-pages
9998
path: gh-pages
10099

100+
- name: Validate workshop website
101+
# https://github.com/carpentries/styles/issues/551 is no longer relevant as styles shouldn't be used for
102+
# lessons but only workshop templates. So, always run the workshop checks now.
103+
run: make workshop-check
104+
if: always()
105+
101106
- name: Commit and Push
102107
if: ${{ github.event_name == 'push' && steps.check-rmd.outputs.count != 0 && github.ref != 'refs/heads/gh-pages'}}
103108
run: |
@@ -118,8 +123,3 @@ jobs:
118123
git push origin gh-pages
119124
# return
120125
cd ..
121-
122-
# waiting for https://github.com/carpentries/styles/issues/551
123-
# to be addressed
124-
# - run: make lesson-check-all
125-
# if: always()

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ create a workshop website.
5050
3. Select the owner for your new repository.
5151
(This will probably be you, but may instead be an organization you belong to.)
5252

53-
4. Choose a name for your workshop website repository.
54-
This name should have the form `YYYY-MM-DD-site`,
53+
4. Name your workshop website repository using the Carpentries slug format.
54+
The slug should have the form `YYYY-MM-DD-site`,
5555
e.g., `2016-12-01-oomza`,
56-
where `YYYY-MM-DD` is the start date of the workshop.
56+
where `YYYY-MM-DD` is the start date of the workshop and 'oomza' is an example site name.
5757
If your workshop is held online, then the respository name should have `-online` in the end.
58-
e.g., `2016-12-01-oomza-online`
58+
e.g., `2016-12-01-oomza-online`. Your website build will fail if the name of your
59+
repository does not match the valid slug format!
5960

6061
5. Make sure the repository is public, leave "Include all branches" unchecked, and click
6162
on "Create repository from template".

_extras/customization.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,25 @@ configure some site-wide variables and make the site function correctly:
3535
it will appear in the "jumbotron" (the gray box at the top of the page). This variable is also
3636
used for the title of the extra pages. The README contains [more information about extra pages](https://github.com/carpentries/workshop-template#creating-extra-pages).
3737

38+
### Slug Validation
39+
40+
For workshops teaching a core or mix and match curriculum, i.e.
41+
where `carpentry` is set to `swc`, `dc`, or `lc`, the website build
42+
will check that your repository name matches the Carpentries slug
43+
format - `YYYY-MM-DD-site[-online]`, e.g. `2024-05-07-oomza-online`.
44+
45+
**If your repository name does not match this format, the build will
46+
fail, and will direct you to rename your workshop website repository
47+
to a valid slug.** You will then need to commit a change to the repo
48+
to rebuild the site, e.g. adding a space or other inconsequential
49+
change to the `README.md`.
50+
51+
Workshop websites using `cp` or `incubator` will go through the same
52+
check, but the build will not fail if the repo name does not match
53+
the slug format. You will see a warning in the build output instead.
54+
55+
### Incubator lessons
56+
3857
For workshops teaching lessons in The Carpentries Incubator,
3958
i.e. where `carpentry` is set to `incubator`,
4059
you should uncomment the following three fields in

bin/workshop_check.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
HUMANTIME_PATTERN = r'((0?[1-9]|1[0-2]):[0-5]\d(am|pm)(-|to)(0?[1-9]|1[0-2]):[0-5]\d(am|pm))|((0?\d|1\d|2[0-3]):[0-5]\d(-|to)(0?\d|1\d|2[0-3]):[0-5]\d)'
1616
EVENTBRITE_PATTERN = r'\d{9,10}'
1717
URL_PATTERN = r'https?://.+'
18+
SLUG_PATTERN = r'\d{4}-\d{2}-\d{2}-[A-z0-9\-\_]+'
1819

1920
# Defaults.
2021
CARPENTRIES = ("dc", "swc", "lc", "cp")
@@ -400,6 +401,38 @@ def check_config(reporter, filename):
400401
carpentry)
401402

402403

404+
def check_slug(reporter, filename, repo_dir):
405+
config = load_yaml(filename)
406+
407+
repo_name = os.path.basename(os.path.realpath(repo_dir))
408+
409+
carpentry = config.get('carpentry', None)
410+
411+
slugfmt = "YYYY-MM-DD-site[-online]"
412+
if (repo_name != "workshop-template"):
413+
if carpentry in ('swc', 'dc', 'lc'):
414+
fail_msg = (
415+
'Website repository name `{0}` does not match the required slug format: `{1}`. '
416+
'Please rename your repository to a valid slug using the rename option in the "Settings" menu.'
417+
)
418+
419+
if not bool(re.match(SLUG_PATTERN, repo_name)):
420+
print(fail_msg.format(repo_name, slugfmt))
421+
sys.exit(1)
422+
423+
elif carpentry in ('cp', 'incubator'):
424+
warn_msg = (
425+
'Website repository name `{0}` does not match the suggested slug format: `{1}`. '
426+
'If teaching a workshop which you are collecting surveys for or are submitting into AMY, '
427+
'please rename your repository to a valid slug using the rename option in the "Settings" menu.'
428+
)
429+
430+
reporter.check(bool(re.match(SLUG_PATTERN, repo_name)),
431+
None,
432+
warn_msg,
433+
repo_name, slugfmt)
434+
435+
403436
def main():
404437
'''Run as the main program.'''
405438

@@ -413,6 +446,9 @@ def main():
413446

414447
reporter = Reporter()
415448
check_config(reporter, config_file)
449+
450+
check_slug(reporter, config_file, root_dir)
451+
416452
check_unwanted_files(root_dir, reporter)
417453
with open(index_file, encoding='utf-8') as reader:
418454
data = reader.read()

0 commit comments

Comments
 (0)