Skip to content

Commit

Permalink
Target lockfile update PR to source branch
Browse files Browse the repository at this point in the history
Fixes #961
  • Loading branch information
jfrost-mo committed Dec 10, 2024
1 parent 1784279 commit 67ad3c4
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions .github/workflows/conda-lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,43 @@ jobs:
private-key: ${{ secrets.AUTH_APP_PRIVATE_KEY }}

- name: Create pull requests
env:
source_ref: ${{ github.ref }}
source_ref_type: ${{ github.ref_type }}
run: |
shopt -s globstar
# Display any changes in the log.
git diff --name-status
if $(sha256sum --status -c ${{ runner.temp }}/lock_file_hashes); then
# Exit early if there are no changes.
if $(sha256sum --status -c ${{ runner.temp }}/lock_file_hashes)
then
echo "Lock files unchanged. Skipping pull request..."
exit 0
fi
# Update lock_file_hashes so pushed branch name is unique.
sha256sum **/locks/*.txt > ${{ runner.temp }}/lock_file_hashes
# Commit changed lockfiles.
git add **/locks/*.txt
git commit -m "[CI] Update conda lock files"
# Update lock_file_hashes so pushed branch name is unique.
sha256sum **/locks/*.txt > ${{ runner.temp }}/lock_file_hashes
remote_branch_name="conda-lock-$(sha256sum ${{ runner.temp }}/lock_file_hashes | head -c 8)"
# If running from a branch target the created PR at that branch.
if [[ $source_ref_type = branch ]]
then
base_branch_name="$source_ref"
else
base_branch_name="main"
fi
# Push branch to GitHub.
git push --set-upstream origin "conda-lock-files:${remote_branch_name}"
# Create PR on GitHub using GitHub REST API.
request_body='{"title":"[CI] Update conda lock files","body":"Created automatically by GitHub Actions.","base":"main","head":"'"${remote_branch_name}"'"}'
request_body='{"title":"[CI] Update conda lock files","body":"Created automatically by GitHub Actions.","base":"'"${base_branch_name}"'","head":"'"${remote_branch_name}"'"}'
curl -LsS --fail-with-body \
-X POST \
-H "Accept: application/vnd.github+json" \
Expand Down

0 comments on commit 67ad3c4

Please sign in to comment.