0
0

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に記事を投稿する

Last updated at Posted at 2025-10-15

Qiita自動投稿&Teams通知の手順まとめ

① 必要なファイルを準備

リポジトリ直下に以下の構成を作ります:

.
├─ articles/
│   └─ xxxxx-xxxx.md
└─ .github/
    └─ workflows/
        └─ qiita-post.yml   ← Workflowファイル

以下にqiita-post.ymlの内容を記載します:

name: Auto Post Qiita Article and Notify Teams

on:
  push:
    branches:
      - main
  workflow_dispatch:

permissions:
  contents: write

# 並行実行の制御
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: false

jobs:
  publish:
    name: Publish article to Qiita
    runs-on: ubuntu-latest
    timeout-minutes: 5
    outputs:
      qiita_success: ${{ steps.publish_qiita.outcome == 'success' }}
      title: ${{ steps.get_info.outputs.title || '' }}
      url: ${{ steps.get_info.outputs.url || '' }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      
      - name: Publish article to Qiita
        id: publish_qiita
        uses: increments/qiita-cli/actions/publish@v1
        with:
          qiita-token: ${{ secrets.QIITA_TOKEN }}
          root: "."
          
      - name: Get published info
        id: get_info
        if: success()
        run: |
          # ここで投稿された記事の情報を取得する実装があればよい
          # 現在は簡易実装
          echo "title=新しい記事" >> $GITHUB_OUTPUT
          echo "url=https://qiita.com/" >> $GITHUB_OUTPUT

  # シンプルなTeams通知ジョブ
  notify:
    name: Notify Teams
    runs-on: ubuntu-latest
    needs: publish
    if: ${{ success() }}  # 前のジョブが成功した場合のみ実行
    steps:
      - name: Send basic notification to Teams
        env:
          TEAMS_WEBHOOK_URL: ${{ secrets.TEAMS_WEBHOOK_URL }}
        run: |
          echo "📢 Sending notification to Teams..."
          
          # 基本的なチェック
          if [ -z "$TEAMS_WEBHOOK_URL" ]; then
            echo "⚠️ Teams webhook URL is not set. Skipping notification."
            exit 0
          fi
          
          # 極めてシンプルなJSON形式のメッセージ送信
          curl -X POST -H "Content-Type: application/json" \
               -d '{"text": "🚀 Qiitaの記事が更新されました!"}' \
               "$TEAMS_WEBHOOK_URL"

② Qiita用トークンを取得

Qiitaの「個人設定 → アプリケーション」から「アクセストークンを発行」してください。

権限は以下で十分です:

  • ✅ read_qiita
  • ✅ write_qiita

③ GitHub Secrets に登録

リポジトリ設定 → Settings > Secrets and variables > Actions

Name Value
QIITA_TOKEN 上で発行したQiitaトークン
TEAMS_WEBHOOK_URL TeamsチャンネルのIncoming Webhook URL

④ 記事を作成

この記事が投稿され、teamsに通知が飛ぶ予定です。

⑤ mainブランチにpush

git add articles/hello-qiita.md
git commit -m "add: first qiita article"
git push origin main

⑥ 結果を確認

GitHub Actions → “Auto Post Qiita Article and Notify Teams” が実行される

成功すれば:

  • Qiitaに新しい記事が投稿されている
  • TeamsにAdaptive Card形式で通知が届く 🎉

これで、mainブランチにpushすればQiita記事が自動で公開&Teams通知される状態になりました。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?