|
45 | 45 | echo "Project version: $VERSION (tag: $TAG)" |
46 | 46 |
|
47 | 47 | current_branch=$(git rev-parse --abbrev-ref HEAD) |
| 48 | +current_sha=$(git rev-parse HEAD) |
48 | 49 | if [ "$current_branch" != "main" ]; then |
49 | 50 | echo "ERROR: release.sh must be run from the main branch. Current branch: $current_branch" |
50 | 51 | exit 1 |
|
109 | 110 |
|
110 | 111 | if [ "$BUILD" = true ]; then |
111 | 112 | branch="$current_branch" |
| 113 | + previous_runs_file=$(mktemp) |
| 114 | + gh run list --repo "$REPO" --workflow "$WORKFLOW" --branch "$branch" \ |
| 115 | + --limit 20 --json databaseId --jq '.[].databaseId' > "$previous_runs_file" |
| 116 | + |
112 | 117 | echo "Triggering workflow on branch: $branch" |
| 118 | + echo "Expected workflow commit: $current_sha" |
113 | 119 | gh workflow run "$WORKFLOW" --repo "$REPO" --ref "$branch" |
114 | 120 |
|
115 | 121 | echo "Waiting for workflow run to appear..." |
116 | 122 | run_id="" |
117 | 123 | for attempt in $(seq 1 12); do |
118 | 124 | sleep 5 |
119 | | - run_id=$(gh run list --repo "$REPO" --workflow "$WORKFLOW" --branch "$branch" \ |
120 | | - --limit 1 --json databaseId,status --jq '.[0].databaseId') |
| 125 | + run_id=$( |
| 126 | + gh run list --repo "$REPO" --workflow "$WORKFLOW" --branch "$branch" \ |
| 127 | + --limit 20 --json databaseId,headSha,status \ |
| 128 | + --jq ".[] | select(.headSha == \"$current_sha\") | .databaseId" | |
| 129 | + while read -r candidate_run_id; do |
| 130 | + if ! grep -qx "$candidate_run_id" "$previous_runs_file"; then |
| 131 | + echo "$candidate_run_id" |
| 132 | + break |
| 133 | + fi |
| 134 | + done |
| 135 | + ) |
121 | 136 | if [ -n "$run_id" ]; then |
122 | 137 | break |
123 | 138 | fi |
124 | | - echo " Attempt $attempt/12: run not yet visible..." |
| 139 | + echo " Attempt $attempt/12: new run for $current_sha not yet visible..." |
125 | 140 | done |
| 141 | + rm -f "$previous_runs_file" |
126 | 142 |
|
127 | 143 | if [ -z "$run_id" ]; then |
128 | 144 | echo "ERROR: Could not find workflow run after 60 seconds." |
@@ -164,6 +180,45 @@ if [ "$BUILD" = true ]; then |
164 | 180 | ls -lh "$DIST_DIR/" |
165 | 181 | fi |
166 | 182 |
|
| 183 | +expected_assets=( |
| 184 | + "alipsa-accounting-${VERSION}-linux.zip" |
| 185 | + "alipsa-accounting-${VERSION}-windows.zip" |
| 186 | + "alipsa-accounting-${VERSION}-macos.zip" |
| 187 | + "app-${VERSION}.zip" |
| 188 | +) |
| 189 | +missing_assets=() |
| 190 | +for asset in "${expected_assets[@]}"; do |
| 191 | + if [ ! -f "$DIST_DIR/$asset" ]; then |
| 192 | + missing_assets+=("$asset") |
| 193 | + fi |
| 194 | +done |
| 195 | + |
| 196 | +wrong_version_assets=() |
| 197 | +for file in "$DIST_DIR"/alipsa-accounting-*.zip "$DIST_DIR"/app-*.zip; do |
| 198 | + [ -e "$file" ] || continue |
| 199 | + name=$(basename "$file") |
| 200 | + case " ${expected_assets[*]} " in |
| 201 | + *" $name "*) ;; |
| 202 | + *) wrong_version_assets+=("$name") ;; |
| 203 | + esac |
| 204 | +done |
| 205 | + |
| 206 | +if [ "${#missing_assets[@]}" -gt 0 ] || [ "${#wrong_version_assets[@]}" -gt 0 ]; then |
| 207 | + echo "ERROR: Artifacts in $DIST_DIR do not match project version $VERSION." |
| 208 | + if [ "${#missing_assets[@]}" -gt 0 ]; then |
| 209 | + echo "Missing expected artifacts:" |
| 210 | + printf ' %s\n' "${missing_assets[@]}" |
| 211 | + fi |
| 212 | + if [ "${#wrong_version_assets[@]}" -gt 0 ]; then |
| 213 | + echo "Unexpected artifact versions:" |
| 214 | + printf ' %s\n' "${wrong_version_assets[@]}" |
| 215 | + fi |
| 216 | + echo "" |
| 217 | + echo "Artifacts in $DIST_DIR:" |
| 218 | + find "$DIST_DIR" -maxdepth 1 -type f -exec basename {} \; | sort | sed 's/^/ /' |
| 219 | + exit 1 |
| 220 | +fi |
| 221 | + |
167 | 222 | if [ "$SIGN" = true ]; then |
168 | 223 | echo "" |
169 | 224 | echo "Signing artifacts with GPG..." |
|
183 | 238 | if [ "$RELEASE" = true ]; then |
184 | 239 | echo "" |
185 | 240 | echo "Creating GitHub release $TAG..." |
| 241 | + if gh release view "$TAG" --repo "$REPO" >/dev/null 2>&1; then |
| 242 | + echo "ERROR: GitHub release $TAG already exists. Delete it or use gh release upload --clobber intentionally." |
| 243 | + exit 1 |
| 244 | + fi |
186 | 245 | mapfile -t release_assets < <(find "$DIST_DIR" -maxdepth 1 -type f) |
187 | 246 | gh release create "$TAG" \ |
188 | 247 | --repo "$REPO" \ |
|
0 commit comments