Skip to content

Commit eecee90

Browse files
authored
Add publish step to BuildExplorer workflow
1 parent 5edae38 commit eecee90

1 file changed

Lines changed: 138 additions & 0 deletions

File tree

‎.github/workflows/buildexplorer.yml‎

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,142 @@ jobs:
3434
java-version: "21"
3535

3636
- name: Set up Gradle
37+
uses: gradle/actions/setup-gradle@v4
38+
39+
- name: Test
40+
run: |
41+
chmod +x ./gradlew
42+
./gradlew test --console=plain --no-daemon
43+
44+
publish:
45+
name: Publish plugin
46+
runs-on: ubuntu-latest
47+
needs: verify
48+
if: github.event_name == 'push'
49+
50+
steps:
51+
- name: Checkout
52+
uses: actions/checkout@v4
53+
with:
54+
fetch-depth: 0
55+
56+
- name: Set up Java
57+
uses: actions/setup-java@v4
58+
with:
59+
distribution: temurin
60+
java-version: "21"
61+
62+
- name: Set up Gradle
63+
uses: gradle/actions/setup-gradle@v4
64+
65+
- name: Build plugin
66+
run: |
67+
chmod +x ./gradlew
68+
./gradlew "${BUILD_GRADLE_TASK}" --console=plain --no-daemon
69+
70+
- name: Publish artifact to BuildExplorer
71+
env:
72+
BUILD_CI_TOKEN: ${{ secrets.BUILD_CI_TOKEN }}
73+
GITHUB_BEFORE: ${{ github.event.before }}
74+
GITHUB_AFTER: ${{ github.sha }}
75+
GITHUB_RUN_ID_VALUE: ${{ github.run_id }}
76+
GITHUB_RUN_NUMBER_VALUE: ${{ github.run_number }}
77+
run: |
78+
set -euo pipefail
79+
80+
if [ -z "${BUILD_CI_TOKEN}" ]; then
81+
echo "Missing BUILD_CI_TOKEN repository secret." >&2
82+
exit 1
83+
fi
84+
85+
if [ ! -d "${BUILD_JAR_DIR}" ]; then
86+
echo "Directory ${BUILD_JAR_DIR} does not exist for ${BUILD_SLUG}." >&2
87+
exit 1
88+
fi
89+
90+
jar="$(python3 - <<'PY'
91+
from pathlib import Path
92+
import os
93+
import sys
94+
95+
jar_dir = Path(os.environ["BUILD_JAR_DIR"])
96+
prefix = os.environ["BUILD_ARTIFACT_PREFIX"]
97+
excluded_suffixes = ("-sources.jar", "-javadoc.jar", "-plain.jar", "-original.jar")
98+
candidates = [
99+
path for path in jar_dir.glob("*.jar")
100+
if not path.name.endswith(excluded_suffixes)
101+
]
102+
preferred = [path for path in candidates if path.name.startswith(prefix)]
103+
pool = preferred or candidates
104+
if not pool:
105+
sys.exit(1)
106+
print(max(pool, key=lambda path: path.stat().st_size))
107+
PY
108+
)"
109+
if [ -z "${jar}" ]; then
110+
echo "No JAR found for ${BUILD_SLUG} in ${BUILD_JAR_DIR}." >&2
111+
exit 1
112+
fi
113+
114+
version="$(./gradlew -q "${BUILD_GRADLE_PROPERTIES_TASK}" --console=plain --no-daemon | awk -F': ' '$1 == "version" {print $2; exit}' | tr -d '\r')"
115+
if [ -z "${version}" ] || [ "${version}" = "unspecified" ]; then
116+
version="${GITHUB_SHA::12}"
117+
fi
118+
artifact_base="$(basename "${jar}" .jar)"
119+
if [ "${artifact_base%-${GITHUB_RUN_NUMBER_VALUE}}" != "${artifact_base}" ]; then
120+
filename="${artifact_base}.jar"
121+
else
122+
filename="${artifact_base}-${GITHUB_RUN_NUMBER_VALUE}.jar"
123+
fi
124+
sha256="$(sha256sum "${jar}" | awk '{print $1}')"
125+
size="$(stat -c%s "${jar}")"
126+
127+
export BUILD_VERSION="${version}"
128+
export BUILD_FILENAME="${filename}"
129+
export BUILD_SHA256="${sha256}"
130+
export BUILD_SIZE="${size}"
131+
132+
python3 - <<'PY' > build-info.json
133+
import json
134+
import os
135+
import subprocess
136+
from datetime import datetime, timezone
137+
138+
before = os.environ.get("GITHUB_BEFORE", "")
139+
after = os.environ["GITHUB_AFTER"]
140+
rev_range = after
141+
if before and before != "0000000000000000000000000000000000000000":
142+
rev_range = f"{before}..{after}"
143+
144+
raw = subprocess.check_output(
145+
["git", "log", "--format=%H%x1f%cI%x1f%s", rev_range],
146+
text=True,
147+
).strip()
148+
commits = []
149+
for line in raw.splitlines():
150+
if not line:
151+
continue
152+
sha, time, message = line.split("\x1f", 2)
153+
commits.append({"sha": sha, "time": time, "message": message})
154+
155+
payload = {
156+
"id": int(os.environ["GITHUB_RUN_ID_VALUE"]),
157+
"time": datetime.now(timezone.utc).isoformat(),
158+
"channel": os.environ["BUILD_CHANNEL"],
159+
"server": os.environ["BUILD_SERVER"],
160+
"version": os.environ["BUILD_VERSION"],
161+
"build_number": os.environ["GITHUB_RUN_NUMBER_VALUE"],
162+
"filename": os.environ["BUILD_FILENAME"],
163+
"sha256": os.environ["BUILD_SHA256"],
164+
"size": int(os.environ["BUILD_SIZE"]),
165+
"commits": commits[:100],
166+
}
167+
print(json.dumps(payload, ensure_ascii=False))
168+
PY
169+
170+
curl --fail-with-body \
171+
-X POST "${MINI_PORTAL_URL}/api/builds/ci/${BUILD_SLUG}" \
172+
-H "X-Build-Token: ${BUILD_CI_TOKEN}" \
173+
-F "metadata=<build-info.json;type=application/json" \
174+
-F "artifact=@${jar};filename=${filename};type=application/java-archive"
37175

0 commit comments

Comments
 (0)