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

Fix test #1471

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# PRのラベルに応じてリリースノートのカテゴリを分ける
changelog:
exclude:
authors:
- github-actions
categories:
- title: New Features
labels:
- "feature"
- title: Bug Fixes
labels:
- "bug"
- title: Hot Fixes
labels:
- "hotfix"
- title: Other Changes
labels:
- "*"
39 changes: 39 additions & 0 deletions .github/workflows/label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Automatically labeling pull request.

on:
pull_request:
types: [opened]

jobs:
auto-labeling-pr:
runs-on: ubuntu-latest

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: Checkout code
uses: actions/checkout@v4

# ラベル名を取得する
- name: Get label name
id: label_name
run: |
branch_type=$(echo ${{ github.head_ref }} | cut -d "/" -f1)
if [ $branch_type == 'feature' ]; then
label_name="feature"
elif [ $branch_type == 'fix' ]; then
label_name="bug"
elif [ $branch_type == 'hotfix' ]; then
label_name="hotfix"
else
label_name=""
fi
echo "label_name=$label_name" >> $GITHUB_OUTPUT

# PRにラベルを付与する
- name: Auto labeling
if: ${{ steps.label_name.outputs.label_name != '' }}
run: |
number=$(echo ${{ github.event.pull_request.number }})
gh pr edit $number --add-label ${{ steps.label_name.outputs.label_name }}
35 changes: 35 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: notion-py
defaults:
run:
shell: bash

on:
pull_request_target:
types:
- closed
workflow_dispatch:
jobs:
DeployToNotion:
name: runner / DeployToNotion
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./notion
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
- name: Setup node/npm
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm install
- name: Run the Notion script
env:
FILE_PATH: ${{ vars.FILE_PATH }}
BLOCK_ID: ${{ vars.BLOCK_ID }}
TOKEN: ${{ secrets.NOTION_API_SECRET }}
run: node markdown.mjs

96 changes: 96 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Create release tag and release note.

on:
pull_request:
types: [closed]
branches:
- main

jobs:
create-release-tag:
# PRがマージされたときのみ実行
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TZ: "Asia/Tokyo"

steps:
- uses: actions/checkout@v4

# 前回のリリースタグを取得する
- name: Get previous tag
id: pre_tag
run: |
echo "pre_tag=$(curl -H 'Accept: application/vnd.github.v3+json' -H 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name)" >> $GITHUB_OUTPUT

# タグを生成する 「{YYYY.MM.DD}-{当日リリース回数}」
- name: Generate tag
id: release_tag
run: |
today=$(date +'%Y.%m.%d')
pre_release_date=$(echo ${{ steps.pre_tag.outputs.pre_tag }} | awk -F'-' '{print $1}')
pre_release_count=$(echo ${{ steps.pre_tag.outputs.pre_tag }} | awk -F'-' '{print $2}')
if [[ ! $pre_release_date = $today ]]; then
pre_release_count=0
fi
echo "release_tag=$today-$(($pre_release_count + 1))" >> $GITHUB_OUTPUT

# PRのDescriptionを取得しマークダウン形式に変換する
- name: Get pr description
id: pr_description
run: |
echo "pr_description=$(curl -H 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
'https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number}}' \
| jq .body | awk '{if ($0 == "null") print ""; else print}')" >> $GITHUB_OUTPUT

# 前回リリースからの差分をもとに、変更点を取得する
- name: Generate release note changes
id: changes
run: |
echo "changes=$(
curl -X POST \
-H 'Accept: application/vnd.github.v3+json' \
-H 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' \
https://api.github.com/repos/${{ github.repository }}/releases/generate-notes \
-d '{
"tag_name": "${{ steps.release_tag.outputs.release_tag }}",
"previous_tag_name": "${{ steps.pre_tag.outputs.pre_tag }}",
"target_commitish": "main"
}' | jq .body
)" >> $GITHUB_OUTPUT

# リリースノートの本文を作成する
- name: Create release note body
id: release_note_body
run: |
echo "release_note_body=$(echo \
${{ steps.pr_description.outputs.pr_description }} \
${{ steps.changes.outputs.changes }} \
| sed 's/\\"//g' | sed 's/["“]//g')" >> $GITHUB_OUTPUT

# タグを切り、リリースノートを作成する
# PRのラベルに応じてカテゴライズする場合は、使用先のリポジトリで下記を定義する
# https://docs.github.com/ja/repositories/releasing-projects-on-github/automatically-generated-release-notes#configuring-automatically-generated-release-notes
- name: Create Release
run: |
response=$(curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-d "{ \
\"tag_name\": \"${{ steps.release_tag.outputs.release_tag }}\", \
\"target_commitish\": \"main\", \
\"name\": \"${{ steps.release_tag.outputs.release_tag }}\", \
\"body\": \"${{ steps.release_note_body.outputs.release_note_body }}\" \
}" \
-w "%{http_code}" \
-o response_body.txt \
https://api.github.com/repos/${{ github.repository }}/releases)
status_code=$(tail -n1 <<< "$response")
echo "Status Code: $status_code"
body=$(cat response_body.txt)
echo "Response Body: $body"
if [ $status_code -ne 201 ]; then
echo "Failed to create release"
exit 1
fi
14 changes: 14 additions & 0 deletions notion/markdown.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Client } from '@notionhq/client';
import { readFileSync } from 'fs';
import matter from 'gray-matter';
import { markdownToBlocks } from '@tryfabric/martian';

const Block_ID = process.env.BLOCK_ID;
const FILE_Path = process.env.FILE_PATH;
const Token = process.env.TOKEN;


console.log("test")
console.log(Block_ID)
console.log(FILE_Path)
console.log(Token)
Loading