Merge New Manga Branches #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: Merge New Manga Branches | |
on: | |
schedule: | |
- cron: "55 11 * * 5" | |
workflow_dispatch: | |
jobs: | |
merge_new_manga_branch: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Git | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Actions" | |
- name: Create and merge PR | |
env: | |
GITHUB_TOKEN: ${{ secrets.AUTOMERGENEWBLOGTOKEN }} | |
run: | | |
# Get the current date in the format 'YYYY-MM-DD' | |
current_date=$(date +%Y-%m-%d) | |
# Construct the branch name | |
branch_name="${current_date}-new-manga" | |
# Check if the branch exists on the remote | |
if git ls-remote --exit-code origin "$branch_name"; then | |
# Check if a PR already exists | |
existing_pr=$(gh pr list --base main --head $branch_name --state open --json url --jq '.[0].url') | |
if [[ -n "$existing_pr" ]]; then | |
echo "PR already exists: $existing_pr" | |
gh pr merge --squash "$existing_pr" | |
else | |
# Create a pull request using GitHub CLI | |
gh pr create --base main --head $branch_name --title "New manga of blog at '${current_date}'" --body "This is a PR for new manga of blog." | |
sleep 5 | |
# Merge the pull request using GitHub CLI | |
gh pr merge --squash | |
fi | |
else | |
echo "Branch '$branch_name' does not exist. There's no new manga to auto-merge." | |
fi |