Skip to content

Commit 7a92da9

Browse files
committed
bugfix: read owner/repo from release.conf instead of hardcoding
1 parent aebff88 commit 7a92da9

4 files changed

Lines changed: 99 additions & 21 deletions

File tree

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{"status": "open"}
1+
{
2+
"status" : "closed",
3+
"resolution" : "implemented",
4+
"target_branch" : "v2.1"
5+
}
Lines changed: 73 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,84 @@
11
# Replace Hardcoded Owner/Repo References in CI Workflow
22

33
## Goal
4-
Replace hardcoded `cowwoc/cat` repository references in `.github/workflows/build-git-filter-repo.yml`
5-
with GitHub Actions context variables (`github.repository_owner` and `github.event.repository.name`)
6-
so the workflow is portable across forks and repository renames.
4+
Replace hardcoded `cowwoc/cat` repository references in `plugin/scripts/download-git-filter-repo.sh`
5+
with values read from `plugin/.git-filter-repo-config/release.conf`, so the download script is
6+
portable across forks and repository renames.
77

88
## Background
9-
The `build-git-filter-repo.yml` workflow contains hardcoded `cowwoc/cat` strings (e.g., in download
10-
URL construction or artifact publishing steps). This prevents the workflow from working correctly in
11-
forks or after a repository rename without manual edits.
9+
`plugin/scripts/download-git-filter-repo.sh` hardcodes `REPO_OWNER="cowwoc"` and `REPO_NAME="cat"`
10+
when constructing the GitHub release download URL. Investigation confirmed `.github/workflows/build-git-filter-repo.yml`
11+
does NOT contain hardcoded owner/repo references — it already uses GitHub Actions context variables correctly.
12+
13+
The fix moves the owner/repo values into `release.conf` alongside the existing `RELEASE_TAG` and
14+
`PLATFORM_SHA256_*` fields, so forks that build their own binaries can update all release
15+
configuration in one place.
16+
17+
## Research Findings
18+
- `.github/workflows/build-git-filter-repo.yml` uses `softprops/action-gh-release` which defaults to
19+
the current repository — no hardcoded owner/repo present, no changes needed.
20+
- `plugin/scripts/download-git-filter-repo.sh:174-175` has `REPO_OWNER="cowwoc"` and `REPO_NAME="cat"`.
21+
- `plugin/.git-filter-repo-config/release.conf` already contains `RELEASE_TAG` and `PLATFORM_SHA256_*`
22+
— the natural place to add `REPO_OWNER` and `REPO_NAME`.
1223

1324
## Changes Required
1425

15-
1. Identify all occurrences of `cowwoc/cat` (or `cowwoc` alone) in
16-
`.github/workflows/build-git-filter-repo.yml`.
17-
2. Replace hardcoded owner with `${{ github.repository_owner }}`.
18-
3. Replace hardcoded repo name with `${{ github.event.repository.name }}`.
19-
4. Verify the replacement works for the artifact upload/download steps and any API calls.
20-
5. Update `plugin/scripts/download-git-filter-repo.sh` if it also contains hardcoded owner/repo
21-
references used for downloading release artifacts.
26+
### 1. `plugin/.git-filter-repo-config/release.conf`
27+
28+
Add these fields immediately before `RELEASE_TAG`:
29+
30+
```conf
31+
REPO_OWNER="cowwoc"
32+
REPO_NAME="cat"
33+
```
34+
35+
Update the "How to update" comment block (line ~13) to add:
36+
```
37+
# 0. Update REPO_OWNER and REPO_NAME if building from a fork (optional for original repo).
38+
```
39+
40+
### 2. `plugin/scripts/download-git-filter-repo.sh`
41+
42+
Remove these lines (~174-175):
43+
```bash
44+
REPO_OWNER="cowwoc"
45+
REPO_NAME="cat"
46+
```
47+
48+
Replace with parsing from `release.conf` (similar to the existing `RELEASE_TAG` parsing pattern):
49+
```bash
50+
REPO_OWNER=$(grep -E '^REPO_OWNER=' "${CONF}" | sed 's/^REPO_OWNER="\(.*\)"$/\1/' | head -1 || true)
51+
if [[ -z "${REPO_OWNER}" ]]; then
52+
echo "ERROR: REPO_OWNER not found in ${CONF}" >&2
53+
exit 1
54+
fi
55+
if ! echo "${REPO_OWNER}" | grep -qE '^[a-zA-Z0-9_-]+$'; then
56+
echo "ERROR: REPO_OWNER in ${CONF} has unexpected format: ${REPO_OWNER}" >&2
57+
exit 1
58+
fi
59+
REPO_NAME=$(grep -E '^REPO_NAME=' "${CONF}" | sed 's/^REPO_NAME="\(.*\)"$/\1/' | head -1 || true)
60+
if [[ -z "${REPO_NAME}" ]]; then
61+
echo "ERROR: REPO_NAME not found in ${CONF}" >&2
62+
exit 1
63+
fi
64+
if ! echo "${REPO_NAME}" | grep -qE '^[a-zA-Z0-9_-]+$'; then
65+
echo "ERROR: REPO_NAME in ${CONF} has unexpected format: ${REPO_NAME}" >&2
66+
exit 1
67+
fi
68+
```
2269

2370
## Post-conditions
2471

25-
- [ ] No hardcoded `cowwoc/cat` or `cowwoc` strings remain in the workflow or download script
26-
(except in comments where explaining the original repository)
27-
- [ ] The workflow uses GitHub Actions context variables for owner and repo name
28-
- [ ] The workflow is tested in a fork to confirm portability
29-
- [ ] No regressions introduced
72+
- [ ] No hardcoded `REPO_OWNER="cowwoc"` or `REPO_NAME="cat"` in `plugin/scripts/download-git-filter-repo.sh`
73+
- [ ] `plugin/.git-filter-repo-config/release.conf` contains `REPO_OWNER` and `REPO_NAME` fields
74+
- [ ] The download script reads `REPO_OWNER` and `REPO_NAME` from `release.conf`
75+
- [ ] Download script fails with a clear error when `REPO_OWNER` or `REPO_NAME` is missing or malformed
76+
- [ ] No regressions in `plugin/scripts/download-git-filter-repo.sh` functionality
77+
78+
## Jobs
79+
80+
### Job 1
81+
- In `plugin/.git-filter-repo-config/release.conf`: add `REPO_OWNER="cowwoc"` and `REPO_NAME="cat"` fields before `RELEASE_TAG`, and add the step-0 note to the update comment block
82+
- In `plugin/scripts/download-git-filter-repo.sh`: remove hardcoded `REPO_OWNER` and `REPO_NAME` lines (~174-175) and add parsing code that reads them from `release.conf` using the same grep/sed pattern as `RELEASE_TAG` parsing, with fail-fast validation
83+
- Update `.cat/issues/v2/v2.1/replace-hardcoded-owner-repo-in-workflow/index.json` with `status: "closed"` and `progress: 100`
84+
- Commit type: `bugfix:`

plugin/.git-filter-repo-config/release.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# pre-built binary for the current platform.
1010
#
1111
# How to update after a new release build:
12+
# 0. Update REPO_OWNER and REPO_NAME if building from a fork (optional for original repo).
1213
# 1. Run the build-git-filter-repo CI workflow with the new version tag.
1314
# 2. After all 4 platform builds succeed, download the .sha256 files from the
1415
# GitHub release artifacts (git-filter-repo-<platform>.sha256).
@@ -25,6 +26,8 @@
2526
# PLATFORM_SHA256_macos_x64 - git-filter-repo-macos-x64 binary
2627
# PLATFORM_SHA256_macos_aarch64 - git-filter-repo-macos-aarch64 binary
2728

29+
REPO_OWNER="cowwoc"
30+
REPO_NAME="cat"
2831
RELEASE_TAG="git-filter-repo-v2.38.0"
2932
# SOURCE_SHA256 is the SHA256 of the upstream git-filter-repo.py source file for this version.
3033
# It is used only by the CI build workflow (build-git-filter-repo.yml) to verify source integrity

plugin/scripts/download-git-filter-repo.sh

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,24 @@ if [[ -f "${CACHED_BINARY}" ]] && [[ -z "${GFR_FORCE_DOWNLOAD:-}" ]]; then
171171
fi
172172

173173
# Construct GitHub release download URL
174-
REPO_OWNER="cowwoc"
175-
REPO_NAME="cat"
174+
REPO_OWNER=$(grep -E '^REPO_OWNER=' "${CONF}" | sed 's/^REPO_OWNER="\(.*\)"$/\1/' | head -1 || true)
175+
if [[ -z "${REPO_OWNER}" ]]; then
176+
echo "ERROR: REPO_OWNER not found in ${CONF}" >&2
177+
exit 1
178+
fi
179+
if ! echo "${REPO_OWNER}" | grep -qE '^[a-zA-Z0-9_-]+$'; then
180+
echo "ERROR: REPO_OWNER in ${CONF} has unexpected format: ${REPO_OWNER}" >&2
181+
exit 1
182+
fi
183+
REPO_NAME=$(grep -E '^REPO_NAME=' "${CONF}" | sed 's/^REPO_NAME="\(.*\)"$/\1/' | head -1 || true)
184+
if [[ -z "${REPO_NAME}" ]]; then
185+
echo "ERROR: REPO_NAME not found in ${CONF}" >&2
186+
exit 1
187+
fi
188+
if ! echo "${REPO_NAME}" | grep -qE '^[a-zA-Z0-9_-]+$'; then
189+
echo "ERROR: REPO_NAME in ${CONF} has unexpected format: ${REPO_NAME}" >&2
190+
exit 1
191+
fi
176192
BINARY_URL="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${RELEASE_TAG}/${BINARY_NAME}"
177193

178194
if ! mkdir -p "${CACHE_DIR}"; then

0 commit comments

Comments
 (0)