-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jason Munro
authored
May 9, 2023
1 parent
aa93193
commit 94a30fd
Showing
1 changed file
with
88 additions
and
0 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,88 @@ | ||
name: Upgrade Dependencies | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
upgrade: | ||
name: ${{ matrix.package }} (${{ matrix.os }}/py${{ matrix.python-version }}) | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: ['ubuntu-latest', 'macos-latest', 'windows-latest'] | ||
package: ["mp-api"] | ||
python-version: ["3.8", "3.9", "3.10"] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
cache: 'pip' | ||
- name: Upgrade Python dependencies | ||
shell: bash | ||
run: | | ||
python -m pip install --upgrade pip pip-tools | ||
cd ${{ matrix.package }} | ||
python -m piptools compile -q --upgrade --resolver=backtracking -o requirements/requirements-${{ matrix.os }}_py${{ matrix.python-version }}.txt pyproject.toml | ||
python -m piptools compile -q --upgrade --resolver=backtracking --all-extras -o requirements/requirements-${{ matrix.os }}_py${{ matrix.python-version }}_extras.txt pyproject.toml | ||
- name: Detect changes | ||
id: changes | ||
shell: bash | ||
run: | | ||
echo "count=$(git diff-index HEAD | wc -l | xargs)" >> $GITHUB_OUTPUT | ||
echo "files=$(git ls-files --exclude-standard --others | wc -l | xargs)" >> $GITHUB_OUTPUT | ||
- name: commit & push changes | ||
if: steps.changes.outputs.count > 0 || steps.changes.outputs.files > 0 | ||
shell: bash | ||
run: | | ||
git config user.name github-actions | ||
git config user.email [email protected] | ||
git add ${{ matrix.package }}/requirements/requirements-${{ matrix.os }}.txt | ||
git add ${{ matrix.package }}/requirements/requirements-${{ matrix.os }}-dev.txt | ||
git commit -m "Update ${{ matrix.os }} dependencies for ${{ matrix.package }}" | ||
git push -f origin ${{ github.ref_name }}:auto-dependency-upgrades-${{ matrix.package }}-${{ matrix.os }}-py${{ matrix.python-version }} | ||
pull_request: | ||
name: Merge all branches and open PR | ||
runs-on: ubuntu-latest | ||
needs: upgrade | ||
strategy: | ||
matrix: | ||
python-version: ["3.10"] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: detect auto-upgrade-dependency branches | ||
id: changes | ||
run: echo "count=$(git branch -r | grep auto-dependency-upgrades- | wc -l | xargs)" >> $GITHUB_OUTPUT | ||
- name: merge all auto-dependency-upgrades branches | ||
if: steps.changes.outputs.count > 0 | ||
run: | | ||
git config user.name github-actions | ||
git config user.email [email protected] | ||
git checkout -b auto-dependency-upgrades | ||
git branch -r | grep auto-dependency-upgrades- | xargs -I {} git merge {} | ||
git rebase ${GITHUB_REF##*/} | ||
git push -f origin auto-dependency-upgrades | ||
git branch -r | grep auto-dependency-upgrades- | cut -d/ -f2 | xargs -I {} git push origin :{} | ||
- name: Open pull request if needed | ||
if: steps.changes.outputs.count > 0 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.VER_BUMP_TOKEN }} | ||
# Only open a PR if the branch is not attached to an existing one | ||
run: | | ||
PR=$(gh pr list --head auto-dependency-upgrades --json number -q '.[0].number') | ||
if [ -z $PR ]; then | ||
gh pr create \ | ||
--head auto-dependency-upgrades \ | ||
--title "Automated dependency upgrades" \ | ||
--body "Full log: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} (THIS IS AN AUTOMATED COMMENT)" | ||
else | ||
echo "Pull request already exists, won't create a new one." | ||
fi |