[Leetcode - Medium] Shortest Bridge #51
Workflow file for this run
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: Auto-merge PRs after one week | |
on: | |
schedule: | |
- cron: '0 0 * * *' # λ§€μΌ μμ μ μ€ν | |
pull_request: | |
types: [opened, synchronize, reopened, ready_for_review] | |
jobs: | |
auto-merge: | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
contents: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Check PR age and merge | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
# λͺ¨λ μ΄λ¦° PR κ°μ Έμ€κΈ° | |
prs=$(gh pr list --json number,createdAt,mergeStateStatus --state open) | |
# κ° PR νμΈ | |
echo "$prs" | jq -c '.[]' | while read pr; do | |
number=$(echo $pr | jq -r .number) | |
created_at=$(echo $pr | jq -r .createdAt) | |
merge_state=$(echo $pr | jq -r .mergeStateStatus) | |
# PR λμ΄ κ³μ° (μΌ λ¨μ) | |
age=$(( ( $(date +%s) - $(date -d "$created_at" +%s) ) / 86400 )) | |
# 7μΌ μ΄μ λμκ³ λ³ν© κ°λ₯ν μνμΈμ§ νμΈ | |
if [ $age -ge 7 ] && [ "$merge_state" == "CLEAN" ]; then | |
echo "Merging PR #$number (age: $age days)" | |
gh pr merge $number --auto --merge | |
else | |
echo "PR #$number is not ready for auto-merge (age: $age days, state: $merge_state)" | |
fi | |
done |