Update PCI Database #60
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }} |