Skip to content

Update environment.lock workflow to raise PR #655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion .github/workflows/update-environment-lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: mamba-org/setup-micromamba@v2
with:
environment-file: ./environment.yml
Expand All @@ -28,9 +30,40 @@ jobs:
- name: Run sagemaker-distribution unit tests to check for regressions
run: pytest -m unit
- name: Commit changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
BRANCH_NAME=environment-lock-bot
# Check if branch exists remotely
if git ls-remote --heads origin $BRANCH_NAME | grep -q $BRANCH_NAME; then
echo "Branch exists, checking out and updating"
git checkout $BRANCH_NAME
git pull origin $BRANCH_NAME
# Merge main to get latest changes
git merge origin/main --no-edit
else
echo "Creating new branch"
git checkout -b $BRANCH_NAME
fi
# Check if there are changes to commit
if git diff --quiet environment.lock; then
echo "No changes to environment.lock file"
exit 0
fi
git add environment.lock
git commit -m 'Update environment.lock'
git push
git push origin $BRANCH_NAME

# Create PR if it doesn't exist
if ! gh pr list --head $BRANCH_NAME --json number | grep -q "number"; then
gh pr create \
--title "Update environment.lock" \
--body "Automated update of environment.lock file" \
--base main \
--head $BRANCH_NAME \
--label "dependencies"
else
echo "PR already exists, skipping creation"
fi