Skip to content

Commit c5d1c35

Browse files
committed
refactor(ci): introduce BRANCH_NAME env var, remove hardcoded welan
1 parent e8458d7 commit c5d1c35

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

.github/workflows/a-welan-release.yml

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ on:
2020
type: string
2121

2222
concurrency:
23-
group: welan-release
23+
group: ${{ env.BRANCH_NAME }}-release
2424
cancel-in-progress: false
2525

2626
permissions:
@@ -30,6 +30,7 @@ env:
3030
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
3131
GH_TOKEN: ${{ secrets.WELAN_PAT }}
3232
WELAN_PATCH_AUTHOR: weizhoublue
33+
BRANCH_NAME: welan
3334

3435
jobs:
3536
release:
@@ -77,13 +78,13 @@ jobs:
7778
7879
- name: Fetch branches and tags
7980
run: |
80-
git fetch origin welan:refs/remotes/origin/welan --tags
81+
git fetch origin "$BRANCH_NAME:refs/remotes/origin/$BRANCH_NAME" --tags
8182
git fetch upstream "refs/tags/$RELEASE_TAG:refs/tags/$RELEASE_TAG"
8283
git rev-parse --verify "refs/tags/$RELEASE_TAG^{commit}" >/dev/null
8384
8485
- name: Prepare welan from upstream tag
8586
run: |
86-
git checkout -B welan "$RELEASE_TAG"
87+
git checkout -B "$BRANCH_NAME" "$RELEASE_TAG"
8788
8889
- name: Cherry-pick welan author patches
8990
id: patches
@@ -93,7 +94,7 @@ jobs:
9394
# commit NOT authored by WELAN_PATCH_AUTHOR. Merge commits count as
9495
# authored by whoever merged them, so this correctly stops at the
9596
# upstream base even when the tip is a merge commit.
96-
base_ref="origin/welan"
97+
base_ref="origin/$BRANCH_NAME"
9798
while true; do
9899
author="$(git log -1 --format='%an' "$base_ref")"
99100
if [[ "$author" != *"$WELAN_PATCH_AUTHOR"* ]]; then
@@ -105,8 +106,8 @@ jobs:
105106
base_ref="${base_ref}^"
106107
done
107108
108-
if [[ "$(git rev-parse "$base_ref")" == "$(git rev-parse "origin/welan")" ]]; then
109-
echo "::error::No commits authored by $WELAN_PATCH_AUTHOR found at the tip of origin/welan"
109+
if [[ "$(git rev-parse "$base_ref")" == "$(git rev-parse "origin/$BRANCH_NAME")" ]]; then
110+
echo "::error::No commits authored by $WELAN_PATCH_AUTHOR found at the tip of origin/$BRANCH_NAME"
110111
exit 1
111112
fi
112113
@@ -115,15 +116,15 @@ jobs:
115116
# real patch commits from any merged branches, making each entry safely
116117
# cherry-pickable without needing -m.
117118
mapfile -t patch_commits < <(
118-
git log --no-merges --reverse --format='%H' "${base_ref}..origin/welan"
119+
git log --no-merges --reverse --format='%H' "${base_ref}..origin/$BRANCH_NAME"
119120
)
120121
121122
if [ "${#patch_commits[@]}" -eq 0 ]; then
122-
echo "::error::No non-merge commits found between $base_ref and origin/welan"
123+
echo "::error::No non-merge commits found between $base_ref and origin/$BRANCH_NAME"
123124
exit 1
124125
fi
125126
126-
echo "Cherry-picking ${#patch_commits[@]} commit(s) from origin/welan (author: $WELAN_PATCH_AUTHOR)"
127+
echo "Cherry-picking ${#patch_commits[@]} commit(s) from origin/$BRANCH_NAME (author: $WELAN_PATCH_AUTHOR)"
127128
for sha in "${patch_commits[@]}"; do
128129
subject="$(git log -1 --format='%s' "$sha")"
129130
echo "Cherry-picking $sha $subject"
@@ -135,15 +136,15 @@ jobs:
135136
run: |
136137
conflicted_files="$(git diff --name-only --diff-filter=U || true)"
137138
upstream_tag="$(git rev-parse "$RELEASE_TAG")"
138-
origin_welan="$(git rev-parse origin/welan)"
139+
origin_branch="$(git rev-parse "origin/$BRANCH_NAME")"
139140
current_head="$(git rev-parse HEAD)"
140141
141-
echo "::error::welan release $RELEASE_TAG hit a cherry-pick conflict"
142+
echo "::error::$BRANCH_NAME release $RELEASE_TAG hit a cherry-pick conflict"
142143
echo "Version: $RELEASE_TAG"
143144
echo "Run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
144145
echo "Upstream tag: $RELEASE_TAG"
145146
echo "Upstream tag SHA: ${upstream_tag}"
146-
echo "origin/welan: ${origin_welan}"
147+
echo "origin/$BRANCH_NAME: ${origin_branch}"
147148
echo "Current HEAD during conflict: ${current_head}"
148149
echo "Patch author: $WELAN_PATCH_AUTHOR"
149150
echo
@@ -216,7 +217,7 @@ jobs:
216217

217218
- name: Stage release binaries
218219
run: |
219-
asset_dir="/tmp/welan-release-assets"
220+
asset_dir="/tmp/$BRANCH_NAME-release-assets"
220221
rm -rf "$asset_dir"
221222
mkdir -p "$asset_dir"
222223
@@ -227,7 +228,7 @@ jobs:
227228
ls -lh "$asset_dir"
228229
229230
- name: Push rebased welan
230-
run: git push origin HEAD:welan --force-with-lease
231+
run: git push origin "HEAD:$BRANCH_NAME" --force-with-lease
231232

232233
- name: Push release archive branch
233234
run: |
@@ -246,9 +247,9 @@ jobs:
246247
git push origin "refs/tags/$tag" --force
247248
248249
gh release create "$tag" \
249-
/tmp/welan-release-assets/opencode-darwin-arm64 \
250-
/tmp/welan-release-assets/opencode-linux-arm64 \
251-
/tmp/welan-release-assets/opencode-linux-x64 \
250+
"$asset_dir/opencode-darwin-arm64" \
251+
"$asset_dir/opencode-linux-arm64" \
252+
"$asset_dir/opencode-linux-x64" \
252253
--repo "${{ github.repository }}" \
253254
--target "$target" \
254255
--title "$tag" \

0 commit comments

Comments
 (0)