This action was started from this version of the template to generate a TypeScript GitHub action.
Example action:
name: Post blogs to Hashnode from latest commit
on:
push:
branches:
- main
paths:
- 'blog/**.md'
workflow_dispatch:
jobs:
update-posts:
runs-on: ubuntu-latest
steps:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 20
# This step is only necessary to test the action locally with act
- name: Install Git
id: install-git
run: npm i -g git
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2 # you must do this to get the last commit
- run: git checkout HEAD^
- name: Run script to post blogs to Hashnode
id: post-blogs
uses: nicolascalev/[email protected]
with:
HASHNODE_HOST: ${{ secrets.HASHNODE_HOST }}
HASHNODE_PAT: ${{ secrets.HASHNODE_PAT }}
Please notice that front matter is required, here's an example blog:
---
title:
This title is required because that's how the action will find your existing
blog in Hashnode
tags:
- When you create a blog, the limit of tags is 5
- When you update a blog you can add more
- That's a limitation of the Hashnode API not this action
---
Your content goes here
- You need to have the directory
./blog
at the root of your project or the action will fail. - The action uses only the
blog/**.md
files from the commit that triggered the action (the last commit). - When using
actions/checkout@v4
you must add the configuration I provided to get the files from the last commit. Otherwise GitHub creates a temporary branch with all the files. - Deleting a
.md
file won't delete your blog in Hashnode. - We find the blogs by title. If you change the title of a blog after it's creation. A new blog will be created, and you have to delete the old one manually.
- Sometimes the updates can take longer to show in your Hashnode blog. Try also opening a new tab.
- To set GitHub secrets go to
Settings > Secrets and variables > Actions > Repository Secrets > New repository secret
- Your Hashnode host is
[hashnode username].hashnode.dev
- You get your Hashnode access token here
After cloning the repository and installing the dependencies. It's easy to test the action locally.
- Copy
.vscode/launch.example.json
to.vscode/launch.json
and set the right environment variables. GITHUB_SHA
should be a commit that contains changes to a blog.- Now you can debug your action without pushing the code to GitHub or using act.
- Before pushing your code, always run
npm run all
to run tests locally, and check formatting errors. - Run
npm run format:write
to fix format errors automatically. - Create a pull request.