From 0bfee551740809086fa9896b429a83269966b124 Mon Sep 17 00:00:00 2001 From: Artyom Tetyukhin <51746822+arttet@users.noreply.github.com> Date: Mon, 16 Sep 2024 23:23:27 +0400 Subject: [PATCH] chore: add Bump License Year workflows --- .github/workflows/bump-license-year.yml | 71 +++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/bump-license-year.yml diff --git a/.github/workflows/bump-license-year.yml b/.github/workflows/bump-license-year.yml new file mode 100644 index 0000000..9ea15c1 --- /dev/null +++ b/.github/workflows/bump-license-year.yml @@ -0,0 +1,71 @@ +name: Bump License Year + +on: + schedule: + - cron: '0 0 1 1 *' + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +jobs: + bump-year: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - 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) + 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 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: ${BRANCH_NAME} + title: 'chore: bump license year to ${CURRENT_YEAR}' + base: main