Update Dependency #12
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 Dependency | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| dependency: | |
| description: "Name of the dependency to update" | |
| required: true | |
| type: string | |
| version: | |
| description: "New version of the dependency" | |
| required: true | |
| type: string | |
| bump_type: | |
| description: "Type of version bump to perform after updating dependency" | |
| type: choice | |
| required: true | |
| default: "minor" | |
| options: ["major", "minor", "patch"] | |
| jobs: | |
| update-dependency: | |
| name: Update ${{ github.event.inputs.dependency }} dependency | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Update dependency in requirements.txt | |
| run: | | |
| echo "Updating ${{ github.event.inputs.dependency }} to version ${{ github.event.inputs.version }}" | |
| # Update in requirements.txt if it exists | |
| if [ -f "requirements.txt" ]; then | |
| sed -i "s/^${{ github.event.inputs.dependency }}==.*/${{ github.event.inputs.dependency }}==${{ github.event.inputs.version }}/" requirements.txt | |
| echo "Updated requirements.txt" | |
| fi | |
| # Update in requirements.in if it exists | |
| if [ -f "requirements.in" ]; then | |
| sed -i "s/^${{ github.event.inputs.dependency }}.*/${{ github.event.inputs.dependency }}>=${{ github.event.inputs.version }}/" requirements.in | |
| echo "Updated requirements.in" | |
| fi | |
| # Update in setup.py if it exists | |
| if [ -f "setup.py" ]; then | |
| sed -i "s/'${{ github.event.inputs.dependency }}[^']*'/'${{ github.event.inputs.dependency }}>=${{ github.event.inputs.version }}'/g" setup.py | |
| sed -i "s/\"${{ github.event.inputs.dependency }}[^\"]*\"/\"${{ github.event.inputs.dependency }}>=${{ github.event.inputs.version }}\"/g" setup.py | |
| echo "Updated setup.py" | |
| fi | |
| - name: Verify dependency availability | |
| run: | | |
| echo "Verifying ${{ github.event.inputs.dependency }}==${{ github.event.inputs.version }} is available on PyPI..." | |
| # Retry pip index lookup up to 3 times with delays | |
| for i in {1..3}; do | |
| echo "Attempt $i/3: Checking PyPI availability..." | |
| if pip index versions ${{ github.event.inputs.dependency }} | grep -q "${{ github.event.inputs.version }}"; then | |
| echo "✅ Package version found on PyPI on attempt $i" | |
| break | |
| else | |
| echo "❌ Package version not found on PyPI on attempt $i" | |
| if [ $i -lt 3 ]; then | |
| echo "Waiting 30 seconds before retry..." | |
| sleep 30 | |
| else | |
| echo "Package still not available after retries, continuing anyway..." | |
| fi | |
| fi | |
| done | |
| - name: Commit dependency update | |
| run: | | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git add -A | |
| git diff --staged --quiet || git commit -m "Update ${{ github.event.inputs.dependency }} to v${{ github.event.inputs.version }} | |
| Auto-generated dependency update triggered by ${{ github.event.inputs.dependency }} release" | |
| git push | |
| release: | |
| name: Release with updated dependency | |
| needs: update-dependency | |
| uses: ./.github/workflows/release.yml | |
| with: | |
| part: ${{ github.event.inputs.bump_type }} | |
| dry-run: false | |
| secrets: inherit |