|
| 1 | +# ----------------------------------------------------------------------------- |
| 2 | +# |
| 3 | +# This file is part of the xPack project (http://xpack.github.io). |
| 4 | +# Copyright (c) 2025-2026 Liviu Ionescu. All rights reserved. |
| 5 | +# |
| 6 | +# Permission to use, copy, modify, and/or distribute this software |
| 7 | +# for any purpose is hereby granted, under the terms of the MIT license. |
| 8 | +# |
| 9 | +# If a copy of the license was not distributed with this file, it can |
| 10 | +# be obtained from https://opensource.org/licenses/mit. |
| 11 | +# |
| 12 | +# ----------------------------------------------------------------------------- |
| 13 | + |
| 14 | +name: 'Keep Alive' |
| 15 | + |
| 16 | +on: |
| 17 | + schedule: |
| 18 | + - cron: '0 0 1 * *' # Monthly on the 1st at midnight UTC |
| 19 | + workflow_dispatch: |
| 20 | + |
| 21 | +jobs: |
| 22 | + keepalive: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 29 | + |
| 30 | + - name: Update keepalive timestamp |
| 31 | + run: | |
| 32 | + # Check if there are any commits in the last 30 days |
| 33 | + last_commit_date=$(git log -1 --format=%ct) |
| 34 | + current_date=$(date +%s) |
| 35 | + days_since_commit=$(( (current_date - last_commit_date) / 86400 )) |
| 36 | +
|
| 37 | + if [ $days_since_commit -lt 30 ]; then |
| 38 | + echo "Repository has commits within the last 30 days (${days_since_commit} days ago). Skipping keepalive update." |
| 39 | + exit 0 |
| 40 | + fi |
| 41 | +
|
| 42 | + echo "No commits in the last ${days_since_commit} days. Updating keepalive timestamp." |
| 43 | + echo "Last keepalive: $(date -u)" > .github/keepalive |
| 44 | + git config --local user.email "action@github.com" |
| 45 | + git config --local user.name "GitHub Action" |
| 46 | + git add .github/keepalive |
| 47 | + if git diff --staged --quiet; then |
| 48 | + echo "No changes to commit" |
| 49 | + else |
| 50 | + git commit -m "chore: update keepalive timestamp [skip ci]" |
| 51 | +
|
| 52 | + # Push to the default branch (xpack) |
| 53 | + git push |
| 54 | +
|
| 55 | + # Merge into xpack-development branch if it exists |
| 56 | + if git ls-remote --heads origin xpack-development | grep -q xpack-development; then |
| 57 | + echo "Merging keepalive update into xpack-development branch" |
| 58 | + current_branch=$(git rev-parse --abbrev-ref HEAD) |
| 59 | + git fetch origin xpack-development |
| 60 | + git checkout xpack-development |
| 61 | + git merge --no-edit ${current_branch} |
| 62 | + git push origin xpack-development |
| 63 | + git checkout ${current_branch} |
| 64 | + else |
| 65 | + echo "xpack-development branch does not exist, skipping merge" |
| 66 | + fi |
| 67 | + fi |
0 commit comments