article_update #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Article Update | |
on: | |
repository_dispatch: | |
types: [article_update] | |
jobs: | |
update_article: | |
runs-on: ubuntu-latest | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
ssh-key: ${{ secrets.GHA_SSH_PRIVATE_KEY }} | |
submodules: recursive | |
- name: Update submodule | |
run: git submodule update --remote | |
- name: Check git status | |
id: status | |
run: | | |
git status -s | |
echo "has_changes=$(git status -s | wc -l)" >> $GITHUB_OUTPUT | |
- name: Create Branch | |
if: ${{ steps.status.outputs.has_changes != '0' }} | |
run: | | |
BRANCH_NAME="article-update-$(date +%Y%m%d-%H%M%S)" | |
git checkout -b $BRANCH_NAME | |
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | |
- name: Commit | |
if: ${{ steps.status.outputs.has_changes != '0' }} | |
run: | | |
git config --local user.name "Github Actions" | |
git config --local user.email "action@github.com" | |
git add . | |
git commit -m "Update submodule: ${{ github.event.client_payload.commit_message }}" | |
- name: Push | |
if: ${{ steps.status.outputs.has_changes != '0' }} | |
uses: ad-m/github-push-action@master | |
with: | |
branch: ${{ env.BRANCH_NAME }} | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Check PullRequest Exists | |
if: ${{ steps.status.outputs.has_changes != '0' }} | |
id: check_pr | |
run: | | |
echo "count=$(gh pr list -S '記事更新'in:title -s open | wc -l)" >> "$GITHUB_OUTPUT" | |
- name: Create Release Pull Request | |
if: ${{ steps.status.outputs.has_changes != '0' && steps.check_pr.outputs.count == '0' }} | |
run: | | |
gh pr create \ | |
--base main \ | |
--head ${{ env.BRANCH_NAME }} \ | |
--title "記事更新: ${{ github.event.client_payload.commit_message }}" \ | |
--body "## 更新内容 | |
${{ github.event.client_payload.commit_message }} | |
自動生成されたPRです。" \ | |
--label "article-update" | |
- name: Edit Release Pull Request | |
if: ${{ steps.status.outputs.has_changes != '0' && steps.check_pr.outputs.count != '0' }} | |
run: | | |
PR_NUMBER=$(gh pr list -S '記事更新'in:title -s open --json number -q '.[0].number') | |
CURRENT_TITLE=$(gh pr view $PR_NUMBER --json title -q '.title') | |
NEW_TITLE="${CURRENT_TITLE} / ${{ github.event.client_payload.commit_message }}" | |
gh pr edit $PR_NUMBER \ | |
--title "$NEW_TITLE" |