Skip to content

Commit 9e48103

Browse files
committed
Update update_pr_branch.yaml
1 parent 31cb72d commit 9e48103

1 file changed

Lines changed: 20 additions & 34 deletions

File tree

.github/workflows/update_pr_branch.yaml

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
- FrogPilot-Staging
77

88
env:
9+
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
10+
911
SOURCE_BRANCH: FrogPilot-Staging
1012
TARGET_BRANCH: MAKE-PRS-HERE
1113

@@ -21,30 +23,25 @@ jobs:
2123
- name: Checkout ${{ env.SOURCE_BRANCH }}
2224
uses: actions/checkout@v3
2325
with:
24-
ref: "${{ env.SOURCE_BRANCH }}"
26+
persist-credentials: false
27+
2528
fetch-depth: 0
2629

30+
ref: ${{ env.SOURCE_BRANCH }}
31+
2732
- name: Find "Compile FrogPilot" Commit in ${{ env.SOURCE_BRANCH }}
2833
id: find_parent
2934
run: |
3035
COMMIT=$(git rev-list HEAD -n 1 --grep="Compile FrogPilot")
31-
if [ -z "$COMMIT" ]; then
32-
echo "Commit with message 'Compile FrogPilot' not found." >&2
33-
exit 1
34-
fi
36+
[ -z "$COMMIT" ] && echo "Compile commit not found." >&2 && exit 1
3537
3638
PARENT=$(git rev-list --parents -n 1 "$COMMIT" | awk '{print $2}')
37-
if [ -z "$PARENT" ]; then
38-
echo "Parent commit not found." >&2
39-
exit 1
40-
fi
39+
[ -z "$PARENT" ] && echo "Parent commit not found." >&2 && exit 1
4140
42-
echo "Compile commit: $COMMIT"
43-
echo "Parent commit: $PARENT"
4441
echo "parent_commit=$PARENT" >> "$GITHUB_OUTPUT"
4542
echo "compile_commit=$COMMIT" >> "$GITHUB_OUTPUT"
4643
47-
- name: Checkout ${{ env.TARGET_BRANCH }}
44+
- name: Fetch and Checkout ${{ env.TARGET_BRANCH }}
4845
run: |
4946
git fetch origin "${{ env.TARGET_BRANCH }}"
5047
git checkout "${{ env.TARGET_BRANCH }}"
@@ -53,17 +50,12 @@ jobs:
5350
run: |
5451
git rm -r --ignore-unmatch .
5552
git clean -fdx
56-
57-
PARENT_COMMIT="${{ steps.find_parent.outputs.parent_commit }}"
58-
git checkout "$PARENT_COMMIT" -- .
53+
git checkout "${{ steps.find_parent.outputs.parent_commit }}" -- .
5954
6055
COMPILE_COMMIT="${{ steps.find_parent.outputs.compile_commit }}"
6156
SOURCE_HEAD=$(git rev-parse "origin/${{ env.SOURCE_BRANCH }}")
6257
63-
if [ "$COMPILE_COMMIT" != "$SOURCE_HEAD" ]; then
64-
echo "Applying changes from '${{ env.SOURCE_BRANCH }}' branch..."
65-
git cherry-pick --no-commit "${COMPILE_COMMIT}".."$SOURCE_HEAD"
66-
fi
58+
[ "$COMPILE_COMMIT" != "$SOURCE_HEAD" ] && git cherry-pick --no-commit "${COMPILE_COMMIT}".."$SOURCE_HEAD"
6759
6860
rm -f .github/update_date
6961
@@ -72,28 +64,22 @@ jobs:
7264
- name: Commit and Push to ${{ env.TARGET_BRANCH }}
7365
run: |
7466
TZ_VALUE="America/Phoenix"
75-
current_day=$(TZ="$TZ_VALUE" date +"%-d")
67+
day=$(TZ="$TZ_VALUE" date +"%-d")
7668
month=$(TZ="$TZ_VALUE" date +"%B")
7769
year=$(TZ="$TZ_VALUE" date +"%Y")
7870
79-
if [[ "$current_day" =~ ^1[123]$ ]]; then
80-
suffix="th"
81-
else
82-
case $(($current_day % 10)) in
83-
1) suffix="st" ;;
84-
2) suffix="nd" ;;
85-
3) suffix="rd" ;;
86-
*) suffix="th" ;;
87-
esac
88-
fi
71+
case $day in
72+
11|12|13) s=th ;;
73+
*) case $((day % 10)) in 1) s=st ;; 2) s=nd ;; 3) s=rd ;; *) s=th ;; esac ;;
74+
esac
8975
90-
commit_message="${month} ${current_day}${suffix}, ${year} Update"
91-
echo "Commit message: $commit_message"
76+
commit_message="${month} ${day}${s}, ${year} Update"
9277
93-
if git log --oneline --format="%s" | grep -q "$commit_message"; then
94-
echo "Existing commit found with message: $commit_message"
78+
if git log -1 --pretty=%s | grep -q "$commit_message"; then
9579
git commit --amend --no-edit
9680
else
9781
git commit -m "$commit_message"
9882
fi
83+
84+
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}
9985
git push origin "${{ env.TARGET_BRANCH }}" --force

0 commit comments

Comments
 (0)