diff --git a/.github/workflows/proc_deprecated.sh b/.github/workflows/proc_deprecated.sh new file mode 100644 index 00000000..83999d65 --- /dev/null +++ b/.github/workflows/proc_deprecated.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +# This script is used to generate the list of all the deprecated apps in the manifest +# It will generate a list of all the apps that are deprecated in the manifest +# It will also estimate which of the apps were deprecated more than x months ago +# It will create a branch and create commits removing each of the deprecated apps +# It will create a PR for the branch and assign it to the user who ran the script and deb-get-devs +# for review + +# get the current date +current_date=$(date +%Y%m%d) +# get the current branch +current_branch=$(git rev-parse --abbrev-ref HEAD) +# get the current user +# current_user=$(git config user.email) +# get the current user name +current_user_name=$(git config user.name) + +app_list=$(grep "^#" 01-main/manifest ) +# strip the # from the app names +app_list=$(echo $app_list | sed 's/#//g') +#for each app in the list get the time the line was last modified +for app in $app_list +do + # get the last time the app was modified + echo "Checking app: $app" + echo "Blame: $(git blame -1 -e --date short -- 01-main/manifest | grep "${app}$" )" + last_modified=$(git blame -1 -e --date short -- 01-main/manifest | grep "${app}$" | awk '{print $3}') + echo "Last modified: $last_modified" + # get the number of months since the app was last modified + months_since_modified=$(echo $(( ( $(date --date="$current_date" +%s) - $(date --date="$last_modified" +%s) )/(60*60*24*30) ))) + # if the app was last modified more than 6 months ago + echo "App: $app was last modified $months_since_modified months ago" + if [ $months_since_modified -gt 6 ] + then + # add the app to the list of apps that are deprecated + deprecated_apps="$deprecated_apps $app" + fi +done + +echo "Deprecated apps: $deprecated_apps" + +if [ -z "$deprecated_apps" ] +then + echo "No deprecated apps found" + exit 0 +fi + +# create a new branch for the changes +git checkout -b remove_deprecated_apps-${current_date} + +for app in $deprecated_apps +do + # remove the app from the manifest + sed -i "/${app}$/d" 01-main/manifest + # remove the app definition + git rm 01-main/packages/${app} + # commit the change + git commit -am "chore: Removed ${app} from the manifest as it was deprecated more than 6 months ago" +done + +# create a PR for the branch +#hub pull-request -m "chore: Remove deprecated apps" -b deb-get:main -h deb-get:remove_deprecated_apps-${current_date} +gh pr create --title "chore: Remove deprecated apps" --assign philclifford --body "This PR removes the following deprecated apps from the manifest: $deprecated_apps" --base main --head remove_deprecated_apps-${current_date} +# assign the PR to the user who ran the script and deb-get-devs +# gh pr edit --assignee "$current_user_name",deb-get-devs +# switch back to the original branch +git checkout $current_branch +# cleanup + +#git branch -D remove_deprecated_apps-${current_date} + + diff --git a/.github/workflows/proc_deprecated.yml b/.github/workflows/proc_deprecated.yml new file mode 100644 index 00000000..cd443d36 --- /dev/null +++ b/.github/workflows/proc_deprecated.yml @@ -0,0 +1,39 @@ +# This workflow file runs the script every day at midnight. +name: Process Deprecated Apps +on: +# run on demand + workflow_dispatch: + push: + branches: + - test-ci-deprecation-chore +# schedule: +# - cron: '0 0 * * *' +jobs: + process_deprecated_apps: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + - name: Install gh + run: | + curl -sL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg + echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null + sudo apt-get update + sudo apt-get install gh + - name: Run script + run: | + bash .github/workflows/proc_deprecated.sh + +# TODO +# Add a job to find merged PRs matching this pattern that have been closed for more than 7 days and delete the branch +# Add a job to find PRs that have been open for more than 17 days and close them + +# Path: .github/workflows/proc_deprecated.sh +#!/bin/bash + + + \ No newline at end of file