Daily Documentation Cleanup #150
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
# ******************************************************************************* | |
# Copyright (c) 2025 Contributors to the Eclipse Foundation | |
# | |
# See the NOTICE file(s) distributed with this work for additional | |
# information regarding copyright ownership. | |
# | |
# This program and the accompanying materials are made available under the | |
# terms of the Apache License Version 2.0 which is available at | |
# https://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# SPDX-License-Identifier: Apache-2.0 | |
# ******************************************************************************* | |
name: Daily Documentation Cleanup | |
on: | |
schedule: | |
- cron: "0 0 * * *" # Runs every day at midnight UTC | |
workflow_dispatch: # Allows manual trigger | |
jobs: | |
docs-cleanup: | |
name: Cleanup old documentation | |
runs-on: ubuntu-latest | |
permissions: | |
pages: write | |
contents: write | |
pull-requests: write | |
issues: write # Allow label creation | |
steps: | |
- name: Close abandoned feature-request PRs | |
uses: actions/stale@v9 | |
with: | |
repo-token: ${{ secrets.GITHUB_TOKEN }} | |
only-pr-labels: feature_request | |
days-before-issue-stale: -1 # Override days-before-stale for issues only | |
days-before-issue-close: -1 # Override days-before-close for issues only | |
days-before-pr-stale: 90 # 30 days idle → stale | |
days-before-pr-close: 10 # close countdown | |
stale-pr-message: > | |
This feature request has been idle for 90 days. We'll auto-close it in 10 days unless there's new activity. | |
close-pr-label: autoclosed | |
operations-per-run: 90 | |
close-pr-message: "Auto-closing: no activity for 90 days. If this is still relevant, reopen or create a fresh PR." | |
- name: Close abandoned PRs | |
uses: actions/stale@v9 | |
with: | |
repo-token: ${{ secrets.GITHUB_TOKEN }} | |
exempt-pr-labels: feature_request | |
# days-before-stale Idle number of days before marking issues/PRs stale (default: 60) | |
# days-before-close Idle number of days before closing stale issues/PRs (default: 7) | |
# Don't handle issues | |
# If set to a negative number like -1, the issues or the pull requests will never be closed automatically. | |
days-before-issue-stale: -1 # Override days-before-stale for issues only | |
days-before-issue-close: -1 # Override days-before-close for issues only | |
# Handle PRs | |
# Mark as stale after 30 days of inactivity and then for stale PRs close after 10 days | |
days-before-pr-stale: 30 # Override days-before-stale for PRs only | |
days-before-pr-close: 10 # Override days-before-close for PRs only | |
# Add message to the PR when it is stale | |
stale-pr-message: > | |
This PR is stale because it has been open for 30 days with no activity. It will be closed in 10 days if no further activity occurs. #magic___^_^___line | |
# Label the PR as autoclosed | |
close-pr-label: autoclosed | |
operations-per-run: 90 # Increase the number of operations per run | |
# Add comment to the PR when it is closed | |
close-pr-message: "Auto-closing: no activity for 30 days. If this is still relevant, reopen or create a fresh PR." | |
- name: Checkout gh-pages branch | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ github.repository }} | |
ref: gh-pages | |
fetch-depth: 0 | |
- name: Cleanup old documentation | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gh auth status # Verify authentication | |
# Fetch list of active branches | |
ACTIVE_BRANCHES=$(gh api --paginate repos/${{ github.repository }}/branches --jq '.[].name') | |
# Fetch list of open PRs | |
OPEN_PRS=$(gh api --paginate repos/${{ github.repository }}/pulls --jq '.[].number' | sed 's/^/pr-/') | |
# Combine active branches and PRs into one list | |
VALID_ENTRIES=$(echo -e "$ACTIVE_BRANCHES\n$OPEN_PRS") | |
# Get current folder names, excluding hidden folders | |
CURRENT_FOLDERS=$(find . -maxdepth 1 -type d -not -name '.' -not -path './.*' -exec basename {} \;) | |
# Read versions.json | |
if [[ -f versions.json ]]; then | |
jq '.' versions.json > versions_tmp.json | |
else | |
echo "[]" > versions_tmp.json | |
fi | |
# Remove outdated folders and update versions.json | |
for FOLDER in $CURRENT_FOLDERS; do | |
if ! echo "$VALID_ENTRIES" | grep -Fxq "$FOLDER"; then | |
echo "Removing $FOLDER" | |
rm -rf "$FOLDER" | |
jq --arg ver "$FOLDER" 'map(select(.version != $ver))' versions_tmp.json > tmp.json && mv tmp.json versions_tmp.json | |
fi | |
done | |
# Remove versions.json entries without corresponding folders | |
jq '[.[] | select((.version | IN($folders[])))]' --argjson folders "$(ls -1 | jq -R -s -c 'split("\n")[:-1]')" versions_tmp.json > versions_tmp_clean.json | |
# Ensure "main" is the first entry and others sorted alphabetically | |
jq '[.[] | select(.version != "main")] | sort_by(.version) | [{"version": "main", "url": "https://eclipse-score.github.io/score/main/"}] + .' versions_tmp_clean.json > versions.json | |
# Clean up temp files | |
rm versions_tmp.json versions_tmp_clean.json | |
- name: Commit and Push Changes | |
uses: JamesIves/github-pages-deploy-action@v4 | |
with: | |
branch: gh-pages | |
folder: . | |
commit-message: "Daily cleanup of outdated documentation" |