Merge New Manga Branches #9
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: "52 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 "Existing PR found: $existing_pr" | |
# Merge the existing PR | |
gh pr merge --squash "$existing_pr" | |
else | |
echo "Creating PR." | |
# Create a new pull request | |
pr_url=$(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.") | |
if [[ -n "$pr_url" ]]; then | |
echo "Created PR: $pr_url" | |
# Merge the newly created PR | |
gh pr merge --squash "$pr_url" | |
else | |
echo "Failed to create PR." | |
fi | |
fi | |
else | |
echo "Branch '$branch_name' does not exist. There's no new manga to auto-merge." | |
fi |