|
2 | 2 | # the result with what's expected. Expected failures use continue-on-error |
3 | 3 | # plus the assert-step-failed action. |
4 | 4 | # |
5 | | -# This repo has no releases of its own, so test-publish-pre-release tests |
6 | | -# the release action with test releases it creates and deletes. |
| 5 | +# This repo has no releases (its type is "no releases"), and the tests make |
| 6 | +# none: test-publish-pre-release uses a fake gh that keeps releases in a file. |
7 | 7 |
|
8 | 8 | name: actions-test |
9 | 9 |
|
@@ -241,47 +241,36 @@ jobs: |
241 | 241 | echo "Scan outcome correct: $ACTUAL_OUTCOME (expected $EXPECTED_OUTCOME)." |
242 | 242 |
|
243 | 243 | # -- publish-pre-release: the release text, the files, replacing a |
244 | | - # -- same-tag pre-release, protecting a stable one, and the cleanup. |
| 244 | + # -- same-tag pre-release, protecting a stable one, and the cleanup. With a |
| 245 | + # -- fake gh (tests/publish-pre-release/fake-gh) that keeps the releases in |
| 246 | + # -- a JSON file, so the tests make no real releases: this repo has none |
| 247 | + # -- (its type is "no releases"). The product repos' daily builds run the |
| 248 | + # -- action against GitHub every day, and repos-janitor checks the result. |
245 | 249 | test-publish-pre-release: |
246 | 250 | runs-on: ubuntu-latest |
247 | | - # Skipped for pull requests from forks, whose token can't change releases. |
248 | | - if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository |
249 | | - permissions: |
250 | | - contents: write |
251 | | - # One run at a time across all branches, since the cleanup acts on all |
252 | | - # of this repo's pre-releases. |
253 | | - concurrency: |
254 | | - group: test-release-actions |
255 | | - cancel-in-progress: false |
256 | | - timeout-minutes: 15 |
| 251 | + timeout-minutes: 10 |
257 | 252 | env: |
258 | | - GH_TOKEN: ${{ github.token }} |
259 | | - GH_REPO: ${{ github.repository }} |
260 | | - # All test releases start with "test-". Unique per run. |
261 | | - TAG: test-${{ github.run_id }}-${{ github.run_attempt }} |
| 253 | + FAKE_GH_STATE: ${{ github.workspace }}/_fake-releases.json |
| 254 | + # The cleanup's referenced tags: a fixture org where logix-ide's |
| 255 | + # dev.jsonc names this repo's test release p1. |
| 256 | + FAKE_GH_ORG: ${{ github.workspace }}/tests/publish-pre-release/org |
| 257 | + GH_TOKEN: unused |
262 | 258 |
|
263 | 259 | steps: |
264 | 260 | - name: Checkout this repo |
265 | 261 | uses: actions/checkout@v7 |
266 | 262 |
|
267 | | - - name: Delete test releases left by earlier runs |
268 | | - run: | |
269 | | - gh release list --limit 1000 --json tagName \ |
270 | | - --jq '.[].tagName | select(startswith("test-"))' | |
271 | | - while read -r tag; do |
272 | | - echo "Deleting $tag" |
273 | | - gh release delete "$tag" --yes |
274 | | - gh api -X DELETE "repos/$GH_REPO/git/refs/tags/$tag" 2>/dev/null || true |
275 | | - done |
| 263 | + - name: Use the fake gh in the next steps |
| 264 | + run: echo "$GITHUB_WORKSPACE/tests/publish-pre-release/fake-gh" >> "$GITHUB_PATH" |
276 | 265 |
|
277 | | - - name: Make the files of release A |
| 266 | + - name: Make the files of release a |
278 | 267 | run: | |
279 | | - jq -n --arg t "$TAG-a" --arg c "$GITHUB_SHA" \ |
280 | | - '{"package-name": "test", "description": "Test.", "release-tag": $t, "repo-commit": $c}' > BUILD-INFO.json |
| 268 | + jq -n --arg c "$GITHUB_SHA" \ |
| 269 | + '{"package-name": "test", "description": "Test.", "release-tag": "a", "repo-commit": $c}' > BUILD-INFO.json |
281 | 270 | echo "Asset one" > asset.txt |
282 | 271 | echo "Our own content, first." > content.md |
283 | 272 |
|
284 | | - - name: Publish release A |
| 273 | + - name: Publish release a |
285 | 274 | uses: ./actions/publish-pre-release |
286 | 275 | with: |
287 | 276 | title: "Test: A test release." |
@@ -291,12 +280,14 @@ jobs: |
291 | 280 | about-bullets: A repo-specific bullet. |
292 | 281 | files: asset.txt |
293 | 282 |
|
294 | | - - name: Check release A |
| 283 | + - name: Check release a |
295 | 284 | run: | |
296 | 285 | set -euo pipefail |
297 | | - gh release view "$TAG-a" --json isPrerelease,name,body,assets > release.json |
| 286 | + gh release view a --json isPrerelease,name,body,assets,target > release.json |
298 | 287 | jq -e '.isPrerelease == true' release.json |
299 | 288 | jq -e '[.assets[].name] | sort == ["BUILD-INFO.json", "SHA256SUMS", "asset.txt"]' release.json |
| 289 | + # The tag names the commit that was built. |
| 290 | + jq -e --arg c "$GITHUB_SHA" '.target == $c' release.json |
300 | 291 | jq -r .body release.json > body.md |
301 | 292 | cat body.md |
302 | 293 | # The sections, in order. |
@@ -308,30 +299,28 @@ jobs: |
308 | 299 | grep -q "The $PRERELEASE_KEEP newest are kept, and older ones while an Open Logix remote config names them" body.md |
309 | 300 | grep -q -- "- A repo-specific bullet." body.md |
310 | 301 | grep -q "$(sha256sum asset.txt | cut -c1-64) asset.txt" body.md |
311 | | - # The tag names the commit that was built. |
312 | | - [ "$(git ls-remote --tags origin "refs/tags/$TAG-a" | cut -f1)" = "$GITHUB_SHA" ] |
313 | 302 |
|
314 | 303 | - name: Change the content |
315 | 304 | run: echo "Our own content, second." > content.md |
316 | 305 |
|
317 | | - - name: Publish release A again, from scratch |
| 306 | + - name: Publish release a again, from scratch |
318 | 307 | uses: ./actions/publish-pre-release |
319 | 308 | with: |
320 | 309 | title: "Test: A test release." |
321 | 310 | content-file: content.md |
322 | 311 | files: asset.txt |
323 | 312 |
|
324 | | - - name: Check release A was replaced |
| 313 | + - name: Check release a was replaced |
325 | 314 | run: | |
326 | | - gh release view "$TAG-a" --json body --jq .body > body.md |
| 315 | + gh release view a --json body --jq .body > body.md |
327 | 316 | grep -q "Our own content, second." body.md |
328 | 317 | ! grep -q "Our own content, first." body.md |
329 | | - [ "$(gh release list --limit 1000 --json tagName --jq "[.[] | select(.tagName == \"$TAG-a\")] | length")" = 1 ] |
| 318 | + [ "$(gh release list --json tagName --jq '[.[] | select(.tagName == "a")] | length')" = 1 ] |
330 | 319 |
|
331 | | - - name: Make a stable release with tag S |
| 320 | + - name: Make a stable release, stable |
332 | 321 | run: | |
333 | | - gh release create "$TAG-stable" --title "$TAG-stable" --notes "Test" --latest=false |
334 | | - jq --arg t "$TAG-stable" '."release-tag" = $t' BUILD-INFO.json > b.json && mv b.json BUILD-INFO.json |
| 322 | + gh release create stable --title stable --notes "Test" --latest=false |
| 323 | + jq '."release-tag" = "stable"' BUILD-INFO.json > b.json && mv b.json BUILD-INFO.json |
335 | 324 |
|
336 | 325 | - name: Publish over the stable release |
337 | 326 | id: over-stable |
@@ -348,48 +337,29 @@ jobs: |
348 | 337 | error-message: "Publishing over a stable release did not fail as expected" |
349 | 338 |
|
350 | 339 | - name: Check the stable release is still stable |
351 | | - run: gh release view "$TAG-stable" --json isPrerelease --jq '.isPrerelease == false' | grep -q true |
| 340 | + run: gh release view stable --json isPrerelease --jq '.isPrerelease == false' | grep -q true |
352 | 341 |
|
353 | 342 | # The cleanup keeps the newest pre-releases by the policy (this test |
354 | | - # assumes 5) and leaves stable releases and drafts. |
| 343 | + # assumes 5), any a remote config names (p1, in the fixture org), and |
| 344 | + # leaves stable releases and drafts. |
355 | 345 | - name: Make 6 more pre-releases and a draft |
356 | 346 | run: | |
357 | 347 | for i in 1 2 3 4 5 6; do |
358 | | - sleep 2 |
359 | | - gh release create "$TAG-p$i" --title "$TAG-p$i" --notes "Test" --prerelease |
| 348 | + gh release create "p$i" --title "p$i" --notes "Test" --prerelease |
360 | 349 | done |
361 | | - gh release create "$TAG-draft" --title "$TAG-draft" --notes "Test" --prerelease --draft |
362 | | - sleep 2 |
363 | | - jq --arg t "$TAG-b" '."release-tag" = $t' BUILD-INFO.json > b.json && mv b.json BUILD-INFO.json |
| 350 | + gh release create draft --title draft --notes "Test" --prerelease --draft |
| 351 | + jq '."release-tag" = "b"' BUILD-INFO.json > b.json && mv b.json BUILD-INFO.json |
364 | 352 |
|
365 | | - - name: Publish release B, the newest |
| 353 | + - name: Publish release b, the newest |
366 | 354 | uses: ./actions/publish-pre-release |
367 | 355 | with: |
368 | 356 | title: "Test: A test release." |
369 | 357 | files: asset.txt |
370 | 358 |
|
371 | 359 | - name: Check what the cleanup kept |
372 | 360 | run: | |
373 | | - gh release list --limit 1000 --json tagName \ |
374 | | - --jq '[.[].tagName | select(startswith(env.TAG))] | sort | .[]' > actual.txt |
375 | | - printf '%s\n' "$TAG-b" "$TAG-draft" "$TAG-p3" "$TAG-p4" "$TAG-p5" "$TAG-p6" "$TAG-stable" | sort > expected.txt |
| 361 | + gh release list --json tagName --jq '[.[].tagName] | sort | .[]' > actual.txt |
| 362 | + printf '%s\n' b draft p1 p3 p4 p5 p6 stable | sort > expected.txt |
376 | 363 | echo "Expected:"; cat expected.txt |
377 | 364 | echo "Actual:"; cat actual.txt |
378 | 365 | diff expected.txt actual.txt |
379 | | - for t in a p1 p2; do |
380 | | - if [ -n "$(git ls-remote --tags origin "refs/tags/$TAG-$t")" ]; then |
381 | | - echo "Error: tag $TAG-$t still exists" >&2 |
382 | | - exit 1 |
383 | | - fi |
384 | | - done |
385 | | -
|
386 | | - - name: Delete this run's test releases |
387 | | - if: always() |
388 | | - run: | |
389 | | - gh release list --limit 1000 --json tagName \ |
390 | | - --jq '.[].tagName | select(startswith(env.TAG))' | |
391 | | - while read -r tag; do |
392 | | - echo "Deleting $tag" |
393 | | - gh release delete "$tag" --yes |
394 | | - gh api -X DELETE "repos/$GH_REPO/git/refs/tags/$tag" 2>/dev/null || true |
395 | | - done |