diff --git a/.github/workflows/keep-alive.yml b/.github/workflows/keep-alive.yml index e43e8d6..a600ac2 100644 --- a/.github/workflows/keep-alive.yml +++ b/.github/workflows/keep-alive.yml @@ -12,25 +12,22 @@ jobs: keep-workflow-alive: name: Keep workflow alive runs-on: ubuntu-latest + permissions: + contents: write steps: - uses: actions/checkout@v6 with: ref: master - - name: Get date from 50 days ago - run: | - datethen=`date -d "-50 days" --utc +%FT%TZ` - echo "datelimit=$datethen" >> $GITHUB_ENV - - - name: setup git config - if: github.event.repository.pushed_at <= env.datelimit - run: | - # setup the username and email. - git config user.name "Github Actions Keepalive Bot" - git config user.email "<>" - - name: commit IF last commit is older than 50 days - if: github.event.repository.pushed_at <= env.datelimit run: | - git commit -m "Empty commit to keep the gihub workflows alive" --allow-empty - git push origin master \ No newline at end of file + datethen=$(date -d "-50 days" --utc +%s) + last_push=$(git log -1 --format=%ct) + if [ "$last_push" -le "$datethen" ]; then + git config user.name "Github Actions Keepalive Bot" + git config user.email "<>" + git commit -m "Empty commit to keep the github workflows alive" --allow-empty + git push origin master + else + echo "Last commit is recent enough, skipping keepalive commit." + fi \ No newline at end of file