Skip to content

Commit b5f199d

Browse files
committed
ci pip-compile: always create PR when one doesn't exist
Previously, this only would create a PR when the branch was newly created earlier in the workflow (assuming that branches would be deleted once the previous dependency update PR was merged), but it was possible for the branch to already exist but not have a PR open against it. This uses the Github API to properly check whether a PR already exists.
1 parent 3c4b158 commit b5f199d

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

.github/workflows/reusable-pip-compile.yml

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ jobs:
9494
pr_title: "[${{ inputs.base-branch }}] ${{ inputs.message }}"
9595
changed_files: "${{ inputs.changed-files }}"
9696
labels: "${{ inputs.labels }}"
97+
branch_exists: "${{ steps.branch.outputs.branch-exists }}"
9798
run: |
9899
set -x
99100
git diff || :
@@ -107,20 +108,31 @@ jobs:
107108
108109
git commit -m "${message}"
109110
git push --force origin "${pr_branch}"
110-
if [ "${{ steps.branch.outputs.branch-exists }}" = "false" ]
111-
then
112-
command=(gh pr create
113-
--base "${base_branch}"
114-
--title "${pr_title}"
115-
--body ""
116-
--label dependency_update
117-
)
118-
# Add custom labels to the command.
119-
old_ifs="$IFS"
120-
IFS=","
121-
for label in ${labels}; do
122-
command+=("--label" "${label}")
123-
done
124-
IFS="${old_ifs}"
111+
112+
if [ "${branch_exists}" = "true" ]; then
113+
current_pr="$(gh pr list \
114+
--head "${pr_branch}"\
115+
--app ansible-documentation-bot \
116+
--state open \
117+
--json url --jq .[].url \
118+
)"
119+
# https://github.com/cli/cli/discussions/5792#discussioncomment-10410197
120+
if [ -n "${current_pr}" ]; then
121+
echo "PR already exists: ${current_pr}"
122+
exit
123+
fi
125124
fi
125+
command=(gh pr create
126+
--base "${base_branch}"
127+
--title "${pr_title}"
128+
--body ""
129+
--label dependency_update
130+
)
131+
# Add custom labels to the command.
132+
old_ifs="$IFS"
133+
IFS=","
134+
for label in ${labels}; do
135+
command+=("--label" "${label}")
136+
done
137+
IFS="${old_ifs}"
126138
"${command[@]}"

0 commit comments

Comments
 (0)