philips-software / post-to-medium-action

GitHub Action that allows you to create a new Medium post with Markdown or HTML.
MIT License
13 stars 2 forks source link

Ignore unknown frontmatter options #18

Closed Brend-Smits closed 1 year ago

Brend-Smits commented 2 years ago

The application currently errors when it finds an option in the front matter that it does not know. Instead of erroring, it should just ignore them.

doughgle commented 1 year ago

@Brend-Smits, @JeroenKnoops, Thank you for creating this action! :clap:

I'm experimenting with it and found this issue to be a constraint for working with Hugo frontmatter. In particular, it fails to parse the frontmatter fields date, publishdate, comments, and draft.

I wanna publish to Medium from markdown without editing the markdown source, and ideally, without editing the resulting Medium Draft.

Here's an example to reproduce the issue, as minimally and on demand (as I can think of)

Example Input file testmin.md:

---
title: "Hello World"
date: 2023-03-05T16:44:36+08:00
publishdate: 2023-03-20T04:44:36+08:00
tags: ['helloworld']
comments: true
draft: true
---
Hello world

Run container

$ docker run --workdir /github/workspace --rm \
  -v $(pwd):/github/workspace \
  -it \
  --entrypoint bash \
  ghcr.io/philips-software/post-to-medium-action:v0.4.2 --login
Unable to find image 'ghcr.io/philips-software/post-to-medium-action:v0.4.2' locally
v0.4.2: Pulling from philips-software/post-to-medium-action
461246efe0a7: Pull complete 
8cff39eab320: Pull complete 
98db8646b1e0: Pull complete 
7ce3048ca177: Pull complete 
ebc008972a5d: Pull complete 
074061fd6261: Pull complete 
dfb7c054f1dd: Pull complete 
c5aeeaa9e3d3: Pull complete 
c848854c81ed: Pull complete 
Digest: sha256:60fbf6c36bb6d65829eec4b916a0970c3ad04d5fc32acea23a8f92a4575528f8
Status: Downloaded newer image for ghcr.io/philips-software/post-to-medium-action:v0.4.2
root@64edc0afbda3:/github/workspace# 

Run /PostMediumGitHubAction.dll (requires valid Medium integration token). Update: drop the frontmatter option completely

root@a9361b98d274:/github/workspace# dotnet /PostMediumGitHubAction.dll "--integration-token" "<REDACTED>" "--title" "testmin.md" "--tags" "helloworld" "--publish-status" "draft" "--content-format" "markdown" "--file" "testmin.md" "--parse-frontmatter" "true"
Unhandled exception. YamlDotNet.Core.YamlException: (Line: 1, Col: 1, Idx: 0) - (Line: 1, Col: 1, Idx: 0): Exception during deserialization
root@a9361b98d274:/github/workspace# dotnet /PostMediumGitHubAction.dll "--integration-token" "<REDACTED>" "--title" "testmin.md" "--tags" "helloworld" "--publish-status" "draft" "--content-format" "markdown" "--file" "testmin.md" "--parse-frontmatter" "true"
Unhandled exception. YamlDotNet.Core.YamlException: (Line: 1, Col: 1, Idx: 0) - (Line: 1, Col: 1, Idx: 0): Exception during deserialization
 ---> System.Runtime.Serialization.SerializationException: Property 'date' not found on type 'PostMediumGitHubAction.Domain.Settings'.
   at YamlDotNet.Serialization.TypeInspectors.TypeInspectorSkeleton.GetProperty(Type type, Object container, String name, Boolean ignoreUnmatched)
   at YamlDotNet.Serialization.NodeDeserializers.ObjectNodeDeserializer.YamlDotNet.Serialization.INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func`3 nestedObjectDeserializer, Object& value)
   at YamlDotNet.Serialization.ValueDeserializers.NodeValueDeserializer.DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
   --- End of inner exception stack trace ---
   at YamlDotNet.Serialization.ValueDeserializers.NodeValueDeserializer.DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
   at YamlDotNet.Serialization.ValueDeserializers.AliasValueDeserializer.DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
   at YamlDotNet.Serialization.Deserializer.Deserialize(IParser parser, Type type)
   at YamlDotNet.Serialization.Deserializer.Deserialize[T](IParser parser)
   at YamlDotNet.Serialization.Deserializer.Deserialize[T](TextReader input)
   at YamlDotNet.Serialization.Deserializer.Deserialize[T](String input)
   at PostMediumGitHubAction.Services.MediumService.ParseFrontmatter(String content) in /Action/Services/MediumService.cs:line 105
   at PostMediumGitHubAction.Services.MediumService.SubmitNewContentAsync() in /Action/Services/MediumService.cs:line 55
   at PostMediumGitHubAction.Program.Main(String[] args) in /Action/Program.cs:line 17
   at PostMediumGitHubAction.Program.<Main>(String[] args)
Aborted (core dumped)

The same issue is reproducable on v0.4.1 and v0.4.2

Brend-Smits commented 1 year ago

Thanks for the detailed information @doughgle, I will try to resolve this as soon as possible (hopefully tomorrow)! Will keep you posted. Feel free to ping me in case this is not fixed in a timely manner.

doughgle commented 1 year ago

Great! Thanks @Brend-Smits ! 👍🏻

doughgle commented 1 year ago

Hi @Brend-Smits , were you able to reproduce the issue? Let me know if you need anything else from me

Brend-Smits commented 1 year ago

Hey @doughgle, This should soon be possible! I fixed it and opened a pull request in #28. I'm awaiting a review from my colleagues, then I will release a new version that you can use.

This issue will automatically be closed when the PR is merged. Thanks for the nudge!

doughgle commented 1 year ago

That's excellent! Thanks for the effort, @Brend-Smits ! 👏🏻

Brend-Smits commented 1 year ago

Hey @doughgle, You should now be able to use the latest version of the docker image, or the GitHub Action in your workflows. This should resolve the problem you are facing.

Let me know if any issues arise, happy to resolve them. We don't heavily use this action ourselves, so we rely on user feedback mostly.

doughgle commented 1 year ago

Thanks again @Brend-Smits ! Will aim to give it a try over the weekend...

doughgle commented 1 year ago

Hey @Brend-Smits,

Looks like image v0.5.0 didn't get into the action v0.5.0 tag so if you're using uses: philips-software/post-to-medium-action@v0.5.0, the behaviour is the same (fails on unknown date field in frontmatter).

It picks image v0.5.0 if you use uses: philips-software/post-to-medium-action@main though. No more error on date field.

One thing that stands out though, is that it doesn't parse title and tags fields from frontmatter even with "--parse-frontmatter" "true".

Instead it requires --tags and --title are specified

root@9cbfe5804d3d:/github/workspace# dotnet /PostMediumGitHubAction.dll "--integration-token" "<REDACTED>" "--publish-status" "draft" "--content-format" "markdown" "--file" "testmin.md" "--parse-frontmatter" "true"
PostMediumGitHubAction 1.0.0
Copyright (C) 2023 PostMediumGitHubAction

ERROR(S):
  Required option 'e, title' is missing.
  Required option 'a, tags' is missing.

... and that --title is non-empty:

root@9cbfe5804d3d:/github/workspace# dotnet /PostMediumGitHubAction.dll "--integration-token" "<READCTED>" "--publish-status" "draft" "--content-format" "markdown" "--file" "testmin.md" "--parse-frontmatter" "true" --title "" --tags ""
Unhandled exception. System.ArgumentNullException: The Title parameter was not set successfully. (Parameter 'Title')
   at PostMediumGitHubAction.Services.ConfigureService.CheckForValidSettings(Settings settingsToCheck) in /Action/Services/ConfigureService.cs:line 82
   at PostMediumGitHubAction.Services.MediumService.SubmitNewContentAsync() in /Action/Services/MediumService.cs:line 57
   at PostMediumGitHubAction.Program.Main(String[] args) in /Action/Program.cs:line 17
   at PostMediumGitHubAction.Program.<Main>(String[] args)
Aborted (core dumped)
Brend-Smits commented 1 year ago

Hey @Brend-Smits,

Looks like image v0.5.0 didn't get into the action v0.5.0 tag so if you're using uses: philips-software/post-to-medium-action@v0.5.0, the behaviour is the same (fails on unknown date field in frontmatter).

It picks image v0.5.0 if you use uses: philips-software/post-to-medium-action@main though. No more error on date field.

One thing that stands out though, is that it doesn't parse title and tags fields from frontmatter even with "--parse-frontmatter" "true".

Instead it requires --tags and --title are specified

root@9cbfe5804d3d:/github/workspace# dotnet /PostMediumGitHubAction.dll "--integration-token" "<REDACTED>" "--publish-status" "draft" "--content-format" "markdown" "--file" "testmin.md" "--parse-frontmatter" "true"
PostMediumGitHubAction 1.0.0
Copyright (C) 2023 PostMediumGitHubAction

ERROR(S):
  Required option 'e, title' is missing.
  Required option 'a, tags' is missing.

... and that --title is non-empty:

root@9cbfe5804d3d:/github/workspace# dotnet /PostMediumGitHubAction.dll "--integration-token" "<READCTED>" "--publish-status" "draft" "--content-format" "markdown" "--file" "testmin.md" "--parse-frontmatter" "true" --title "" --tags ""
Unhandled exception. System.ArgumentNullException: The Title parameter was not set successfully. (Parameter 'Title')
   at PostMediumGitHubAction.Services.ConfigureService.CheckForValidSettings(Settings settingsToCheck) in /Action/Services/ConfigureService.cs:line 82
   at PostMediumGitHubAction.Services.MediumService.SubmitNewContentAsync() in /Action/Services/MediumService.cs:line 57
   at PostMediumGitHubAction.Program.Main(String[] args) in /Action/Program.cs:line 17
   at PostMediumGitHubAction.Program.<Main>(String[] args)
Aborted (core dumped)

Hey there, sorry about that! This happened because of an issue with different naming conventions. Please try again on version v0.6.0

doughgle commented 1 year ago

It works great now! Thanks again @Brend-Smits !