Skip to content

Commit f101a68

Browse files
committed
Fix #7 - skip pypi release if the db diff doesn't contain any changes
1 parent 8142f14 commit f101a68

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

.github/workflows/pci-update-workflow.yml

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,53 +33,64 @@ jobs:
3333
run: |
3434
curl -o pci.ids.new https://raw.githubusercontent.com/pciutils/pciids/master/pci.ids
3535
36-
- name: Check for changes
37-
id: check_changes
36+
- name: Check for sha256 change
37+
id: check_sha256
3838
run: |
3939
# Calculate new checksum
4040
NEW_CHECKSUM=$(sha256sum pci.ids.new | cut -d' ' -f1)
4141
4242
# Check if checksum file exists and compare
4343
if [ ! -f pci.ids.sha256 ]; then
44-
echo "No existing checksum file found. Will proceed with update."
44+
echo "Cached checksum file not found. Will proceed with update."
4545
echo "has_changes=true" >> "$GITHUB_OUTPUT"
4646
echo "$NEW_CHECKSUM" > pci.ids.sha256
4747
else
4848
OLD_CHECKSUM=$(cat pci.ids.sha256)
4949
if [ "$NEW_CHECKSUM" != "$OLD_CHECKSUM" ]; then
50-
echo "Changes detected in pci.ids file"
50+
echo "pci.ids checksum is different"
5151
echo "$NEW_CHECKSUM" > pci.ids.sha256
5252
echo "has_changes=true" >> "$GITHUB_OUTPUT"
5353
else
54-
echo "No changes detected in pci.ids file"
54+
echo "No changes detected in pci.ids"
5555
echo "has_changes=false" >> "$GITHUB_OUTPUT"
5656
rm pci.ids.new
5757
exit 0
5858
fi
5959
fi
6060
6161
- name: Update files and generate database
62-
if: steps.check_changes.outputs.has_changes == 'true'
62+
if: steps.check_sha256.outputs.has_changes == 'true'
6363
run: |
6464
mv torchruntime/gpu_pci_ids.db old.db
6565
export PYTHONPATH=$PYTHONPATH:$(pwd)
6666
python scripts/txt_to_db.py pci.ids.new torchruntime/gpu_pci_ids.db
6767
6868
- name: Get the DB diff
69-
if: steps.check_changes.outputs.has_changes == 'true'
69+
id: check_db_diff
70+
if: steps.check_sha256.outputs.has_changes == 'true'
7071
run: |
7172
python scripts/sqldiff.py old.db torchruntime/gpu_pci_ids.db > db_diff.txt
73+
diff_count=$(cat db_diff.txt | wc -l)
74+
if [ "$diff_count" -eq "0" ]; then
75+
echo "No changes detected in db diff"
76+
echo "has_changes=false" >> "$GITHUB_OUTPUT"
77+
exit 0
78+
else
79+
echo "db diff is different"
80+
cat db_diff.txt
81+
echo "has_changes=true" >> "$GITHUB_OUTPUT"
82+
fi
7283
echo 'DIFF_OUTPUT<<EOF' >> $GITHUB_ENV
7384
cat db_diff.txt >> $GITHUB_ENV
7485
echo 'EOF' >> $GITHUB_ENV
7586
7687
- name: Run tests
77-
if: steps.check_changes.outputs.has_changes == 'true'
88+
if: steps.check_db_diff.outputs.has_changes == 'true'
7889
run: |
7990
python -m pytest
8091
8192
- name: Update version in pyproject.toml
82-
if: steps.check_changes.outputs.has_changes == 'true'
93+
if: steps.check_db_diff.outputs.has_changes == 'true'
8394
id: update_version
8495
run: |
8596
python - <<EOF
@@ -111,19 +122,19 @@ jobs:
111122
ls -l torchruntime/gpu_pci_ids.db
112123
113124
- name: Configure Git
114-
if: steps.check_changes.outputs.has_changes == 'true'
125+
if: steps.check_db_diff.outputs.has_changes == 'true'
115126
run: |
116127
git config --local user.email "github-actions[bot]@users.noreply.github.com"
117128
git config --local user.name "github-actions[bot]"
118129
119130
- name: Commit changes
120-
if: steps.check_changes.outputs.has_changes == 'true'
131+
if: steps.check_db_diff.outputs.has_changes == 'true'
121132
run: |
122133
git add pci.ids.sha256 torchruntime/gpu_pci_ids.db pyproject.toml
123134
git commit -m "Update PCI database, raw data file and version"
124135
125136
- name: Create Release
126-
if: steps.check_changes.outputs.has_changes == 'true'
137+
if: steps.check_db_diff.outputs.has_changes == 'true'
127138
uses: softprops/action-gh-release@v1
128139
with:
129140
tag_name: v${{ steps.update_version.outputs.new_version }}
@@ -136,7 +147,7 @@ jobs:
136147
prerelease: false
137148

138149
- name: Push changes
139-
if: steps.check_changes.outputs.has_changes == 'true'
150+
if: steps.check_db_diff.outputs.has_changes == 'true'
140151
run: git push && git push --tags
141152

142153
- name: Cleanup

scripts/sqldiff.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,21 @@
2323
cols = cursor1.execute(COL_NAME_QUERY).fetchall()
2424
cols = tuple(col[1] for col in cols)
2525

26-
print("### Additions")
27-
print("```")
28-
print(cols)
29-
for row in res2 - res1:
30-
print(row)
31-
print("```")
32-
33-
print("### Deletions")
34-
print("```")
35-
print(cols)
36-
for row in res1 - res2:
37-
print(row)
38-
print("```")
26+
additions = res2 - res1
27+
deletions = res1 - res2
28+
29+
if additions:
30+
print("### Additions")
31+
print("```")
32+
print(cols)
33+
for row in additions:
34+
print(row)
35+
print("```")
36+
37+
if deletions:
38+
print("### Deletions")
39+
print("```")
40+
print(cols)
41+
for row in deletions:
42+
print(row)
43+
print("```")

0 commit comments

Comments
 (0)