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

タイトルからファイルを特定する処理の不備を修正 #34

Merged
merged 3 commits into from
Oct 31, 2023
Merged
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
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
name: pull draft by title
name: create draft pull request

inputs:
title:
description: draft entry title
required: true
BLOG_DOMAIN:
required: true
ENTRY_PATH:
required: true

runs:
using: "composite"
steps:
- name: pull
run: |
blogsync pull ${{ inputs.BLOG_DOMAIN }}
shell: bash
- name: find entry
id: find-entry
- name: set entry variables
id: set-entry-variables
run: |
entry=$(grep -xl "Title: ${{ inputs.title }}" $(git ls-files -o --exclude-standard))
if [[ -z "$entry" ]]; then
echo "Error: No draft entry titled ${{ inputs.title }} was found"
exit 1
fi
echo "ENTRY_ID=$(yq --front-matter=extract '.EditURL' "$entry" | grep -oP '[^/]+\d$')" >> $GITHUB_OUTPUT
echo "PREVIEW_URL=$(yq --front-matter=extract '.PreviewURL' "$entry")" >> $GITHUB_OUTPUT
echo "EDIT_URL=$(yq --front-matter=extract '.EditURL' ${{ inputs.ENTRY_PATH }})" >> $GITHUB_OUTPUT
echo "ENTRY_ID=$(yq --front-matter=extract '.EditURL' ${{ inputs.ENTRY_PATH }} | grep -oP '[^/]+\d$')" >> $GITHUB_OUTPUT
echo "PREVIEW_URL=$(yq --front-matter=extract '.PreviewURL' ${{ inputs.ENTRY_PATH }})" >> $GITHUB_OUTPUT
shell: bash
- name: set owner
id: set-owner
Expand All @@ -32,11 +25,11 @@ runs:
if [[ "$owner" == 'null' ]]; then
owner=$(yq ".[\"${{ inputs.BLOG_DOMAIN }}\"].username" blogsync.yaml)
fi
echo "OWNER_NAME="$owner"" >> $GITHUB_OUTPUT
echo "OWNER_NAME=$owner" >> $GITHUB_OUTPUT
shell: bash
- name: delete other files
run: |
delete_files=($(grep -xL "Title: ${{ inputs.title }}" $(git ls-files -mo --exclude-standard)))
delete_files=($(grep -xL "EditURL: ${{ steps.set-entry-variables.outputs.EDIT_URL }}" $(git ls-files -mo --exclude-standard)))
for file in ${delete_files[@]}; do
rm "$file"
done
Expand All @@ -47,8 +40,8 @@ runs:
uses: peter-evans/create-pull-request@v5
env:
OWNER_NAME: ${{ steps.set-owner.outputs.OWNER_NAME }}
ENTRY_ID: ${{ steps.find-entry.outputs.ENTRY_ID }}
PREVIEW_URL: ${{ steps.find-entry.outputs.PREVIEW_URL }}
ENTRY_ID: ${{ steps.set-entry-variables.outputs.ENTRY_ID }}
PREVIEW_URL: ${{ steps.set-entry-variables.outputs.PREVIEW_URL }}
with:
title: ${{ github.event.inputs.title }}
branch: draft-entry-${{ env.ENTRY_ID }}
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/create-draft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ jobs:
env:
TITLE: ${{ inputs.title }}
- name: post draft to hatenablog
id: post-draft
run: |
blogsync post --draft ${{ inputs.BLOG_DOMAIN }} < 'draft'
entry_path=$(blogsync post --draft ${{ inputs.BLOG_DOMAIN }} < 'draft')
echo "ENTRY_PATH=$entry_path" >> $GITHUB_OUTPUT
- name: pull
run: |
blogsync pull ${{ inputs.BLOG_DOMAIN }}
- name: pull draft by title
uses: hatena/hatenablog-workflows/.github/actions/pull-draft-by-title@v1
uses: hatena/hatenablog-workflows/.github/actions/create-draft-pull-request@v1
with:
title: ${{ inputs.title }}
BLOG_DOMAIN: ${{ inputs.BLOG_DOMAIN }}
ENTRY_PATH: ${{ steps.post-draft.outputs.ENTRY_PATH }}
21 changes: 20 additions & 1 deletion .github/workflows/pull-draft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,27 @@ jobs:
fetch-depth: 0
- name: setup
uses: hatena/hatenablog-workflows/.github/actions/setup@v1
- name: pull
run: |
blogsync pull ${{ inputs.BLOG_DOMAIN }}
- name: set entry path
id: set-entry-path
run: |
files=($(git ls-files -o --exclude-standard))
for file in ${files[@]}; do
title=$(yq --front-matter=extract '.Title' "$file")
if [[ "$title" == ${{ inputs.title }} ]]; then
entry_path="$file"
fi
done
if [[ -z "$entry_path" ]]; then
echo "Error: No draft entry titled ${{ inputs.title }} was found"
exit 1
fi
echo "ENTRY_PATH=$entry_path" >> $GITHUB_OUTPUT
- name: pull draft by title
uses: hatena/hatenablog-workflows/.github/actions/pull-draft-by-title@v1
uses: hatena/hatenablog-workflows/.github/actions/create-draft-pull-request@v1
with:
title: ${{ inputs.title }}
BLOG_DOMAIN: ${{ inputs.BLOG_DOMAIN }}
ENTRY_PATH: ${{ steps.set-entry-path.outputs.ENTRY_PATH }}