Skip to content

Commit

Permalink
Merge branch 'main' into FireFrozen94-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
ctmbl committed Apr 12, 2024
2 parents dc6d12f + 9f1ba53 commit c6f11cd
Show file tree
Hide file tree
Showing 22 changed files with 886 additions and 47 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
# Build the static website with the provided docker-compose rules
- name: 🛠️ Build with HUGO
run: |
docker compose up builder
docker compose up builder --exit-code-from builder
# Upload build artifacts for deployment or download
- name: 🚀 Upload Artifacts
Expand All @@ -39,10 +39,10 @@ jobs:
path: ./build/blog

# Deployment job: heavily inspired from https://swharden.com/blog/2022-03-20-github-actions-hugo/
# /!\ only triggers on push events
# /!\ only triggers on push events and manually triggered
deploy:
needs: [build]
if: ${{ github.event_name == 'push' }}
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
steps:
- name: 🛠️ Setup build directory
Expand Down Expand Up @@ -73,8 +73,10 @@ jobs:
rsync --archive --stats --verbose --delete ./build/blog/* ${{ secrets.CI_USER_NAME }}@iscsc.fr:${{ secrets.STATIC_WEBSITE_PATH}}
# Finally notify of the new article (if any) on the iScsc discord server
# action jitterbit/get-changed-files@v1 doesn't support 'workflow_dispatch' events: https://github.com/jitterbit/get-changed-files/issues/38
notify:
needs: [deploy]
if: ${{ github.event_name != 'workflow_dispatch' }}
runs-on: ubuntu-latest
steps:
# Checkout repo, no need to checkout submodule
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Pytest

on:
# Runs on pull requests to check that the website is building without errors
pull_request:

# Only run if the push to main
push:
branches:
- main

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
# Build job
build:
runs-on: ubuntu-latest
steps:
# Checkout repo
- name: 🛒 Checkout
uses: actions/checkout@v3

# Install pytest
- name: 🛠️ Install pytest
run: |
python3 -m pip install pytest pytest-mock
# Run tests
- name: 🚀 Run pytest
run: |
cd ./scripts/
pytest
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# env files
.env.prod
.env.dev

Expand All @@ -10,3 +11,6 @@ certbot/*
# hugo build
src/public
build/blog/*

# python
**/__pycache__
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "src/themes/poison"]
path = src/themes/poison
url = https://github.com/lukeorth/poison.git
url = https://github.com/ctmbl/poison.git
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ version: "3.8"

services:
builder:
image: klakegg/hugo:0.111.3
command: --verbose --baseUrl="https://iscsc.fr" --buildFuture
image: floryn90/hugo:0.123.7
command: --logLevel info --baseURL="https://iscsc.fr" --buildFuture
environment:
- HUGO_DESTINATION=/build/blog
# For maximum backward compatibility with Hugo modules:
Expand Down
60 changes: 40 additions & 20 deletions scripts/new_article.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
import os
import sys
import re
import requests
import yaml

for file_path in sys.argv[1:]:
# Check that this is an article file
if re.match("^src/content/posts/.+\.md$", file_path):
# Read YAML Header
with open(file_path, "r") as f:
raw_txt = f.read()
data = yaml.safe_load(raw_txt.split("---")[1])

# Get rid of python objects, only keep basic types
for key in data:
if type(data[key]) not in [int, str, float, bool]:
data[key] = str(data[key])

# Add URL info
file_name = file_path.split("/")[-1][:-3]
data["url"] = f"https://iscsc.fr/posts/{file_name}"

# Finally send Data
requests.post("http://iscsc.fr:8001/new-blog", json=data)
print(file_path, file_name, data)
ARTICLE_FILE_BASE_PATH = "src/content/posts/"

def main(files_paths):
for file_path in files_paths:
# Check that this is an article file
if re.match(f"^{ARTICLE_FILE_BASE_PATH}.+\.md$", file_path):
## Read YAML Header
with open(file_path, "r") as f:
raw_txt = f.read()
data = yaml.safe_load(raw_txt.split("---")[1])

## Get rid of python objects, only keep basic types
for key in data:
if type(data[key]) not in [int, str, float, bool]:
data[key] = str(data[key])

# we have to deal with both possibilities of new article:
# - an article as a .md file which URL is the name
# - a leaf bundle article (https://gohugo.io/content-management/page-bundles/#leaf-bundles):
# it's an article which name is the folder's name and body is in a index.md in this directory
dirname, basename = os.path.split(file_path)
if basename == "index.md":
# leaf bundle: name is directory name
file_name = os.path.basename(dirname)
else:
# direct article file: name is file name
file_name = basename[:-3] # get rid of the `.md`

## Add URL info:
data["url"] = f"https://iscsc.fr/posts/{file_name}"

## Finally send Data
req = requests.post("http://iscsc.fr:8001/new-blog", json=data)
print(file_path, file_name, data)
assert(req.status_code == 200)


if __name__ == "__main__":
main(sys.argv[1:])
68 changes: 68 additions & 0 deletions scripts/test_new_article.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import pytest

import new_article

### DISCLAIMER:
# Whereas other extensions are allowed by HUGO:
# "The extension can be .html, .json or any valid MIME type"
# We only accept Markdown articles and so only parse these
###


@pytest.fixture
def mock_requests_post(mocker):
mock_post = mocker.MagicMock()
fake_response = mocker.Mock()

fake_response.status_code = 200
mock_post.return_value = fake_response

mocker.patch("requests.post", mock_post)
mocker.patch("new_article.ARTICLE_FILE_BASE_PATH", "test_resources/")

yield mock_post


def test_new_article_file(mock_requests_post):
new_article.main(["test_resources/article_1.md"])

mock_requests_post.assert_called_once_with(
'http://iscsc.fr:8001/new-blog',
json={
'title': 'article title',
'summary': 'article summary',
'date': '2024-02-19 10:52:09+01:00',
'lastUpdate': '2024-02-19 10:52:09+01:00',
'tags': "['some', 'tags']",
'author': 'ctmbl',
'draft': False,
'url': 'https://iscsc.fr/posts/article_1'
}
)

def test_new_leaf_bundle_article(mock_requests_post):
new_article.main(["test_resources/leaf_bundle/index.md"])

mock_requests_post.assert_called_once_with(
'http://iscsc.fr:8001/new-blog',
json={
'title': 'leaf bundle title',
'summary': 'leaf bundle summary',
'date': '2024-02-19 10:52:09+01:00',
'lastUpdate': '2024-02-19 10:52:09+01:00',
'tags': "['leaf', 'bundle']",
'author': 'ctmbl',
'draft': False,
'url': 'https://iscsc.fr/posts/leaf_bundle'
}
)

def test_new_branch_bundle():
# not yet implemented
# https://gohugo.io/content-management/page-bundles/#branch-bundles
pass

def test_headless_bundle():
# not yet implemented
# https://gohugo.io/content-management/page-bundles/#headless-bundle
pass
9 changes: 9 additions & 0 deletions scripts/test_resources/article_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: "article title"
summary: "article summary"
date: 2024-02-19T10:52:09+01:00
lastUpdate: 2024-02-19T10:52:09+01:00
tags: ["some","tags"]
author: ctmbl
draft: false
---
9 changes: 9 additions & 0 deletions scripts/test_resources/leaf_bundle/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: "leaf bundle title"
summary: "leaf bundle summary"
date: 2024-02-19T10:52:09+01:00
lastUpdate: 2024-02-19T10:52:09+01:00
tags: ["leaf","bundle"]
author: ctmbl
draft: false
---
6 changes: 0 additions & 6 deletions src/archetypes/default.md

This file was deleted.

2 changes: 2 additions & 0 deletions src/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enableEmoji = true
# copy paste from https://themes.gohugo.io/themes/poison/#example-config :
paginate = 10
pluralizelisttitles = false # removes the automatically appended "s" on sidebar entries
capitalizelisttitles = false # respect list title case; ex with author: ctmbl stays ctmbl not Ctmbl

# NOTE: If using Disqus as commenting engine, uncomment and configure this line
# disqusShortname = "yourDisqusShortname"
Expand Down Expand Up @@ -103,4 +104,5 @@ pluralizelisttitles = false # removes the automatically appended "s" on sideba
[taxonomies]
series = 'series'
tags = 'tags'
author = 'author'

Loading

0 comments on commit c6f11cd

Please sign in to comment.