Skip to content

Commit 898e58f

Browse files
authored
[ git ] Refactor CI workflow and optimize caching (#38)
* [ fix ] Update test.yaml WASM build to match wasm.yaml approach * [ fix ] Add delay to dev release creation to avoid draft status * [ change ][ ci ] Create dev release on either `dev` or `ci` branches * [ fix ] Dependency of ghc-wasm-meta * [ change ][ ci ] Consolidate release creation * [ change ][ ci ] Split the workflow into: build + test -> release -> upload * [ change ][ ci ] Cache the Haskell toolchain * [ change ][ ci ] Improve CI caching strategy * [ fix ][ ci ] Prevent mixing cache key on ARM64 and Intel macOS
1 parent 9ee766f commit 898e58f

File tree

2 files changed

+136
-85
lines changed

2 files changed

+136
-85
lines changed

.github/workflows/release.yaml

Lines changed: 0 additions & 28 deletions
This file was deleted.

.github/workflows/test.yaml

Lines changed: 136 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ on:
1616

1717
jobs:
1818
build-and-test:
19-
runs-on: ${{ matrix.os }}
19+
name: Build and Test
20+
runs-on: ${{ matrix.os }}
2021
strategy:
2122
matrix:
2223
os: [windows-latest, ubuntu-latest, macos-latest, macos-13]
@@ -67,6 +68,19 @@ jobs:
6768
echo STACK_RESOLVER="${STACK_RESOLVER}" >> "${GITHUB_ENV}"
6869
echo GHC_VERSION="${GHC_VERSION}" >> "${GITHUB_ENV}"
6970
71+
- name: 💾 Cache Haskell toolchain
72+
if: runner.os == 'macOS'
73+
uses: actions/cache@v4
74+
with:
75+
path: |
76+
~/.ghcup
77+
~/.stack/programs
78+
~/.stack/pantry
79+
key: ${{ runner.os }}-${{ runner.arch }}-haskell-${{ env.GHC_VERSION }}-stack-latest
80+
restore-keys: |
81+
${{ runner.os }}-${{ runner.arch }}-haskell-${{ env.GHC_VERSION }}-
82+
${{ runner.os }}-${{ runner.arch }}-haskell-
83+
7084
- name: 🏗 Setup Haskell
7185
if : runner.os == 'macOS'
7286
uses: haskell-actions/setup@v2
@@ -299,45 +313,23 @@ jobs:
299313
mv zip/"$($env:ARTEFACT).zip" .
300314
301315
- name: 🧪 Run tests
302-
run: stack test $STACK_YAML_ARG --ta --als-path=zip/als
303-
304-
# release (optional)
305-
- name: 🚢 Release Artifacts (stable)
306-
if: startsWith(github.ref, 'refs/tags/v') # so that only commits with a git tag would upload artifacts
307-
env:
308-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
309-
run: gh release upload ${{ github.ref_name }} $ARTEFACT.zip --clobber
316+
run: stack test $STACK_YAML_ARG
310317

311-
# dev release (optional)
312-
- name: 🚢 Create/Update Dev Release
313-
if: github.ref == 'refs/heads/dev' && matrix.agda == 'Agda-2.8.0' && matrix.os == 'ubuntu-latest'
314-
env:
315-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
316-
run: |
317-
# Delete existing dev release if it exists
318-
gh release delete dev --cleanup-tag -y || true
319-
320-
# Create new dev pre-release
321-
gh release create dev \
322-
--title "Development Release (dev)" \
323-
--notes "Development pre-release build from latest changes. This is a pre-release for testing purposes." \
324-
--prerelease
325-
326-
- name: 📤 Upload artifacts to dev release
327-
if: github.ref == 'refs/heads/dev' && matrix.agda == 'Agda-2.8.0'
328-
env:
329-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
330-
run: |
331-
gh release upload dev $ARTEFACT.zip --clobber
318+
- name: 📤 Upload build artifact
319+
uses: actions/upload-artifact@v4
320+
with:
321+
name: ${{ env.ARTEFACT }}
322+
path: ${{ env.ARTEFACT }}.zip
323+
retention-days: 1
332324

333325
build-wasm:
334326
name: Build WASM
335-
if: github.ref == 'refs/heads/dev'
327+
if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/ci'
336328
runs-on: ubuntu-22.04
337329

338330
env:
339331
GHC_WASM_META_FLAVOUR: '9.10'
340-
GHC_WASM_META_COMMIT_HASH: '7927129e42bcd6a54b9e06e26455803fa4878261'
332+
GHC_WASM_META_COMMIT_HASH: 'c3f44696d29aaeadd755d69c51735954bfcd59db'
341333

342334
steps:
343335
- uses: actions/checkout@v4
@@ -354,6 +346,8 @@ jobs:
354346
with:
355347
path: ~/.ghc-wasm
356348
key: ghc-wasm-${{ env.CI_CACHE_KEY }}
349+
restore-keys: |
350+
ghc-wasm-${{ runner.os }}-${{ runner.arch }}-
357351
358352
- name: Try to restore cached native cabal
359353
id: native-cabal-cache-restore
@@ -363,15 +357,17 @@ jobs:
363357
~/.config/cabal
364358
~/.cache/cabal
365359
key: native-cabal-${{ env.CI_CACHE_KEY }}
360+
restore-keys: |
361+
native-cabal-${{ runner.os }}-${{ runner.arch }}-
366362
367363
- name: Try to restore cached dist-newstyle
368364
id: dist-newstyle-cache-restore
369365
uses: actions/cache/restore@v4
370366
with:
371367
path: als/dist-newstyle
372-
key: dist-newstyle-${{ env.CI_CACHE_KEY }}-${{ hashFiles('als/dist-newstyle/**') }}
368+
key: dist-newstyle-${{ env.CI_CACHE_KEY }}
373369
restore-keys: |
374-
dist-newstyle-${{ env.CI_CACHE_KEY }}-
370+
dist-newstyle-${{ runner.os }}-${{ runner.arch }}-
375371
376372
- name: Clone and setup ghc-wasm-meta
377373
id: ghc-wasm-setup
@@ -407,27 +403,19 @@ jobs:
407403
mv cabal.project.wasm32 cabal.project
408404
wasm32-wasi-cabal configure --flag=Agda-2-8-0
409405
410-
- name: 'Build dep: lsp-types'
411-
uses: nick-fields/retry@v3
412-
id: build-dep-lsp-types
413-
with:
414-
timeout_minutes: 10
415-
max_attempts: 2
416-
command: cd als && wasm32-wasi-cabal build lib:lsp-types
417-
418-
- name: 'Build dep: agda'
406+
- name: Build Agda as dependency
419407
id: build-dep-agda
420408
working-directory: './als'
421409
run: wasm32-wasi-cabal build lib:agda
422410

423411
- name: Cache dist-newstyle
424412
uses: actions/cache/save@v4
425-
if: steps.build-dep-lsp-types.outcome == 'success' && steps.build-dep-agda.outcome == 'success'
413+
if: steps.build-dep-agda.outcome == 'success'
426414
with:
427415
path: als/dist-newstyle
428-
key: dist-newstyle-${{ env.CI_CACHE_KEY }}-${{ hashFiles('als/dist-newstyle/**') }}
416+
key: dist-newstyle-${{ env.CI_CACHE_KEY }}
429417

430-
- name: Build dependencies
418+
- name: Build dependencies other than Agda
431419
working-directory: './als'
432420
run: |
433421
# Setup network submodule autotools
@@ -466,17 +454,108 @@ jobs:
466454
path: ~/.ghc-wasm
467455
key: ${{ steps.ghc-wasm-cache-restore.outputs.cache-primary-key }}
468456

469-
- name: 📤 Upload WASM to dev release
457+
- name: 📤 Upload WASM artifact
458+
uses: actions/upload-artifact@v4
459+
with:
460+
name: als-dev-wasm
461+
path: ~/out/${{ env.WASM_BINARY_NAME }}
462+
retention-days: 1
463+
464+
create-release:
465+
name: Create Release
466+
needs: [build-and-test, build-wasm]
467+
if: always() && !cancelled() && !contains(needs.*.result, 'failure') && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/ci')
468+
runs-on: ubuntu-latest
469+
steps:
470+
471+
- name: 📥 Checkout repository
472+
uses: actions/checkout@v4
473+
474+
- name: 🏭 Create Stable Release
475+
if: startsWith(github.ref, 'refs/tags/v')
476+
run: |
477+
gh release create ${{ github.ref_name }} --generate-notes
478+
env:
479+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
480+
481+
- name: 🚢 Create/Update Dev Release
482+
if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/ci'
470483
env:
471484
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
472485
run: |
473-
cd ~/out
474-
ls -la
475-
echo "Looking for WASM binary: $WASM_BINARY_NAME"
476-
if [ -f "$WASM_BINARY_NAME" ]; then
477-
mv "$WASM_BINARY_NAME" als-dev-wasm
478-
gh release upload dev als-dev-wasm --clobber --repo ${{ github.repository }}
479-
else
480-
echo "WASM binary '$WASM_BINARY_NAME' not found in ~/out"
481-
exit 1
482-
fi
486+
# Delete existing dev release if it exists
487+
gh release delete dev --cleanup-tag -y || true
488+
489+
# Wait for GitHub to process the deletion to avoid race condition
490+
# that causes releases to be created as drafts
491+
# See: https://github.com/cli/cli/issues/8458
492+
sleep 5
493+
494+
# Create new dev pre-release
495+
gh release create dev \
496+
--title "Development Release (dev)" \
497+
--notes "Development pre-release build from latest changes. This is a pre-release for testing purposes." \
498+
--prerelease
499+
500+
upload-stable-release:
501+
name: Upload to Stable Release
502+
needs: create-release
503+
if: startsWith(github.ref, 'refs/tags/v')
504+
runs-on: ubuntu-latest
505+
steps:
506+
507+
- name: 📥 Download all artifacts
508+
uses: actions/download-artifact@v4
509+
with:
510+
path: artifacts
511+
512+
- name: 🚢 Upload artifacts to release
513+
env:
514+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
515+
run: |
516+
cd artifacts
517+
for dir in */; do
518+
artifact_name="${dir%/}"
519+
echo "Uploading ${artifact_name}..."
520+
if [ -f "${artifact_name}/${artifact_name}.zip" ]; then
521+
gh release upload ${{ github.ref_name }} "${artifact_name}/${artifact_name}.zip" --clobber --repo ${{ github.repository }}
522+
else
523+
echo "Warning: No .zip file found in ${artifact_name}"
524+
fi
525+
done
526+
527+
upload-dev-release:
528+
name: Upload to Dev Release
529+
needs: create-release
530+
if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/ci'
531+
runs-on: ubuntu-latest
532+
steps:
533+
534+
- name: 📥 Download all artifacts
535+
uses: actions/download-artifact@v4
536+
with:
537+
path: artifacts
538+
539+
- name: 🚢 Upload artifacts to dev release
540+
env:
541+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
542+
run: |
543+
cd artifacts
544+
# Upload only Agda-2.8.0 artifacts and WASM
545+
for dir in *Agda-2.8.0* als-dev-wasm; do
546+
if [ -d "$dir" ]; then
547+
artifact_name="$dir"
548+
echo "Uploading ${artifact_name}..."
549+
if [ -f "${artifact_name}/${artifact_name}.zip" ]; then
550+
gh release upload dev "${artifact_name}/${artifact_name}.zip" --clobber --repo ${{ github.repository }}
551+
elif [ "$artifact_name" = "als-dev-wasm" ]; then
552+
# Find the WASM binary (filename may vary)
553+
wasm_file=$(find "${artifact_name}" -type f -name "als*" | head -1)
554+
if [ -n "$wasm_file" ]; then
555+
gh release upload dev "$wasm_file" --clobber --repo ${{ github.repository }}
556+
else
557+
echo "Warning: WASM binary not found in ${artifact_name}"
558+
fi
559+
fi
560+
fi
561+
done

0 commit comments

Comments
 (0)