2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GitHub ActionsでQiita記事を自動投稿する完全ガイド【Qiita自動投稿シリーズ #1(実践編)】

Last updated at Posted at 2025-10-22

はじめに

こんにちは、piyovateです。

この記事では、Qiita CLIとGitHub Actionsを使って、GitHubにpushするだけで自動的にQiitaに記事を投稿する環境を0から構築します 🚀

「記事をローカルで管理したい」「バージョン管理したい」「自動投稿したい」という方におすすめです 💪


🎯 この記事でできるようになること

  • Qiita CLIで作成した記事をGitHubで安全に管理できる
  • GitHubにpushするだけで自動的にQiitaに投稿される
  • 公式のシンプルな方法で確実に動作する環境を構築できる

🧭 前提環境

ツール バージョン例
Node.js 20.x 以上
npm 10.x 以上
Qiita CLI 最新版
GitHub Actions Ubuntu Runner 最新版

📝 Step 1:新しいプロジェクトを作成

まずは、クリーンな環境で始めましょう。

# 作業ディレクトリを作成
mkdir qiita-posts-official
cd qiita-posts-official

# Qiita CLIで初期化
npx qiita init

実行すると以下のファイルが自動生成されます:

qiita-posts-official/
├── .github/
│   └── workflows/
│       └── publish.yml    # ← GitHub Actionsのワークフロー
├── .gitignore
└── qiita.config.json

🔑 Step 2:Qiitaにログイン

npx qiita login

ブラウザで以下のURLが表示されるので、アクセスしてトークンを発行:
https://qiita.com/settings/tokens/new?read_qiita=1&write_qiita=1

発行したトークンを入力すると、ログイン完了です 🎉


📰 Step 3:テスト記事を作成

npx qiita new test-article

生成された test-article.md を編集:

---
title: GitHub Actionsでの自動投稿テスト
tags:
  - test
private: false
updated_at: ''
id: null
organization_url_name: null
slide: false
ignorePublish: false
---

これはGitHub Actionsのテストです 🚀

🐙 Step 4:GitHubリポジトリを作成

  1. ブラウザで https://github.com/new を開く
  2. 以下を設定:
    • Repository name: qiita-posts-official(任意)
    • Public/Private: どちらでもOK
    • Initialize this repository with: すべてチェックなし
  3. Create repository をクリック

🔐 Step 5:QIITA_TOKENをSecretsに登録

これが最重要ステップです!

  1. 作成したリポジトリページで Settings タブをクリック
  2. 左メニューから Secrets and variablesActions をクリック
  3. New repository secret をクリック
  4. 以下を入力:
    • Name: QIITA_TOKEN
    • Secret: Step 2で発行したトークンを貼り付け
  5. Add secret をクリック

⚠️ 重要: トークンは絶対にコードにコミットしないでください!


📤 Step 6:Gitの初期設定とプッシュ

# Gitリポジトリを初期化
git init

# ユーザー設定(未設定の場合)
git config user.name "your-name"
git config user.email "your-email@example.com"

# すべてのファイルを追加
git add .

# 初回コミット
git commit -m "Initial commit: Qiita CLI setup"

# ブランチ名をmainに
git branch -M main

# リモートリポジトリを追加
git remote add origin https://github.com/your-username/qiita-posts-official.git

# プッシュ
git push -u origin main

🎬 Step 7:GitHub Actionsの動作確認

プッシュすると、自動的にGitHub Actionsが実行されます。

  1. GitHubのリポジトリページで Actions タブをクリック
  2. 「Publish articles」ワークフローが実行中/完了を確認
  3. ✅ 成功すると、Qiitaに記事が投稿されます

🚀 使い方:記事を投稿する

新規記事を投稿

# 記事を作成
npx qiita new my-awesome-article

# 内容を編集
notepad my-awesome-article.md

# Git管理
git add .
git commit -m "Add new article"
git push

→ GitHub Actionsが自動実行され、Qiitaに投稿されます 🎉

既存記事を更新

# 記事を編集
notepad existing-article.md

# Git管理
git add .
git commit -m "Update article"
git push

→ GitHub Actionsが自動実行され、Qiitaの記事が更新されます 🎉


🎓 まとめ

この記事では、公式のQiita CLIとGitHub Actionを使った、シンプルで確実な自動投稿環境を構築しました。

できるようになったこと

✅ GitHubにpushするだけで自動的にQiitaに投稿
✅ 記事のバージョン管理
✅ 複雑なスクリプトなしで確実に動作


📚 参考リンク


🙌 おわりに

この記事が役に立ったら、いいねをお願いします 👍

次回は投稿予約の設定を行いたいと思います

次回もお楽しみに!

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?