From d772f33e329e9593275009199695301c0039a1b0 Mon Sep 17 00:00:00 2001 From: Remo Senekowitsch Date: Wed, 16 Apr 2025 19:49:30 +0200 Subject: [PATCH] Add check against date placeholders The date of publication often has to be adjusted at the last minute. This can easily be forgotten. This commit introduces a new workflow: Blog authors keep a placeholder as the date (9999/12/99) until shortly before publication. Setting the date is aided with automation. Lastly, A check triggered by the merge queue event is used to block PRs from being merged where the placeholder hasn't been replaced yet. --- .github/workflows/merge_queue.yml | 61 +++++++++++++++++++++++++++++++ README.md | 7 +++- front_matter/src/lib.rs | 43 ++++++++++++++++++++++ 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/merge_queue.yml diff --git a/.github/workflows/merge_queue.yml b/.github/workflows/merge_queue.yml new file mode 100644 index 000000000..cedca9cb7 --- /dev/null +++ b/.github/workflows/merge_queue.yml @@ -0,0 +1,61 @@ +name: CI +on: + push: + branches: + - master + pull_request: + +env: + # renovate: datasource=github-tags depName=rust lookupName=rust-lang/rust + RUST_VERSION: 1.86.0 + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + + - run: rustup override set ${{ env.RUST_VERSION }} + - run: rustup component add clippy + - run: rustup component add rustfmt + - uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8 + + - run: cargo clippy --workspace -- -D warnings + - run: cargo fmt --check --all + - run: cargo test --package front_matter + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + + - run: rustup override set ${{ env.RUST_VERSION }} + - uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8 + + - name: Install Zola + run: cargo install --locked --git https://github.com/senekor/zola --rev 620bf3c46a39b41db30b1e91756a995bbff84d3a + - run: zola build + - run: cp CNAME ./public/ + - run: touch public/.nojekyll + + - uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1 + with: + path: public + + deploy: + if: ${{ github.ref == 'refs/heads/master' }} + + needs: build + + permissions: + pages: write + id-token: write + + runs-on: ubuntu-latest + steps: + - id: deployment + uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5 + + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} diff --git a/README.md b/README.md index 81e5f2fb1..ff8a5d68b 100644 --- a/README.md +++ b/README.md @@ -33,10 +33,15 @@ You can store your main blog post in `content//index.md`. Images go into the same directory: `content//my_image.png`. Now you can reference that image with a simple relative path: `![alt text](my_image.png)`. +A post's date of publication is embedded in the `path` key of the front matter. +Keep the placeholder (`9999/12/99`) until the post is about to be merged. +You can easily do so by adding a comment containing the string `publish=today` on the PR. +Don't worry, there's a merge queue check to make sure you don't forget. + Here is an example of the front matter format: ```md +++ -path = "2015/03/15/some-slug" +path = "9999/12/99/some-slug" title = "Title of the blog post" authors = ["Blog post author (or on behalf of which team)"] description = "(optional)" diff --git a/front_matter/src/lib.rs b/front_matter/src/lib.rs index 9445d0562..a9f63b5ce 100644 --- a/front_matter/src/lib.rs +++ b/front_matter/src/lib.rs @@ -212,4 +212,47 @@ The post {post} has abnormal front matter. }; } } + + /// This test is run by the merge queue check to make sure a blog post + /// isn't merged before its date is set. The date of a blog post is usually + /// a placeholder (path = "9999/12/99/...") until shortly before it's + /// published. Setting the date can be done manually or by commenting + /// "publish=today" on the PR. + #[test] + #[ignore] + fn date_is_set() { + let repo_root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(".."); + + let posts = fs::read_dir(repo_root.join("content")) + .unwrap() + .chain(fs::read_dir(repo_root.join("content/inside-rust")).unwrap()) + .map(|p| p.unwrap().path()) + .filter(|p| p.is_file() && p.file_name() != Some("_index.md".as_ref())); + + for post in posts { + let slug = post.file_stem().unwrap().to_str().unwrap(); + + let content = fs::read_to_string(&post).unwrap(); + let (front_matter, _) = parse(&content).unwrap(); + + if front_matter.path.starts_with("9999/12/99/") { + panic!( + " +The post {slug} has a placeholder publication date. + + ┌──────────────────────────────────────────────────────────────────────────┐ + │ │ + │ You can set the publication date automatically by commenting │ + │ │ + │ publish=today │ + │ │ + │ on the pull request of the post. │ + │ (You can also edit the 'path' key in the front matter directly.) │ + │ │ + └──────────────────────────────────────────────────────────────────────────┘ + ", + ); + } + } + } }