Skip to content

Commit 89d9e27

Browse files
committed
ci(apt-update): fix apt package grep regexp
1 parent fc3f1dd commit 89d9e27

1 file changed

Lines changed: 72 additions & 19 deletions

File tree

.github/workflows/dependabot-apt-update.yml

Lines changed: 72 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,71 +16,124 @@ jobs:
1616
steps:
1717
- name: Checkout code
1818
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
19-
19+
2020
- name: Check for apt package updates
21+
id: check-updates
2122
run: |
2223
# Create a list of all pinned apt packages from github workflow files
23-
grep -r "apt-get install" .github/workflows/ | grep -o "[a-zA-Z0-9\-\._+~:]*=[a-zA-Z0-9\.\-+~:]*" > pinned_apt_packages.txt
24-
24+
# Exclude the current workflow file and ensure package names are not empty
25+
grep -r "apt-get install" .github/workflows/ --exclude="dependabot-apt-update.yml" | grep -o "[a-zA-Z0-9_.:+~-]\+=[a-zA-Z0-9_.:+~-]\+" > pinned_apt_packages.txt
26+
2527
# Create report file header
2628
echo "# Apt Package Update Report" > apt_update_report.md
2729
echo "Generated on $(date)" >> apt_update_report.md
2830
echo "" >> apt_update_report.md
29-
31+
3032
if [ -s pinned_apt_packages.txt ]; then
3133
echo "Checking these pinned apt packages for updates:"
3234
cat pinned_apt_packages.txt
33-
35+
3436
echo "## Pinned Packages" >> apt_update_report.md
3537
echo "" >> apt_update_report.md
3638
echo "| Package | Current Version | Latest Version | Update Available |" >> apt_update_report.md
3739
echo "|---------|----------------|---------------|-----------------|" >> apt_update_report.md
38-
40+
3941
# Update apt database
4042
sudo apt-get update
41-
43+
4244
updates_available=false
43-
45+
4446
# Check each package for available updates
4547
while read package; do
4648
pkg_name=${package%=*}
4749
current_version=${package#*=}
50+
51+
# Skip empty package names
52+
if [ -z "$pkg_name" ]; then
53+
continue
54+
fi
55+
4856
available_version=$(apt-cache policy $pkg_name | grep Candidate | awk '{print $2}')
49-
57+
5058
echo "Package: $pkg_name"
5159
echo " Current pinned version: $current_version"
5260
echo " Latest available version: $available_version"
5361
echo ""
54-
62+
5563
if [ "$current_version" != "$available_version" ]; then
5664
update_status="Yes"
5765
updates_available=true
5866
else
5967
update_status="No"
6068
fi
61-
69+
6270
echo "| $pkg_name | $current_version | $available_version | $update_status |" >> apt_update_report.md
6371
done < pinned_apt_packages.txt
64-
72+
6573
echo "" >> apt_update_report.md
6674
if [ "$updates_available" = true ]; then
6775
echo "## Action Required" >> apt_update_report.md
6876
echo "Please update the pinned versions in the workflow files to the latest available versions." >> apt_update_report.md
77+
echo "updates_available=true" >> $GITHUB_OUTPUT
78+
echo "Check complete. Manual update required for outdated packages."
6979
else
7080
echo "## No Action Required" >> apt_update_report.md
7181
echo "All pinned packages are up to date." >> apt_update_report.md
82+
echo "updates_available=false" >> $GITHUB_OUTPUT
83+
echo "Check complete. No manual update required."
7284
fi
73-
74-
echo "Check complete. Manual update required for any outdated packages."
85+
7586
else
76-
echo "No pinned apt packages found in workflow files."
87+
echo "No pinned apt packages found in workflow files."
7788
echo "## No Pinned Packages Found" >> apt_update_report.md
7889
echo "No pinned apt packages were found in the workflow files." >> apt_update_report.md
90+
echo "updates_available=false" >> $GITHUB_OUTPUT
7991
fi
80-
81-
- name: Create issue for outdated packages
82-
if: ${{ success() }}
83-
uses: peter-evans/create-issue-from-file@v5.0.1 # v5.0.1
92+
93+
- name: Check for existing issues
94+
id: check-issues
95+
if: steps.check-updates.outputs.updates_available == 'true'
96+
uses: actions/github-script@v6
97+
with:
98+
script: |
99+
const issueTitle = 'Outdated apt packages in workflows';
100+
const issues = await github.rest.issues.listForRepo({
101+
owner: context.repo.owner,
102+
repo: context.repo.repo,
103+
state: 'open',
104+
labels: 'dependencies,apt'
105+
});
106+
107+
const existingIssue = issues.data.find(issue => issue.title === issueTitle);
108+
if (existingIssue) {
109+
console.log(`Found existing issue #${existingIssue.number}`);
110+
core.exportVariable('ISSUE_NUMBER', existingIssue.number);
111+
core.exportVariable('ISSUE_EXISTS', 'true');
112+
} else {
113+
console.log('No existing issue found');
114+
core.exportVariable('ISSUE_EXISTS', 'false');
115+
}
116+
117+
- name: Update existing issue
118+
if: steps.check-updates.outputs.updates_available == 'true' && env.ISSUE_EXISTS == 'true'
119+
uses: actions/github-script@v6
120+
with:
121+
script: |
122+
const fs = require('fs');
123+
const issueNumber = parseInt(process.env.ISSUE_NUMBER);
124+
const content = fs.readFileSync('./apt_update_report.md', 'utf8');
125+
126+
await github.rest.issues.update({
127+
owner: context.repo.owner,
128+
repo: context.repo.repo,
129+
issue_number: issueNumber,
130+
body: content
131+
});
132+
console.log(`Updated issue #${issueNumber}`);
133+
134+
- name: Create new issue for outdated packages
135+
if: steps.check-updates.outputs.updates_available == 'true' && env.ISSUE_EXISTS == 'false'
136+
uses: peter-evans/create-issue-from-file@v5.0.1
84137
with:
85138
title: Outdated apt packages in workflows
86139
content-filepath: ./apt_update_report.md

0 commit comments

Comments
 (0)