Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Word Count Log File GitHub Action #22

Merged
merged 11 commits into from Sep 24, 2020
Merged

feat: Word Count Log File GitHub Action #22

merged 11 commits into from Sep 24, 2020

Conversation

mcmxcdev
Copy link

@mcmxcdev mcmxcdev commented Sep 23, 2020

Phew, this was quite a lot of work, but fun!

I hope the implementation is how you would imagine it ;)

The logfile.json displays all blog posts with initial words
As soon as there is a diff because of rewriting files, you can see a ISO timestamp with the diff to the previous number of words and now current words.

To try it out locally:

  • clear content of logfile.json, just leave it an empty object
  • run node wordCount.js
  • expect initial filling of all markdown files into logfile.json
  • add or delete some markdown file content
  • run node wordCount.js
  • expect timestamp with diff and new word count in object key with name of blog post

I will implement the GitHub action when you say this is how you want it! Should just be a matter of running node wordCount.js on git push.

Closes #21.


IssueHunt Summary

Referenced issues

This pull request has been submitted to:


- add package.json to be able to use external dependencies
- add glob and reading-time for calculating word count
- add wordCount.js for iterating over all markdown files and displaying diff changes between each file edit
- add node_modules to .gitignore
- add logfile.json example

Signed-off-by: mhatvan <markus_hatvan@aon.at>
@singularityhacker
Copy link
Owner

You are the man! I'm not able to run locally for some reason. Getting the following error:

BKSQ-XL0J-MAC:content conderj$ node wordCount.js

/Users/conderj/content/wordCount.js:48

      const wordCountExisting = currentWords ?? existingFileName.initialWords;

SyntaxError: Unexpected token '?'

    at wrapSafe (internal/modules/cjs/loader.js:1053:16)

    at Module._compile (internal/modules/cjs/loader.js:1101:27)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)

    at Module.load (internal/modules/cjs/loader.js:985:32)

    at Function.Module._load (internal/modules/cjs/loader.js:878:14)

    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)

    at internal/main/run_main_module.js:17:47

@singularityhacker
Copy link
Owner

I can still merge the pull request if it helps you debug/move forward. As long as it works in the action, I can always figure out what's wrong on local later.

@mcmxcdev
Copy link
Author

mcmxcdev commented Sep 24, 2020

Sorry, my bad.
The issue is that you probably are not using node 14, am I right?

The ?? operator is quite new, replace it on your machine with || for now and you will be able to run it. There is an edge case for markdown files without any words where it doesn't work, so I will find a fix in the meantime!

No need for merging yet, I will work on the action file next.

mhatvan and others added 10 commits September 24, 2020 10:09
- updated GitHub actions.yml

Signed-off-by: mhatvan <markus_hatvan@aon.at>
- change rewriting logfile with JSON.stringify to keep formatting

Signed-off-by: mhatvan <markus_hatvan@aon.at>
…tvan/Content into 21-word-count-log-file-github-action
- remove paragraph in testfile.md to inspect changes on diff
- change npm i to npm ci for faster install with frozen lockfile

Signed-off-by: mhatvan <markus_hatvan@aon.at>
Signed-off-by: mhatvan <markus_hatvan@aon.at>
@mcmxcdev
Copy link
Author

mcmxcdev commented Sep 24, 2020

I have good news!

I updated the GitHub action file and it works perfectly:

  • it now uses Node v10 (oldest version that is still supported)
  • installs dependencies
  • runs node wordCount.js and then
  • adds, commit and pushes the changes to the logfile.json

You can go through the commit history of this PR to see what exactly is happening.

If you ever need GitHub actions more often, you can use this helpful library to run them locally: https://github.com/nektos/act

Currently, the GitHub action is triggered on a push in any branch. I can specify this to be master only.
It depends on how often you want to see the changes, and if you work with branches a lot or mainly push to master.

When you decide this is the way you want it, I would:

  • remove testfile.md
  • change back logfile.json to be empty object, so that it gets initialized on push
  • (optional) change actions to trigger for master only
  • squash merge into master when it is ready to avoid unnecessary commits that were necessary to test

And BIG thanks for your GitHub Sponsors support!! 🎉
Just hit me up whenever you need some work done.

@singularityhacker singularityhacker merged commit 0b43e03 into singularityhacker:master Sep 24, 2020
@singularityhacker
Copy link
Owner

THIS is a thing of beauty! I love the way you record the log as a json file too. Opens the door to build a dashboard using Netlify. Thank you so much for the time you spent on this. We have a lot of similar interests (jamstack, svelte, IF, EDM, crypto, etc) so I'm honored to be your first sponsor.

@mcmxcdev
Copy link
Author

mcmxcdev commented Sep 24, 2020

I am glad you like it!
Yeah, using a JSON file instead of a simple text file enables you to do a lot of stuff with the data and you have a super nice diff log that is displaying step by step. I also made sure all the variable names make sense, so you can do easy changes.

Haha, cool that you are also interested in all of these things 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Word Count Log File GitHub Action
2 participants