1- name : Build project
21
3- on : push
2+ name : Build
3+
4+ on :
5+ workflow_dispatch :
6+
7+ push :
8+ paths :
9+ - ' **'
10+ - ' !.github/**'
11+ - ' .github/workflows/applications.yml'
412
513jobs :
614 build :
7- name : Build
15+ if : " !startsWith(github.ref, 'refs/tags/') "
816 runs-on : ${{ matrix.os }}
917 strategy :
1018 fail-fast : false
1119 matrix :
12- ghc : ['9.6.4' ]
13- cabal : ['3.8' ]
14- os : [' ubuntu-20 .04', ' ubuntu-22 .04', 'macOS-latest' ]
20+ ghc : ["9.10.3" ]
21+ cabal : ["3.12" ]
22+ os : [" ubuntu-22 .04", " ubuntu-24 .04", "macos-14", "macos-15" ]
1523
1624 steps :
17- # Setup
1825 - name : Checkout repository
19- uses : actions/checkout@v3
26+ uses : actions/checkout@v4
27+ with :
28+ ref : ${{ inputs.commit_sha || github.sha }}
2029
2130 # Haskell Setup
31+ - name : Set permissions for .ghcup (ubuntu)
32+ if : startsWith(matrix.os, 'ubuntu-')
33+ run : sudo chown -R $USER /usr/local/.ghcup
2234 - name : Install GHC and Cabal
2335 uses : haskell-actions/setup@v2
2436 with :
@@ -29,140 +41,95 @@ jobs:
2941 ghc --version
3042 cabal --version
3143
32- # System dependencies
33- - if : startsWith(matrix.os, 'macOS')
34- name : Set up system depdendencies
35- run : |
36- brew install openssl
44+ - name : Setting up MPFR (Ubuntu)
45+ if : startsWith(matrix.os, 'ubuntu-')
46+ shell : bash
47+ run : sudo apt-get update && sudo apt-get install -y libmpfr-dev
3748
49+ # Project Setup
50+ - name : Create cabal.project.local
51+ shell : bash
52+ run : |
3853 cat > cabal.project.local <<EOF
39- package *
40- extra-include-dirs:
41- /opt/homebrew/include
42- /opt/homebrew/opt/openssl/include
43- extra-lib-dirs:
44- /opt/homebrew/lib
45- /opt/homebrew/opt/openssl/lib
54+ documentation: False
55+ package pact
56+ tests: True
57+ benchmarks: True
58+ documentation: False
59+ optimization: 1
60+ flags: ${{ matrix.flags }} +cryptonite-ed25519
61+ extra-include-dirs:
62+ /opt/local/include
63+ /usr/local/opt/openssl/include
64+ extra-lib-dirs:
65+ /opt/local/lib
66+ /usr/local/opt/openssl/lib/
4667 EOF
4768
48- # dist cache
49- # the cache-key forces uploading of cache at least once a day, which ensures that
50- # upstream dependency changes are captured regularly.
51- - name : Create date file for dist-newstyle cache key
52- id : cache-date
69+ - name : Extend cabal.project.local for GHC-9.0.2
70+ if : " startsWith(matrix.ghc, '9')"
71+ shell : bash
5372 run : |
54- echo "value=$(date +%Y.%j)" >> $GITHUB_OUTPUT
55- - uses : actions/cache@v3
56- name : Cache dist-newstyle
57- with :
58- path : |
59- ~/.cabal/packages
60- ~/.cabal/store
61- dist-newstyle
62- key : ${{ matrix.os }}-${{ matrix.ghc }}-${{ steps.cache-date.outputs.value }}-${{ hashFiles('cabal.*', '*.cabal', 'src/**', 'test/**') }}
63- restore-keys : |
64- ${{ matrix.os }}-${{ matrix.ghc }}-${{ steps.cache-date.outputs.value }}-
65- ${{ matrix.os }}-${{ matrix.ghc }}-
66-
67- # Build
68- - name : Update package database
69- run : cabal update
70- - name : Display outdated packages
71- run : cabal outdated
72- - name : Install build dependencies
73- run : cabal build --only-dependencies
74- - name : Build
75- run : cabal build
76- - name : Show installed packages
77- run : cabal freeze && cat cabal.project.freeze
78-
79- # Upload artifacts
80- - name : Copy build artifact
81- run : cp `cabal list-bin exe:kda` .
82- - name : Stripping binary
83- run : strip kda
84- - uses : actions/upload-artifact@v4
85- with :
86- name : kda-build-${{ matrix.os }}-${{ matrix.ghc }}
87- path : kda
88-
89- # Test
90- - name : Test
91- run : cabal test
73+ cat >> cabal.project.local <<EOF
74+ package pact
75+ ghc-options: -Wwarn -Wunused-packages
76+ EOF
9277
93- # ########################################################################## #
94- # Build and publish docker image
78+ - name : Add check for unused packages
79+ shell : bash
80+ run : |
81+ cat >> cabal.project.local <<EOF
82+ package pact
83+ ghc-options: -Wunused-packages
84+ EOF
9585
96- docker-image :
97- name : Build and publish docker image
98- needs : [build]
99- runs-on : ${{ matrix.os }}
100- strategy :
101- fail-fast : false
102- matrix :
103- ghc : ["9.6.4"]
104- os : ["ubuntu-20.04"]
86+ - name : Print cabal.project.local
87+ shell : bash
88+ run : cat cabal.project.local
10589
106- steps :
107- - name : Get build artifacts
108- uses : actions/download-artifact@v3
109- with :
110- name : kda-build-${{ matrix.os }}-${{ matrix.ghc }}
111- path : .
90+ - name : Update package database
91+ shell : bash
92+ run : cabal update
11293
113- - name : Create Dockerfile
94+ - name : Configure build / and freeze
11495 run : |
115- chmod 755 kda
116- export OS=${{ matrix.os }}
117- cat > Dockerfile <<EOF
118- FROM ubuntu:${OS#ubuntu-}
119- LABEL com.chainweb.docker.image.compiler="ghc-${{ matrix.ghc }}"
120- LABEL com.chainweb.docker.image.os="${OS}"
121- RUN apt-get update && apt-get install -y ca-certificates libgmp10 libssl1.1 locales && rm -rf /var/lib/apt/lists/* && locale-gen en_US.UTF-8 && update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
122- ENV LANG=en_US.UTF-8
123- WORKDIR /home/kda
124- COPY kda /usr/bin/
125- ENTRYPOINT ["/usr/bin/kda"]
126- EOF
96+ cabal build --dry-run
97+ cabal freeze
12798
128- - name : Docker meta
129- id : meta
130- uses : docker/metadata-action@v3
131- with :
132- images : ghcr.io/kadena-io/kda-tool
133- tags : |
134- type=sha
135- type=ref,event=branch
136- type=ref,event=tag
137- type=ref,event=pr
138-
139- - name : Set up Docker Buildx
140- uses : docker/setup-buildx-action@v1
141-
142- - name : Cache Docker layers
143- uses : actions/cache@v3
99+ - name : Generate cache key
100+ id : cache-key
101+ run : |
102+ grep -v '^index-state:' cabal.project.freeze > freeze-deps-only
103+ FREEZE_HASH=$(shasum freeze-deps-only | cut -d' ' -f1)
104+ echo "freeze-hash=$FREEZE_HASH" >> $GITHUB_OUTPUT
105+ rm freeze-deps-only
106+
107+ - name : Restore Cabal store
108+ id : restore-cabal
109+ uses : actions/cache/restore@v4
144110 with :
145- path : /tmp/.buildx-cache
146- key : ${{ runner .os }}-buildx -${{ github.sha }}
111+ path : ~/.cabal/store
112+ key : cabal- ${{ matrix .os }}-${{ matrix.ghc }} -${{ steps.cache-key.outputs.freeze-hash }}
147113 restore-keys : |
148- ${{ runner .os }}-buildx-
114+ cabal- ${{ matrix .os }}-${{ matrix.ghc }}
149115
150- - name : Login to GitHub Container Registry
151- uses : docker/login-action@v1
152- with :
153- registry : ghcr.io
154- username : kadena-build
155- password : ${{ secrets.GITHUB_TOKEN }}
116+ - name : Build dependencies
117+ if : steps.restore-cabal.outputs.cache-hit != 'true'
118+ shell : bash
119+ run : cabal build --only-dependencies
156120
157- - name : Build and push
158- id : docker_build
159- uses : docker/build-push-action@v2
121+ - name : Cache Cabal store if necessary
122+ if : steps.restore-cabal.outputs.cache-hit != 'true'
123+ uses : actions/cache/save@v4
160124 with :
161- push : true
162- context : .
163- file : ./Dockerfile
164- tags : ${{ steps.meta.outputs.tags }}
165- labels : ${{ steps.meta.outputs.labels }}
166- cache-from : type=local,src=/tmp/.buildx-cache
167- cache-to : type=local,dest=/tmp/.buildx-cache
125+ path : ~/.cabal/store
126+ key : cabal-${{ matrix.os }}-${{ matrix.ghc }}-${{ steps.cache-key.outputs.freeze-hash }}
127+
128+ - name : Build
129+ shell : bash
130+ run : cabal build
168131
132+ - name : Verify Binary Linking
133+ shell : bash
134+ if : " !contains(matrix.flags, '-build-tool')"
135+ run : cabal run exe:kda -- --version
0 commit comments