Skip to content

Commit f693de2

Browse files
committed
Fix publish-conan workflow: use curl/REST API instead of gh CLI
1 parent 329afe8 commit f693de2

File tree

2 files changed

+52
-37
lines changed

2 files changed

+52
-37
lines changed

.github/workflows/publish-conan.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,6 @@ jobs:
4545
git checkout master || git checkout -b master
4646
git merge upstream/master || true
4747
48-
- name: Install GitHub CLI
49-
run: |
50-
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
51-
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
52-
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
53-
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
54-
&& sudo apt update \
55-
&& sudo apt install gh -y
56-
57-
- name: Authenticate GitHub CLI
58-
run: |
59-
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
60-
6148
- name: Publish to Conan Center
6249
env:
6350
GITHUB_REPO: d-led/influxdb-cpp-rest

scripts/publish-conan-version.sh

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -241,18 +241,14 @@ if [ -n "${GITHUB_TOKEN:-}" ]; then
241241
fi
242242
git push -u origin "${BRANCH_NAME}" || git push origin "${BRANCH_NAME}"
243243

244-
# Create pull request
244+
# Create pull request using GitHub REST API (works without gh CLI)
245245
if [ "${SKIP_PR}" != true ]; then
246246
echo "Creating pull request..."
247-
# Authenticate gh CLI if GITHUB_TOKEN is available (for CI)
248-
if [ -n "${GITHUB_TOKEN:-}" ]; then
249-
echo "${GITHUB_TOKEN}" | gh auth login --with-token 2>/dev/null || true
250-
fi
251247

252-
PR_URL=$(gh pr create \
253-
--repo "${CONAN_INDEX_UPSTREAM}" \
254-
--title "Add influxdb-cpp-rest/${VERSION}" \
255-
--body "This PR adds the influxdb-cpp-rest package version ${VERSION} to Conan Center.
248+
if [ -n "${GITHUB_TOKEN:-}" ]; then
249+
# Use GitHub REST API to create PR
250+
PR_BODY=$(cat <<EOF
251+
This PR adds the influxdb-cpp-rest package version ${VERSION} to Conan Center.
256252
257253
## Package Details
258254
- **Name**: influxdb-cpp-rest
@@ -277,22 +273,54 @@ if [ "${SKIP_PR}" != true ]; then
277273
- C++20 or later
278274
- GCC 11+, Clang 14+, MSVC 2019+
279275
280-
Automatically created by GitHub Actions workflow on tag push." \
281-
2>&1) || {
282-
echo "Warning: Failed to create PR. You may need to create it manually."
283-
echo "Branch pushed to: ${CONAN_INDEX_FORK}:${BRANCH_NAME}"
284-
exit 1
285-
}
286-
287-
echo ""
288-
echo "✅ Pull request created: ${PR_URL}"
289-
echo ""
290-
echo "Next steps:"
291-
echo " 1. Monitor the PR for CI results"
292-
echo " 2. Address any review comments or CI failures"
293-
echo " 3. Once merged, the package will be available on Conan Center"
276+
Automatically created by GitHub Actions workflow on tag push.
277+
EOF
278+
)
279+
280+
# Extract owner and repo from CONAN_INDEX_UPSTREAM (format: owner/repo)
281+
# Format PR body as JSON (escape newlines and quotes)
282+
ESCAPED_BODY=$(echo "${PR_BODY}" | sed ':a;N;$!ba;s/\n/\\n/g' | sed 's/"/\\"/g')
283+
284+
# Extract fork owner from CONAN_INDEX_FORK (format: owner/repo)
285+
FORK_OWNER="${CONAN_INDEX_FORK%%/*}"
286+
287+
PR_RESPONSE=$(curl -s -w "\n%{http_code}" \
288+
-X POST \
289+
-H "Accept: application/vnd.github.v3+json" \
290+
-H "Authorization: token ${GITHUB_TOKEN}" \
291+
"https://api.github.com/repos/${CONAN_INDEX_UPSTREAM}/pulls" \
292+
-d "{
293+
\"title\": \"Add influxdb-cpp-rest/${VERSION}\",
294+
\"body\": \"${ESCAPED_BODY}\",
295+
\"head\": \"${FORK_OWNER}:${BRANCH_NAME}\",
296+
\"base\": \"master\"
297+
}")
298+
299+
HTTP_CODE=$(echo "${PR_RESPONSE}" | tail -1)
300+
PR_JSON=$(echo "${PR_RESPONSE}" | head -n -1)
301+
302+
if [ "${HTTP_CODE}" = "201" ] || [ "${HTTP_CODE}" = "200" ]; then
303+
PR_URL=$(echo "${PR_JSON}" | grep -o '"html_url":[^,]*' | cut -d'"' -f4 || echo "")
304+
echo ""
305+
echo "✅ Pull request created: ${PR_URL}"
306+
echo ""
307+
echo "Next steps:"
308+
echo " 1. Monitor the PR for CI results"
309+
echo " 2. Address any review comments or CI failures"
310+
echo " 3. Once merged, the package will be available on Conan Center"
311+
else
312+
echo "Warning: Failed to create PR (HTTP ${HTTP_CODE})"
313+
echo "Response: ${PR_JSON}"
314+
echo "Branch pushed to: ${CONAN_INDEX_FORK}:${BRANCH_NAME}"
315+
echo "Create PR manually at: https://github.com/${CONAN_INDEX_UPSTREAM}/compare/master...${CONAN_INDEX_FORK#*/}:${BRANCH_NAME}"
316+
exit 1
317+
fi
318+
else
319+
echo "✅ Branch pushed. Create PR manually:"
320+
echo " https://github.com/${CONAN_INDEX_UPSTREAM}/compare/master...${CONAN_INDEX_FORK#*/}:${BRANCH_NAME}"
321+
fi
294322
else
295323
echo "✅ Branch pushed. Create PR manually:"
296-
echo " gh pr create --repo ${CONAN_INDEX_UPSTREAM} --title \"Add influxdb-cpp-rest/${VERSION}\""
324+
echo " https://github.com/${CONAN_INDEX_UPSTREAM}/compare/master...${CONAN_INDEX_FORK#*/}:${BRANCH_NAME}"
297325
fi
298326

0 commit comments

Comments
 (0)