diff --git a/.github/workflows/bump-license-year.yml b/.github/workflows/bump-license-year.yml index 9ea15c1..8370665 100644 --- a/.github/workflows/bump-license-year.yml +++ b/.github/workflows/bump-license-year.yml @@ -2,17 +2,17 @@ name: Bump License Year on: schedule: - - cron: '0 0 1 1 *' + - cron: 0 0 1 1 * workflow_dispatch: -permissions: - contents: write - pull-requests: write - jobs: - bump-year: + bump-license-year: runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: - name: Checkout uses: actions/checkout@v4 @@ -20,52 +20,28 @@ jobs: - name: Set the current year run: | echo "CURRENT_YEAR=$(date +'%Y')" >> $GITHUB_ENV - echo "BRANCH_NAME=bump-license-year-${CURRENT_YEAR}" >> $GITHUB_ENV - - - name: Configure Git - run: | - git config --global user.name "github-actions[bot]" - git config --global user.email "github-actions[bot]@users.noreply.github.com" - name: Update license year run: | OLD_YEAR=$(grep -oP '\d{4}' LICENSE | tail -n 1) + + echo "Old year: $OLD_YEAR" + echo "Current year: ${CURRENT_YEAR}" + if [ "$OLD_YEAR" != "${CURRENT_YEAR}" ]; then sed -i "s/$OLD_YEAR/${CURRENT_YEAR}/g" LICENSE fi - - name: Check for changes - id: changes_check - run: | - if git diff --quiet; then - echo "No changes detected." - echo "CHANGES_DETECTED=false" >> $GITHUB_ENV - else - echo "Changes detected." - echo "CHANGES_DETECTED=true" >> $GITHUB_ENV - - - name: Create new branch - if: env.CHANGES_DETECTED == 'true' - run: | - git checkout -b ${BRANCH_NAME} - - - name: Commit changes - if: env.CHANGES_DETECTED == 'true' - run: | - git add LICENSE - git commit -m "chore: bump license year to ${CURRENT_YEAR}" - - - name: Push changes - if: env.CHANGES_DETECTED == 'true' - run: git push --set-upstream origin ${BRANCH_NAME} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Create Pull Request - if: env.CHANGES_DETECTED == 'true' - uses: actions/create-pull-request@v7 + uses: peter-evans/create-pull-request@v7 with: token: ${{ secrets.GITHUB_TOKEN }} - branch: ${BRANCH_NAME} - title: 'chore: bump license year to ${CURRENT_YEAR}' + commit-message: | + chore: bump license year to ${{ env.CURRENT_YEAR }} + sign-commits: true + title: | + Bump license year to ${{ env.CURRENT_YEAR }} + body: | + - Bump license year to ${{ env.CURRENT_YEAR }} + branch: bump-license-year-${{ env.CURRENT_YEAR }} base: main