Skip to content

Commit

Permalink
chore: fix Bump License Year workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
arttet committed Sep 17, 2024
1 parent 592f0ab commit 7617774
Showing 1 changed file with 19 additions and 43 deletions.
62 changes: 19 additions & 43 deletions .github/workflows/bump-license-year.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,46 @@ 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

- 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

0 comments on commit 7617774

Please sign in to comment.