-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1356 from pyiron/dependabot_pr_update
Update workflow for dependabot PRs
- Loading branch information
Showing
3 changed files
with
112 additions
and
33 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"tables": "pytables", | ||
"pyiron-base": "pyiron_base", | ||
"pyiron-atomistics": "pyiron_atomistics", | ||
"pyiron-contrib": "pyiron_contrib", | ||
"pyiron-experimental": "pyiron_experimental", | ||
"pyiron-continuum": "pyiron_continuum", | ||
"pyiron-gpl": "pyiron_gpl", | ||
"pyiron-gui": "pyiron_gui" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# coding: utf-8 | ||
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department | ||
# Distributed under the terms of "New BSD License", see the LICENSE file. | ||
|
||
import json | ||
import re | ||
import sys | ||
|
||
import yaml | ||
|
||
environment_file = '.ci_support/environment.yml' | ||
name_mapping_file = '.ci_support/pypi_vs_conda_names.json' | ||
|
||
|
||
class EnvironmentUpdater: | ||
def __init__(self, package_name, from_version, to_version): | ||
""" | ||
Updates the version of a package in the conda environment file. | ||
Parameters: | ||
package_name: Name of the package to update as available on PyPI | ||
from_version: Version the package is before the update | ||
to_version: Version to which the package should be updated | ||
""" | ||
self.from_version = from_version | ||
self.to_version = to_version | ||
with open(name_mapping_file, 'r') as f: | ||
self._name_conversion_dict = json.load(f) | ||
|
||
with open(environment_file, 'r') as f: | ||
self.environment = yaml.safe_load(f) | ||
|
||
self.package_name = self._convert_package_name(package_name) | ||
|
||
def _convert_package_name(self, name): | ||
if name in self._name_conversion_dict.keys(): | ||
result = self._name_conversion_dict[name] | ||
else: | ||
result = name | ||
return result | ||
|
||
def _update_dependencies(self): | ||
updated_dependencies = [] | ||
|
||
for dep in self.environment['dependencies']: | ||
updated_dependencies.append(re.sub( | ||
r'(' + self.package_name + '.*)' + self.from_version, | ||
r'\g<1>' + self.to_version, | ||
dep | ||
)) | ||
|
||
self.environment['dependencies'] = updated_dependencies | ||
|
||
def _write(self): | ||
with open(environment_file, 'w') as f: | ||
yaml.safe_dump(self.environment, f) | ||
|
||
def update_dependencies(self): | ||
"""Update the version of the requested dependency in the environment file""" | ||
self._update_dependencies() | ||
self._write() | ||
|
||
|
||
if len(sys.argv) != 7 or not (sys.argv[1] == 'Bump' and sys.argv[3] == 'from' and sys.argv[5] == 'to'): | ||
raise ValueError(f"Title of a dependabot PR 'Bump <package> from <version> to <version>' expected, " | ||
f"but got {' '.join(sys.argv[1:])}") | ||
package_to_update = sys.argv[2] | ||
from_version = sys.argv[4] | ||
to_version = sys.argv[6] | ||
|
||
updater = EnvironmentUpdater(package_to_update, from_version, to_version) | ||
updater.update_dependencies() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,30 @@ | ||
name: UpdateDependabotPR | ||
|
||
on: | ||
pull_request_target: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
if: (github.actor == 'dependabot[bot]') | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.event.pull_request.head.ref }} # Check out the head of the actual branch, not the PR | ||
fetch-depth: 0 # otherwise, you will fail to push refs to dest repo | ||
token: ${{ secrets.DEPENDABOT_WORKFLOW_TOKEN }} | ||
- name: UpdateEnvironmentFile | ||
shell: bash -l {0} | ||
run: | | ||
package=$(echo "${{ github.event.pull_request.title }}" | awk '{print $2}') | ||
from=$(echo "${{ github.event.pull_request.title }}" | awk '{print $4}') | ||
to=$(echo "${{ github.event.pull_request.title }}" | awk '{print $6}') | ||
sed -i "/${package}/s/${from}/${to}/g" .ci_support/environment.yml | ||
- name: UpdateDependabotPR commit | ||
run: | | ||
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
git config --local user.name "github-actions[bot]" | ||
git commit -m "[dependabot skip] Update environment" -a | ||
- name: UpdateDependabotPR push | ||
uses: ad-m/github-push-action@master | ||
with: | ||
github_token: ${{ secrets.DEPENDABOT_WORKFLOW_TOKEN }} | ||
branch: ${{ github.event.pull_request.head.ref }} | ||
name: UpdateDependabotPR | ||
|
||
on: | ||
pull_request_target: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
if: (github.actor == 'dependabot[bot]') | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.event.pull_request.head.ref }} # Check out the head of the actual branch, not the PR | ||
fetch-depth: 0 # otherwise, you will fail to push refs to dest repo | ||
token: ${{ secrets.DEPENDABOT_WORKFLOW_TOKEN }} | ||
- name: UpdateEnvironmentFile | ||
shell: bash -l {0} | ||
run: | | ||
python .ci_support/update_environment.py ${{ github.event.pull_request.title }} | ||
- name: UpdateDependabotPR commit | ||
run: | | ||
git config --local user.email "pyiron@mpie.de" | ||
git config --local user.name "pyiron-runner" | ||
git commit -m "[dependabot skip] Update environment" -a | ||
- name: UpdateDependabotPR push | ||
uses: ad-m/github-push-action@master | ||
with: | ||
github_token: ${{ secrets.DEPENDABOT_WORKFLOW_TOKEN }} | ||
branch: ${{ github.event.pull_request.head.ref }} |