Skip to content

Conversation

@spider-man-tm
Copy link
Contributor

@spider-man-tm spider-man-tm commented Oct 14, 2023

Closes #23

.github/workflows/initialize.yamlについて、対象ファイルがない場合に、xargs コマンドが受け取る引数がなく、エラーが発生

(修正前)

      - name: delete draft files
        if: inputs.is_draft_included == false
        run: |
          target=$(git ls-files -mo --exclude-standard | xargs grep -xl 'Draft: true')
          IFS=" " read -r -a draft_files <<< "$(echo "$target" | xargs)"
          for file in "${draft_files[@]}"; do
            rm "$file"
          done

修正後は以下の通り、下書き記事があった場合にのみ、ファイル削除を行なっています。

(修正後)

          target=$(git ls-files -mo --exclude-standard | xargs grep -xl 'Draft: true' || echo "")
          if [[ ! -z "$target" ]]; then
            IFS=" " read -r -a draft_files <<< "$(echo "$target" | xargs)"
            for file in "${draft_files[@]}"; do
              rm "$file"
            done
          fi

.github/actions/move-draft-and-update-metadata/action.yamlについて、こちらも対象ファイルがない場合に、draft_filesが空になることでエラーが発生していました。

(修正前)

    - name: move draft and update metadata
      run: |
        draft_files=($(grep -xl 'Draft: true' $(git ls-files -mo --exclude-standard)))
        for file in ${draft_files[@]}; do
          entry_id=$(yq --front-matter=extract '.EditURL' "$file" | grep -oP '[^/]+\d$')
          yq --front-matter=process -i 'del(.Date,.URL)' "$file" 
          mv "$file" "draft_entries/$entry_id.${file##*.}"
        done
      shell: bash

修正後は以下のように、空だった場合に処理をスキップするようにしています。

(修正後)

        draft_files=($(grep -xl 'Draft: true' $(git ls-files -mo --exclude-standard) || echo ""))
        if [[ ${#draft_files[@]} -eq 0 ]]; then
          exit 0
        fi
        for file in ${draft_files[@]}; do
          entry_id=$(yq --front-matter=extract '.EditURL' "$file" | grep -oP '[^/]+\d$')
          yq --front-matter=process -i 'del(.Date,.URL)' "$file"
          mv "$file" "draft_entries/$entry_id.${file##*.}"
        done

Copy link
Member

@halkt halkt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご提案ありがとうございます!

おっしゃる通り下書き記事がない場合に動作しないようになっていたので変更をMergeさせていただきます.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

はてなブログ側に下書き記事が1つも存在していない場合にinitializeワークフローが失敗してしまう

2 participants