fix: rearange instead of delete nested compoents #766
This file contains 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: Dependabot pre-commit updater | |
on: pull_request | |
permissions: | |
contents: read | |
jobs: | |
dependabot: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
if: github.actor == 'dependabot[bot]' | |
steps: | |
- name: Dependabot metadata | |
id: metadata | |
uses: dependabot/fetch-metadata@dbb049abf0d677abbd7f7eee0375145b417fdd34 # v2.2.0 | |
with: | |
github-token: "${{ secrets.GITHUB_TOKEN }}" | |
- name: Set up SSH | |
uses: webfactory/ssh-agent@dc588b651fe13675774614f8e6a936a468676387 # v0.9.0 | |
with: | |
ssh-private-key: ${{ secrets.COMMIT_KEY }} | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
# Check out HEAD of source branch. Without this option, the merge commit would be checked out. | |
ref: ${{ github.event.pull_request.head.ref }} | |
- name: Update .pre-commit-config.yaml | |
id: update-pre-commit | |
run: | | |
# Reduces the output of the metadata step above to a simpler JSON format: | |
# { "<package-1-name>": "<new-version>", ... } | |
export updates=$(yq --null-input 'env(updates) | .[] as $item ireduce ({}; .[$item | .dependencyName] = ($item | .newVersion))' -o json) | |
# Goes through the dependencies of the mypy hook in pre-commit config and if any of them have | |
# been updated in this PR, replace the version number with the new version | |
yq --inplace 'env(updates) as $up | (.repos[].hooks[] | select(.id == "mypy").additional_dependencies[] | select(split("==") | .[0] as $pkg | $up | has ($pkg))) |= (split("==") | .[0] as $pkg | $pkg + "==" + $up[$pkg])' .pre-commit-config.yaml | |
# Commit the changes | |
git add .pre-commit-config.yaml | |
if ! git diff-index --cached --quiet HEAD -- | |
then | |
echo "::notice::Committing changes" | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git remote set-url origin "[email protected]:${{ github.repository }}.git" | |
git commit -m "Update additional dependencies for mypy pre-commit hook" | |
git push | |
else | |
echo "::notice::No changes made" | |
fi | |
env: | |
updates: ${{ steps.metadata.outputs.updated-dependencies-json }} |