1313 permissions :
1414 contents : write
1515 pull-requests : write
16+ env :
17+ BASE_BRANCH : ${{ github.event.repository.default_branch }}
1618
1719 steps :
1820 - name : Checkout repository
@@ -31,31 +33,48 @@ jobs:
3133 git config user.name "github-actions[bot]"
3234 git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
3335
36+ - name : Prepare branch
37+ run : |
38+ YEAR=$(date +%Y)
39+ BASE="${BASE_BRANCH:-master}"
40+ BRANCH="maintenance/update-copyright-dates-${YEAR}"
41+
42+ git fetch origin "$BASE"
43+ git switch "$BASE"
44+ git branch -D "$BRANCH" 2>/dev/null || true
45+
46+ PRE_SHA=$(git rev-parse --verify "$BRANCH" 2>/dev/null || echo "none")
47+ echo "YEAR=$YEAR" >> "$GITHUB_ENV"
48+ echo "BASE=$BASE" >> "$GITHUB_ENV"
49+ echo "BRANCH=$BRANCH" >> "$GITHUB_ENV"
50+ echo "PRE_SHA=$PRE_SHA" >> "$GITHUB_ENV"
51+
3452 - name : Update copyright dates
35- id : update-dates
3653 run : |
37- set +e
38- bdip update-copyright-dates --git .
39- EXIT_CODE=$?
40- set -e
41-
42- if [ $EXIT_CODE -eq 0 ]; then
43- echo "Changes were made and committed to branch"
44- echo "has_changes=true" >> $GITHUB_OUTPUT
54+ bdip update-copyright-dates \
55+ --dockerfiles-dir . \
56+ --git \
57+ --create-branch \
58+ --push
59+
60+ - name : Detect commit
61+ id : detect
62+ run : |
63+ POST_SHA=$(git rev-parse --verify "$BRANCH" 2>/dev/null || echo "none")
64+ if [ "$POST_SHA" != "none" ] && [ "$POST_SHA" != "$PRE_SHA" ]; then
65+ echo "has_changes=true" >> "$GITHUB_OUTPUT"
4566 else
46- echo "No copyright updates needed"
47- echo "has_changes=false" >> $GITHUB_OUTPUT
67+ echo "has_changes=false" >> "$GITHUB_OUTPUT"
4868 fi
4969
5070 - name : Create Pull Request
51- if : steps.update-dates .outputs.has_changes == 'true'
71+ if : steps.detect .outputs.has_changes == 'true'
5272 env :
53- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
73+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
5474 run : |
55- YEAR=$(date +%Y)
5675 gh pr create \
5776 --title "Update copyright dates to $YEAR" \
5877 --body "This PR updates the copyright dates to $YEAR." \
59- --base master \
60- --head "maintenance/update-copyright-dates-$YEAR " \
78+ --base "$BASE" \
79+ --head "$BRANCH " \
6180 --label "maintenance"
0 commit comments