-
Notifications
You must be signed in to change notification settings - Fork 5
150 lines (127 loc) · 5.05 KB
/
pci-update-workflow.yml
File metadata and controls
150 lines (127 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
name: Update PCI Database
on:
workflow_dispatch:
# Run weekly on Thursday at 3:14 AM UTC
schedule:
- cron: '14 3 * * 4'
jobs:
update-db:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Required for getting tags
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install toml pytest
- name: Create raw_data directory if it doesn't exist
run: mkdir -p raw_data
- name: Download latest pci.ids
run: |
curl -o pci.ids.new https://raw.githubusercontent.com/pciutils/pciids/master/pci.ids
- name: Check for sha256 change
id: check_sha256
run: |
# Calculate new checksum
NEW_CHECKSUM=$(sha256sum pci.ids.new | cut -d' ' -f1)
# Check if checksum file exists and compare
if [ ! -f pci.ids.sha256 ]; then
echo "Cached checksum file not found. Will proceed with update."
echo "has_changes=true" >> "$GITHUB_OUTPUT"
echo "$NEW_CHECKSUM" > pci.ids.sha256
else
OLD_CHECKSUM=$(cat pci.ids.sha256)
if [ "$NEW_CHECKSUM" != "$OLD_CHECKSUM" ]; then
echo "pci.ids checksum is different"
echo "$NEW_CHECKSUM" > pci.ids.sha256
echo "has_changes=true" >> "$GITHUB_OUTPUT"
else
echo "No changes detected in pci.ids"
echo "has_changes=false" >> "$GITHUB_OUTPUT"
rm pci.ids.new
exit 0
fi
fi
- name: Update files and generate database
if: steps.check_sha256.outputs.has_changes == 'true'
run: |
mv torchruntime/gpu_pci_ids.db old.db
export PYTHONPATH=$PYTHONPATH:$(pwd)
python scripts/txt_to_db.py pci.ids.new torchruntime/gpu_pci_ids.db
- name: Get the DB diff
id: check_db_diff
if: steps.check_sha256.outputs.has_changes == 'true'
run: |
python scripts/sqldiff.py old.db torchruntime/gpu_pci_ids.db > db_diff.txt
diff_count=$(cat db_diff.txt | wc -l)
if [ "$diff_count" -eq "0" ]; then
echo "No changes detected in db diff"
echo "has_changes=false" >> "$GITHUB_OUTPUT"
exit 0
else
echo "db diff is different"
cat db_diff.txt
echo "has_changes=true" >> "$GITHUB_OUTPUT"
fi
echo 'DIFF_OUTPUT<<EOF' >> $GITHUB_ENV
cat db_diff.txt >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Run tests
if: steps.check_db_diff.outputs.has_changes == 'true'
run: |
python -m pytest
- name: Update version in pyproject.toml
if: steps.check_db_diff.outputs.has_changes == 'true'
id: update_version
run: |
python - <<EOF
import toml
import os
# Read the current pyproject.toml
with open('pyproject.toml', 'r') as f:
config = toml.load(f)
# Get current version and increment minor version
current_version = config['project']['version']
major, minor, patch = current_version.split('.')
new_version = f"{major}.{int(minor) + 1}.0"
# Update version in config
config['project']['version'] = new_version
# Write back to pyproject.toml
with open('pyproject.toml', 'w') as f:
toml.dump(config, f)
# Set output for later steps
print(f"new_version={new_version}", file=open(os.environ['GITHUB_OUTPUT'], 'a'))
EOF
cat pyproject.toml
cat pci.ids.sha256
ls -l torchruntime/gpu_pci_ids.db
- name: Configure Git
if: steps.check_db_diff.outputs.has_changes == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
- name: Commit changes
if: steps.check_db_diff.outputs.has_changes == 'true'
run: |
git add pci.ids.sha256 torchruntime/gpu_pci_ids.db pyproject.toml
git commit -m "Update PCI database, raw data file and version"
- name: Push changes
if: steps.check_db_diff.outputs.has_changes == 'true'
run: git push
- name: Create Release
if: steps.check_db_diff.outputs.has_changes == 'true'
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.update_version.outputs.new_version }}
name: v${{ steps.update_version.outputs.new_version }}
body: |
Automatic update of PCI database. Install using `pip install --upgrade torchruntime==${{ steps.update_version.outputs.new_version }}`
${{ env.DIFF_OUTPUT }}
token: ${{ secrets.CUSTOM_GITHUB_TOKEN }}