|
| 1 | +name: Check apt dependencies for updates |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 0 * * 0' # Run weekly on Sunday at midnight |
| 6 | + workflow_dispatch: # Allow manual triggering |
| 7 | + |
| 8 | +jobs: |
| 9 | + check-apt-updates: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Checkout code |
| 13 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 14 | + |
| 15 | + - name: Check for apt package updates |
| 16 | + run: | |
| 17 | + # Create a list of all pinned apt packages from github workflow files |
| 18 | + grep -r "apt-get install" .github/workflows/ | grep -o "[a-zA-Z0-9\-\._+~:]*=[a-zA-Z0-9\.\-+~:]*" > pinned_apt_packages.txt |
| 19 | + |
| 20 | + # Create report file header |
| 21 | + echo "# Apt Package Update Report" > apt_update_report.md |
| 22 | + echo "Generated on $(date)" >> apt_update_report.md |
| 23 | + echo "" >> apt_update_report.md |
| 24 | + |
| 25 | + if [ -s pinned_apt_packages.txt ]; then |
| 26 | + echo "Checking these pinned apt packages for updates:" |
| 27 | + cat pinned_apt_packages.txt |
| 28 | + |
| 29 | + echo "## Pinned Packages" >> apt_update_report.md |
| 30 | + echo "" >> apt_update_report.md |
| 31 | + echo "| Package | Current Version | Latest Version | Update Available |" >> apt_update_report.md |
| 32 | + echo "|---------|----------------|---------------|-----------------|" >> apt_update_report.md |
| 33 | + |
| 34 | + # Update apt database |
| 35 | + sudo apt-get update |
| 36 | + |
| 37 | + updates_available=false |
| 38 | + |
| 39 | + # Check each package for available updates |
| 40 | + while read package; do |
| 41 | + pkg_name=${package%=*} |
| 42 | + current_version=${package#*=} |
| 43 | + available_version=$(apt-cache policy $pkg_name | grep Candidate | awk '{print $2}') |
| 44 | + |
| 45 | + echo "Package: $pkg_name" |
| 46 | + echo " Current pinned version: $current_version" |
| 47 | + echo " Latest available version: $available_version" |
| 48 | + echo "" |
| 49 | + |
| 50 | + if [ "$current_version" != "$available_version" ]; then |
| 51 | + update_status="Yes" |
| 52 | + updates_available=true |
| 53 | + else |
| 54 | + update_status="No" |
| 55 | + fi |
| 56 | + |
| 57 | + echo "| $pkg_name | $current_version | $available_version | $update_status |" >> apt_update_report.md |
| 58 | + done < pinned_apt_packages.txt |
| 59 | + |
| 60 | + echo "" >> apt_update_report.md |
| 61 | + if [ "$updates_available" = true ]; then |
| 62 | + echo "## Action Required" >> apt_update_report.md |
| 63 | + echo "Please update the pinned versions in the workflow files to the latest available versions." >> apt_update_report.md |
| 64 | + else |
| 65 | + echo "## No Action Required" >> apt_update_report.md |
| 66 | + echo "All pinned packages are up to date." >> apt_update_report.md |
| 67 | + fi |
| 68 | + |
| 69 | + echo "Check complete. Manual update required for any outdated packages." |
| 70 | + else |
| 71 | + echo "No pinned apt packages found in workflow files." |
| 72 | + echo "## No Pinned Packages Found" >> apt_update_report.md |
| 73 | + echo "No pinned apt packages were found in the workflow files." >> apt_update_report.md |
| 74 | + fi |
| 75 | + |
| 76 | + - name: Create issue for outdated packages |
| 77 | + if: ${{ success() }} |
| 78 | + uses: peter-evans/create-issue-from-file@v5.0.1 # v5.0.1 |
| 79 | + with: |
| 80 | + title: Outdated apt packages in workflows |
| 81 | + content-filepath: ./apt_update_report.md |
| 82 | + labels: dependencies, apt |
0 commit comments