@@ -31,18 +31,21 @@ jobs:
3131 ver="${tag#v}"
3232 echo "version=$ver" >> $GITHUB_OUTPUT
3333
34- - name : Install tooling (jq, yq, gh )
34+ - name : Install tooling (jq, gh, Python deps )
3535 run : |
3636 sudo apt-get update -y
37- sudo apt-get install -y jq
38- curl -sSL https://github.com/mikefarah/yq/releases/download/v4.44.3/yq_linux_amd64 -o yq
39- sudo install -m 0755 yq /usr/local/bin/yq
40- type -p gh >/dev/null || ( curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \
41- | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg && \
42- sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg && \
37+ sudo apt-get install -y jq python3-pip
38+ # gh CLI
39+ if ! command -v gh >/dev/null; then
40+ curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \
41+ | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
42+ sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
4343 echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
44- | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null && \
45- sudo apt-get update && sudo apt-get install -y gh)
44+ | sudo tee /etc/apt/sources.list.d/github-cli.list >/dev/null
45+ sudo apt-get update -y && sudo apt-get install -y gh
46+ fi
47+ python3 -m pip install --upgrade pip
48+ python3 -m pip install ruamel.yaml
4649
4750 - name : Wait for conda package to appear in channel
4851 env :
7174 git config user.email "access-bot@users.noreply.github.com"
7275
7376 - name : Create branch and update environment.yml
77+ id : edit
7478 working-directory : ${{ env.TARGET_REPO }}
7579 env :
7680 VERSION : ${{ steps.ver.outputs.version }}
@@ -79,53 +83,78 @@ jobs:
7983 git fetch origin "${TARGET_BRANCH}"
8084 git checkout -b "$BRANCH" "origin/${TARGET_BRANCH}"
8185
82- # 1) Replace if present
83- yq -i '(.dependencies[] | select(tag == "!!str" and test("^accessnri::access-mopper=="))) = "accessnri::access-mopper=="+env(VERSION)' "${FILE_PATH}"
86+ python3 - <<'PY'
87+ from ruamel.yaml import YAML
88+ from ruamel.yaml.comments import CommentedSeq
89+ from pathlib import Path
90+ import os, sys
8491
85- # 2) If still missing, append to the list
86- if ! yq '.dependencies[] | select(tag == "!!str")' "${FILE_PATH}" | grep -q "^accessnri::access-mopper==${VERSION}$"; then
87- yq -i '.dependencies += ["accessnri::access-mopper=="+env(VERSION)]' "${FILE_PATH}"
88- fi
92+ path = Path("${{ env.FILE_PATH }}")
93+ version = os.environ["VERSION"]
94+ target = f"accessnri::access-mopper=={version}"
95+
96+ yaml = YAML()
97+ yaml.preserve_quotes = True
98+ yaml.width = 4096
99+ yaml.indent(mapping=2, sequence=2, offset=2)
100+
101+ text = path.read_text(encoding="utf-8")
102+ data = yaml.load(text)
103+
104+ deps = data.get("dependencies", CommentedSeq())
105+ if not isinstance(deps, list):
106+ print("ERROR: dependencies is not a list", file=sys.stderr)
107+ sys.exit(1)
108+
109+ replaced = False
110+ for i, d in enumerate(deps):
111+ if isinstance(d, str) and d.startswith("accessnri::access-mopper=="):
112+ if d != target:
113+ deps[i] = target
114+ replaced = True
115+ break
89116
90- echo "Final dependency line:"
91- yq '.dependencies[] | select(tag == "!!str")' "${FILE_PATH}" | grep accessnri::access-mopper || true
117+ if not replaced:
118+ deps.append(target)
119+
120+ data["dependencies"] = deps
121+ with open(path, "w", encoding="utf-8") as f:
122+ yaml.dump(data, f)
123+ PY
92124
93125 git add "${FILE_PATH}"
94126 if git diff --cached --quiet; then
95- echo "No changes to commit (already at desired version)."
96127 echo "changed=false" >> $GITHUB_OUTPUT
128+ echo "No changes to commit."
97129 else
98130 git commit -m "analysis3: bump access-mopper to ${VERSION}"
99131 git push -u origin "$BRANCH"
100132 echo "changed=true" >> $GITHUB_OUTPUT
133+ echo "$BRANCH" > ../branch.txt
101134 fi
102135
103136 - name : Create PR (idempotent)
104- if : ${{ success() }}
137+ if : steps.edit.outputs.changed == 'true'
105138 working-directory : ${{ env.TARGET_REPO }}
106139 env :
107140 VERSION : ${{ steps.ver.outputs.version }}
108141 run : |
109- BRANCH="bump-${{ env.PACKAGE }}-${VERSION} "
110- # If a PR already exists for this branch, this returns non-zero; ignore errors.
142+ BRANCH="$(cat ../branch.txt) "
143+ # Create PR; if it already exists, ignore failure
111144 gh pr create \
112145 --base "${TARGET_BRANCH}" \
113146 --head "${BRANCH}" \
114- --title "Bump ${PACKAGE} to ${VERSION} in analysis3 env" \
147+ --title "Bump access-mopper to ${VERSION} in analysis3 env" \
115148 --body "Updates \`${FILE_PATH}\` to \`accessnri::access-mopper==${VERSION}\`."
116-
117- # Capture PR number for the next step
118- gh pr view --json number -q .number > ../pr_number.txt || true
149+ # Capture PR number (works whether newly created or pre-existing)
150+ gh pr view --head "${BRANCH}" --json number -q .number > ../pr_number.txt
119151
120152 - name : Enable auto-merge
153+ if : steps.edit.outputs.changed == 'true'
121154 working-directory : ${{ env.TARGET_REPO }}
122155 run : |
123- if [ -f ../pr_number.txt ]; then
124- PR=$(cat ../pr_number.txt)
125- # Choose one of: --merge | --squash | --rebase
126- gh pr merge "$PR" --auto --merge
127- echo "Auto-merge enabled on PR #$PR."
128- else
129- echo "No PR number found (maybe PR already existed). Enabling auto-merge anyway…"
130- gh pr merge --auto --merge || true
131- fi
156+ PR=$(cat ../pr_number.txt)
157+ # Requires Repo B setting: Settings → General → Allow auto-merge
158+ # Merge method must be allowed in repo settings
159+ gh pr merge "$PR" --auto --merge
160+ echo "Auto-merge enabled on PR #$PR."
0 commit comments