Keep Alive #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ----------------------------------------------------------------------------- | |
| # | |
| # This file is part of the xPack project (http://xpack.github.io). | |
| # Copyright (c) 2025 Liviu Ionescu. All rights reserved. | |
| # | |
| # Permission to use, copy, modify, and/or distribute this software | |
| # for any purpose is hereby granted, under the terms of the MIT license. | |
| # | |
| # If a copy of the license was not distributed with this file, it can | |
| # be obtained from https://opensource.org/licenses/mit. | |
| # | |
| # ----------------------------------------------------------------------------- | |
| name: 'Keep Alive' | |
| on: | |
| schedule: | |
| - cron: '0 0 1 * *' # Monthly on the 1st at midnight UTC | |
| workflow_dispatch: | |
| jobs: | |
| keepalive: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Update keepalive timestamp | |
| run: | | |
| # Check if there are any commits in the last 30 days | |
| last_commit_date=$(git log -1 --format=%ct) | |
| current_date=$(date +%s) | |
| days_since_commit=$(( (current_date - last_commit_date) / 86400 )) | |
| if [ $days_since_commit -lt 30 ]; then | |
| echo "Repository has commits within the last 30 days (${days_since_commit} days ago). Skipping keepalive update." | |
| exit 0 | |
| fi | |
| echo "No commits in the last ${days_since_commit} days. Updating keepalive timestamp." | |
| echo "Last keepalive: $(date -u)" > .github/keepalive | |
| git config --local user.email "[email protected]" | |
| git config --local user.name "GitHub Action" | |
| git add .github/keepalive | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| else | |
| git commit -m "chore: update keepalive timestamp [skip ci]" | |
| # Push to the default branch (xpack) | |
| git push | |
| # Merge into xpack-development branch if it exists | |
| if git ls-remote --heads origin xpack-development | grep -q xpack-development; then | |
| echo "Merging keepalive update into xpack-development branch" | |
| current_branch=$(git rev-parse --abbrev-ref HEAD) | |
| git fetch origin xpack-development | |
| git checkout xpack-development | |
| git merge --no-edit ${current_branch} | |
| git push origin xpack-development | |
| git checkout ${current_branch} | |
| else | |
| echo "xpack-development branch does not exist, skipping merge" | |
| fi | |
| fi |