Logo

dev-resources.site

for different kinds of informations.

How to upload Markdown files to Dev.to from GitHub

Published at
1/15/2025
Categories
github
actions
devto
automation
Author
alexantartico
Categories
4 categories in total
github
open
actions
open
devto
open
automation
open
Author
13 person written this
alexantartico
open
How to upload Markdown files to Dev.to from GitHub

How to upload Markdown files to Dev.to from GitHub

his is a test post to show how to upload Markdown files to Dev.to.

You can do this with:

  • GitHub actions
  • Dev.to API Token
  • A custom GitHub action
  • A simple python script

I am assuming you have a general knowledge with GitHub actions and Python scripting, but you can achieve this with a superficial knowledge. To know more about it, you can check the GitHub documentation.

GitHub action to upload Markdown file

You can use GitHub actions to automate the process of uploading Markdown files to Dev.to. Using this action will make your life easier as every time you push a new commit to your repository, the markdown document will be pushed as well. There are already several actions available that can help you with this task or you can create your own action, but why reinvent the wheel?

I did some quick research and initially decided to use this Publish to dev.to GitHub action. It's simple to use and gets the job done. Or so I thought, after 2 failed repositories and a bunch of attempts I falled back to the conventional curl POST method. To be fair, is probably due to my lack of knowledge in GitHub actions, but I will try to use it again in the future.

First, fetch your DEV.TO API key. For this, log in to your DEV.TO account and go to settings/extensions, scroll all the way to the bottom and in you will see a section Named "DEV Community API Keys". Name your project and click on "Generate API Key". Copy this key and save it in your GitHub repository secrets.

Dev.to API Key

To save the key as a secret. go to your repository settings, click on secrets, and add a new secret with the name DEVTO_TOKEN and paste the key you copied from DEV.TO.'

Repository Settings

Add Secret

In your repository, create a new file called .github/workflows/devto_publish.yml and add the following code that you can find here.

name: Publish to Dev.to

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  publish:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout repository
      uses: actions/checkout@v2

    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: '3.10.13'

    - name: Upgrade pip and Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install pyyaml requests

    - name: Convert md to Dev.to format
      run: |
        python publish_script.py ./posts/main.md > formatted_article.json

    - name: Publish to Dev.to
      env:
        DEVTO_API_KEY: ${{ secrets.DEVTO_TOKEN }}
      run: |
        curl -X POST "https://dev.to/api/articles" \
        -H "api-key: $DEVTO_TOKEN" \
        -H "Content-Type: application/json" \
        -d @formatted_article.json
Enter fullscreen mode Exit fullscreen mode

So far, you have:

  • Fetched your DEV.TO API key
  • Saved it as a secret in your GitHub repository
  • Created a new file in your repository .github/workflows/devto_publish.yml
  • Added the code above to the repository

We now have to write the python script that will convert the markdown file to the DEV.TO format. You can find the script here.

** I will update what the script does later ** as for now I was only testing the ability to post a markdown file to DEV.TO. Right now, I am just glad that I was able to do it.

To finalize, commit and push the changes to your repository, the action will run automatically and if everything is set up correctly; you will see your markdown file uploaded to DEV.TO.

Cheers and happy coding!

Eduardo Mendoza

github Article's
30 articles in total
Favicon
CΓ³mo gestionar tus proyectos de software con Github
Favicon
How to upload Markdown files to Dev.to from GitHub
Favicon
Implantando um aplicativo Angular com DigitalOcean e GitHub de forma gratuita
Favicon
Survival Manual: How to Create and Manage a Project in Git
Favicon
Top 50 Websites a Backend Developer Must Know πŸ–₯οΈπŸ”§πŸš€
Favicon
Unlocking the Power of GitHub Copilot: Your AI Pair Programmer
Favicon
Top 10 Trending GitHub Repositories, Nov 24 2024
Favicon
Improving Port Management Speed: Why I Created `port-client` to Replace `npx kill-port`
Favicon
Unlock Your Coding Potential with the GitHub Copilot Global Bootcamp!
Favicon
Publish Private Nuget Packages on Github
Favicon
Git Merge VS Git Rebase: Which One Should YOU Use?
Favicon
Static sites FTW
Favicon
Hood Ball β€” Multiplayer web-based game
Favicon
GitHub Makeover: Create a Profile README That Stands Out and Connects! πŸ‘¨β€πŸ’»
Favicon
Deploying a Next.js UI App on S3 Using Jenkins🀩
Favicon
The Global South OSC
Favicon
🎁 20 Open Source Projects You Shouldn't Miss in 2025
Favicon
A Conversation with Docker CTO Justin Cormack and Flux CEO Ron Efrani: The Future of Developer Environments
Favicon
Sample Programs Repo Celebrates 1,000 Code Snippets
Favicon
Learn Machine Learning with these amazing GitHub repositories! πŸš€
Favicon
πŸˆβ€β¬› Git and GitHub: A Beginner’s Guide to Version Control πŸš€
Favicon
Undo Mistakes in Git: Revert, Reset, and Checkout Simplified
Favicon
My First npm Package!
Favicon
Top 14 GitHub Data Risks: Data Loss Scenarios and How to Prevent Them
Favicon
Mastering Git and GitHub: A Guide for New Team Members
Favicon
Why I Stopped Using Plain Git Pull (And Why You Should Too)
Favicon
Why I Built commit-ai: A Story About Git Security and Team Safety
Favicon
πŸ”„ Automating GitHub PR Notifications with Slack Integration: A Journey
Favicon
How to Link git to GitHub via SSH on Windows
Favicon
Mastering Git Workflows: Beyond Basic Commands

Featured ones: