update dep workflow github compare link (#35212)
This commit is contained in:
@@ -40,6 +40,15 @@ jobs:
|
||||
|
||||
SED=sed
|
||||
|
||||
get_dep_url() {
|
||||
sed -n '/deps = {/, /^}/p' DEPS | sed 's/deps = //' |
|
||||
python3 -c "import sys, ast; d=ast.literal_eval(sys.stdin.read()); dep=d[\"$1\"]; print(dep) if isinstance(dep, str) else print(dep.get(\"url\"))"
|
||||
}
|
||||
|
||||
get_dep_repo() {
|
||||
echo "$1" | grep -Po '(?<=github.com\/).*?(?=\.git)?(?=@)' | sed 's/\.git//'
|
||||
}
|
||||
|
||||
# Inputs
|
||||
DEP="${{ inputs.dep }}"
|
||||
DEPREF="${{ inputs.ref }}"
|
||||
@@ -47,12 +56,7 @@ jobs:
|
||||
[[ "${DEP:?}" =~ ^[a-zA-Z/-]+$ ]] || { echo "Input dependency validation failed"; exit 1; }
|
||||
if [[ -z "${DEPREF}" ]]; then
|
||||
echo "Attempting to guess ref hash"
|
||||
DEP_REPO=$(\
|
||||
sed -n '/deps = {/, /^}/p' DEPS|\
|
||||
sed 's/deps = //'|\
|
||||
python3 -c "import sys,ast; d=ast.literal_eval(sys.stdin.read()); dep=d[\""$DEP"\"]; print(dep) if isinstance(dep, str) else print(dep.get(\"url\"))"|\
|
||||
grep -Po '(?<=github.com\/).*?(?=\.git)?(?=@)'|\
|
||||
sed 's/\.git//')
|
||||
DEP_REPO=$(get_dep_repo "$(get_dep_url "$DEP")")
|
||||
gh api /repos/"${DEP_REPO}"/commits/master -q .sha > /tmp/DEPREF || gh api /repos/"${DEP_REPO}"/commits/main -q .sha > /tmp/DEPREF
|
||||
DEPREF=$(</tmp/DEPREF)
|
||||
fi
|
||||
@@ -68,8 +72,13 @@ jobs:
|
||||
for branch in "${branches[@]}"
|
||||
do
|
||||
git switch "$branch"
|
||||
# Current dep URL on this branch (before bump) — used for compare link in PR body
|
||||
DEP_URL=$(get_dep_url "$DEP")
|
||||
DEP_REPO=$(get_dep_repo "$DEP_URL")
|
||||
OLD_REF="${DEP_URL##*@}"
|
||||
|
||||
pr_branch="update-dep-${branch}-${DEP}-${DEPREF}"
|
||||
if git rev-parse --verify "$pr_branch"; then continue; fi # Skip duplicate
|
||||
if git rev-parse --verify "$pr_branch" 2>/dev/null; then continue; fi # Skip duplicate
|
||||
git switch -c "$pr_branch"
|
||||
"$SED" -i -e "s,^\(\s*\"$DEP\"\s*:\s*\"https.*\)@[^\"]*\",\1@$DEPREF\"," \
|
||||
-e "/^\s*\"${DEP//\//\\/}\"\s*:\s*{/,/@/ s/@[^\"]*/@$DEPREF/" DEPS
|
||||
@@ -83,5 +92,6 @@ jobs:
|
||||
--field sha="$(git rev-parse "$pr_branch:DEPS")"
|
||||
git restore DEPS
|
||||
git pull
|
||||
gh pr create --base "${branch}" -f -t "Update dependency ${DEP}@${DEPREF}" -l "CI/run-audit-deps"
|
||||
PR_BODY="https://github.com/${DEP_REPO}/compare/${OLD_REF}...${DEPREF}"
|
||||
gh pr create --base "${branch}" -t "Update dependency ${DEP}@${DEPREF}" -b "${PR_BODY}" -l "CI/run-audit-deps"
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user