Skip to content

Commit dd80133

Browse files
committed
ci: add rich summary for update-opencode-commit workflow
1 parent c6e6003 commit dd80133

2 files changed

Lines changed: 154 additions & 0 deletions

File tree

.github/workflows/update-opencode-commit.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,129 @@ jobs:
3333
git config user.email "github-actions[bot]@users.noreply.github.com"
3434
3535
- name: Update opencode commit
36+
id: update
3637
run: |
3738
./scripts/update-opencode-commit.sh
3839
3940
- name: Verify OCI description label
41+
id: verify_oci
4042
run: python3 scripts/extract-oci-description.py packages/core/src/docker/Dockerfile
4143

4244
- name: Commit and push if changed
45+
id: commit_push
4346
run: |
4447
if git diff --quiet; then
4548
echo "No changes to commit."
49+
{
50+
echo "changed=false"
51+
echo "pushed=false"
52+
echo "commit_sha="
53+
} >> "$GITHUB_OUTPUT"
4654
exit 0
4755
fi
4856
4957
git add packages/core/src/docker/Dockerfile packages/opencode
5058
git commit -m "chore: update opencode commit"
59+
commit_sha="$(git rev-parse HEAD)"
60+
{
61+
echo "changed=true"
62+
echo "pushed=false"
63+
echo "commit_sha=${commit_sha}"
64+
} >> "$GITHUB_OUTPUT"
5165
git push
66+
echo "pushed=true" >> "$GITHUB_OUTPUT"
67+
68+
- name: Write summary
69+
if: always()
70+
env:
71+
UPDATE_OUTCOME: ${{ steps.update.outcome }}
72+
VERIFY_OCI_OUTCOME: ${{ steps.verify_oci.outcome }}
73+
COMMIT_PUSH_OUTCOME: ${{ steps.commit_push.outcome }}
74+
SUBMODULE_BRANCH: ${{ steps.update.outputs.submodule_branch }}
75+
SUBMODULE_REPO_URL: ${{ steps.update.outputs.submodule_repo_url }}
76+
CURRENT_SUBMODULE_COMMIT: ${{ steps.update.outputs.current_submodule_commit }}
77+
LATEST_COMMIT: ${{ steps.update.outputs.latest_commit }}
78+
CURRENT_PIN_VALUE: ${{ steps.update.outputs.current_pin_value }}
79+
UPDATED_PIN_VALUE: ${{ steps.update.outputs.updated_pin_value }}
80+
NEEDS_UPDATE: ${{ steps.update.outputs.needs_update }}
81+
UPDATED: ${{ steps.update.outputs.updated }}
82+
CHANGED: ${{ steps.commit_push.outputs.changed }}
83+
PUSHED: ${{ steps.commit_push.outputs.pushed }}
84+
COMMIT_SHA: ${{ steps.commit_push.outputs.commit_sha }}
85+
run: |
86+
set -euo pipefail
87+
88+
fallback() {
89+
local value="${1:-}"
90+
if [[ -z "${value}" ]]; then
91+
echo "n/a"
92+
else
93+
echo "${value}"
94+
fi
95+
}
96+
97+
branch="$(fallback "${SUBMODULE_BRANCH:-}")"
98+
repo_url="$(fallback "${SUBMODULE_REPO_URL:-}")"
99+
current_submodule="$(fallback "${CURRENT_SUBMODULE_COMMIT:-}")"
100+
latest_submodule="$(fallback "${LATEST_COMMIT:-}")"
101+
current_pin="$(fallback "${CURRENT_PIN_VALUE:-}")"
102+
updated_pin="$(fallback "${UPDATED_PIN_VALUE:-}")"
103+
needs_update="$(fallback "${NEEDS_UPDATE:-}")"
104+
updated="$(fallback "${UPDATED:-}")"
105+
changed="$(fallback "${CHANGED:-}")"
106+
pushed="$(fallback "${PUSHED:-}")"
107+
108+
superproject_repo_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}"
109+
commit_link="n/a"
110+
if [[ "${PUSHED:-}" == "true" && -n "${COMMIT_SHA:-}" ]]; then
111+
commit_link="${superproject_repo_url}/commit/${COMMIT_SHA}"
112+
fi
113+
114+
compare_link="n/a"
115+
if [[ -n "${SUBMODULE_REPO_URL:-}" && -n "${CURRENT_SUBMODULE_COMMIT:-}" && -n "${LATEST_COMMIT:-}" && "${CURRENT_SUBMODULE_COMMIT}" != "${LATEST_COMMIT}" ]]; then
116+
compare_link="${SUBMODULE_REPO_URL}/compare/${CURRENT_SUBMODULE_COMMIT}...${LATEST_COMMIT}"
117+
fi
118+
119+
status_line="ℹ️ No update needed"
120+
if [[ "${UPDATE_OUTCOME:-}" == "failure" || "${VERIFY_OCI_OUTCOME:-}" == "failure" || "${COMMIT_PUSH_OUTCOME:-}" == "failure" || "${UPDATE_OUTCOME:-}" == "cancelled" || "${VERIFY_OCI_OUTCOME:-}" == "cancelled" || "${COMMIT_PUSH_OUTCOME:-}" == "cancelled" ]]; then
121+
status_line="❌ Failed"
122+
elif [[ "${PUSHED:-}" == "true" ]]; then
123+
status_line="✅ Updated and pushed"
124+
fi
125+
126+
{
127+
echo "## ${status_line}"
128+
echo ""
129+
echo "**Trigger:** \`${GITHUB_EVENT_NAME}\`"
130+
echo "**Ref:** \`${GITHUB_REF}\`"
131+
echo "**Actor:** \`${GITHUB_ACTOR}\`"
132+
echo ""
133+
echo "**Submodule branch:** \`${branch}\`"
134+
echo "**Submodule repo:** ${repo_url}"
135+
echo ""
136+
echo "**Submodule commit:** \`${current_submodule} -> ${latest_submodule}\`"
137+
echo "**Dockerfile pin:** \`${current_pin} -> ${updated_pin}\`"
138+
echo ""
139+
echo "**Update flags:**"
140+
echo "- needs_update: \`${needs_update}\`"
141+
echo "- updated: \`${updated}\`"
142+
echo "- changed: \`${changed}\`"
143+
echo "- pushed: \`${pushed}\`"
144+
echo ""
145+
echo "**Links:**"
146+
if [[ "${compare_link}" == "n/a" ]]; then
147+
echo "- submodule compare: n/a"
148+
else
149+
echo "- submodule compare: ${compare_link}"
150+
fi
151+
if [[ "${commit_link}" == "n/a" ]]; then
152+
echo "- pushed superproject commit: n/a"
153+
else
154+
echo "- pushed superproject commit: ${commit_link}"
155+
fi
156+
echo ""
157+
echo "**Step outcomes:**"
158+
echo "- update: \`${UPDATE_OUTCOME:-n/a}\`"
159+
echo "- verify_oci: \`${VERIFY_OCI_OUTCOME:-n/a}\`"
160+
echo "- commit_push: \`${COMMIT_PUSH_OUTCOME:-n/a}\`"
161+
} >> "${GITHUB_STEP_SUMMARY}"

scripts/update-opencode-commit.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,34 @@ dockerfile="${root_dir}/packages/core/src/docker/Dockerfile"
66
submodule_dir="${root_dir}/packages/opencode"
77
gitmodules="${root_dir}/.gitmodules"
88

9+
set_output() {
10+
local key="$1"
11+
local value="$2"
12+
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
13+
echo "${key}=${value}" >> "${GITHUB_OUTPUT}"
14+
fi
15+
}
16+
17+
normalize_repo_url() {
18+
local input="$1"
19+
local normalized="$input"
20+
21+
if [[ "${normalized}" == git@github.com:* ]]; then
22+
normalized="https://github.com/${normalized#git@github.com:}"
23+
elif [[ "${normalized}" == ssh://git@github.com/* ]]; then
24+
normalized="https://github.com/${normalized#ssh://git@github.com/}"
25+
elif [[ "${normalized}" == git://github.com/* ]]; then
26+
normalized="https://github.com/${normalized#git://github.com/}"
27+
elif [[ "${normalized}" == http://github.com/* ]]; then
28+
normalized="https://github.com/${normalized#http://github.com/}"
29+
fi
30+
31+
normalized="${normalized%.git}"
32+
normalized="${normalized%/}"
33+
34+
echo "${normalized}"
35+
}
36+
937
if [[ ! -f "${dockerfile}" ]]; then
1038
echo "Dockerfile not found at ${dockerfile}" >&2
1139
exit 1
@@ -33,6 +61,15 @@ if [[ -f "${gitmodules}" ]]; then
3361
submodule_branch="${configured_branch}"
3462
fi
3563
fi
64+
set_output "submodule_branch" "${submodule_branch}"
65+
66+
submodule_repo_url_raw="$(git -C "${submodule_dir}" remote get-url origin 2>/dev/null || true)"
67+
if [[ -z "${submodule_repo_url_raw}" && -f "${gitmodules}" ]]; then
68+
submodule_repo_url_raw="$(git config -f "${gitmodules}" --get submodule.packages/opencode.url 2>/dev/null || true)"
69+
fi
70+
submodule_repo_url="$(normalize_repo_url "${submodule_repo_url_raw}")"
71+
set_output "submodule_repo_url" "${submodule_repo_url}"
72+
set_output "current_submodule_commit" "${current_submodule_commit}"
3673

3774
# In GitHub Actions, submodule URLs may be SSH-style from .gitmodules
3875
# (git@github.com:...), but runners usually do not have an SSH key.
@@ -47,6 +84,7 @@ if [[ -z "${latest_commit}" ]]; then
4784
echo "Failed to resolve latest commit for branch ${submodule_branch}." >&2
4885
exit 1
4986
fi
87+
set_output "latest_commit" "${latest_commit}"
5088

5189
current_pin="$(grep -oE 'OPENCODE_COMMIT="[^\"]+"' "${dockerfile}" | head -n1 || true)"
5290
if [[ -z "${current_pin}" ]]; then
@@ -56,6 +94,7 @@ fi
5694

5795
current_pin_value="${current_pin#OPENCODE_COMMIT=\"}"
5896
current_pin_value="${current_pin_value%\"}"
97+
set_output "current_pin_value" "${current_pin_value}"
5998

6099
needs_update="false"
61100
if [[ "${latest_commit}" != "${current_submodule_commit}" ]]; then
@@ -64,8 +103,11 @@ fi
64103
if [[ "${latest_commit}" != "${current_pin_value}" ]]; then
65104
needs_update="true"
66105
fi
106+
set_output "needs_update" "${needs_update}"
67107

68108
if [[ "${needs_update}" == "false" ]]; then
109+
set_output "updated" "false"
110+
set_output "updated_pin_value" "${current_pin_value}"
69111
echo "No update needed; opencode is already at the latest commit."
70112
echo " Branch: ${submodule_branch}"
71113
echo " Commit: ${latest_commit}"
@@ -84,6 +126,8 @@ if [[ "${updated_pin}" != "${expected_pin}" ]]; then
84126
echo "Failed to update OPENCODE_COMMIT in ${dockerfile}." >&2
85127
exit 1
86128
fi
129+
set_output "updated" "true"
130+
set_output "updated_pin_value" "${latest_commit}"
87131

88132
echo "Updated opencode references."
89133
echo " Branch: ${submodule_branch}"

0 commit comments

Comments
 (0)