Skip to content

Commit

Permalink
Merge pull request #831 from carpentries/frog-slugcheck-1
Browse files Browse the repository at this point in the history
Add slug check
  • Loading branch information
froggleston authored Jul 10, 2024
2 parents 9fd6239 + cc0987e commit a3ecbdc
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 10 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ jobs:
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}


- name: Install system dependencies for R packages
if: steps.check-rmd.outputs.count != 0
run: |
Expand All @@ -98,6 +97,12 @@ jobs:
ref: gh-pages
path: gh-pages

- name: Validate workshop website
# https://github.com/carpentries/styles/issues/551 is no longer relevant as styles shouldn't be used for
# lessons but only workshop templates. So, always run the workshop checks now.
run: make workshop-check
if: always()

- name: Commit and Push
if: ${{ github.event_name == 'push' && steps.check-rmd.outputs.count != 0 && github.ref != 'refs/heads/gh-pages'}}
run: |
Expand All @@ -118,8 +123,3 @@ jobs:
git push origin gh-pages
# return
cd ..
# waiting for https://github.com/carpentries/styles/issues/551
# to be addressed
# - run: make lesson-check-all
# if: always()
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ create a workshop website.
3. Select the owner for your new repository.
(This will probably be you, but may instead be an organization you belong to.)

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

5. Make sure the repository is public, leave "Include all branches" unchecked, and click
on "Create repository from template".
Expand Down
19 changes: 19 additions & 0 deletions _extras/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,25 @@ configure some site-wide variables and make the site function correctly:
it will appear in the "jumbotron" (the gray box at the top of the page). This variable is also
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).

### Slug Validation

For workshops teaching a core or mix and match curriculum, i.e.
where `carpentry` is set to `swc`, `dc`, or `lc`, the website build
will check that your repository name matches the Carpentries slug
format - `YYYY-MM-DD-site[-online]`, e.g. `2024-05-07-oomza-online`.

**If your repository name does not match this format, the build will
fail, and will direct you to rename your workshop website repository
to a valid slug.** You will then need to commit a change to the repo
to rebuild the site, e.g. adding a space or other inconsequential
change to the `README.md`.

Workshop websites using `cp` or `incubator` will go through the same
check, but the build will not fail if the repo name does not match
the slug format. You will see a warning in the build output instead.

### Incubator lessons

For workshops teaching lessons in The Carpentries Incubator,
i.e. where `carpentry` is set to `incubator`,
you should uncomment the following three fields in
Expand Down
36 changes: 36 additions & 0 deletions bin/workshop_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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)'
EVENTBRITE_PATTERN = r'\d{9,10}'
URL_PATTERN = r'https?://.+'
SLUG_PATTERN = r'\d{4}-\d{2}-\d{2}-[A-z0-9\-\_]+'

# Defaults.
CARPENTRIES = ("dc", "swc", "lc", "cp")
Expand Down Expand Up @@ -400,6 +401,38 @@ def check_config(reporter, filename):
carpentry)


def check_slug(reporter, filename, repo_dir):
config = load_yaml(filename)

repo_name = os.path.basename(os.path.realpath(repo_dir))

carpentry = config.get('carpentry', None)

slugfmt = "YYYY-MM-DD-site[-online]"
if (repo_name != "workshop-template"):
if carpentry in ('swc', 'dc', 'lc'):
fail_msg = (
'Website repository name `{0}` does not match the required slug format: `{1}`. '
'Please rename your repository to a valid slug using the rename option in the "Settings" menu.'
)

if not bool(re.match(SLUG_PATTERN, repo_name)):
print(fail_msg.format(repo_name, slugfmt))
sys.exit(1)

elif carpentry in ('cp', 'incubator'):
warn_msg = (
'Website repository name `{0}` does not match the suggested slug format: `{1}`. '
'If teaching a workshop which you are collecting surveys for or are submitting into AMY, '
'please rename your repository to a valid slug using the rename option in the "Settings" menu.'
)

reporter.check(bool(re.match(SLUG_PATTERN, repo_name)),
None,
warn_msg,
repo_name, slugfmt)


def main():
'''Run as the main program.'''

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

reporter = Reporter()
check_config(reporter, config_file)

check_slug(reporter, config_file, root_dir)

check_unwanted_files(root_dir, reporter)
with open(index_file, encoding='utf-8') as reader:
data = reader.read()
Expand Down

0 comments on commit a3ecbdc

Please sign in to comment.