Skip to content

Commit 2f031e6

Browse files
ysangkokandreasabel
authored andcommitted
Separate examples.md file
1 parent cbf8b7a commit 2f031e6

File tree

2 files changed

+191
-192
lines changed

2 files changed

+191
-192
lines changed

README.md

+1-192
Original file line numberDiff line numberDiff line change
@@ -17,198 +17,7 @@ For all other versions, this action utilizes
1717

1818
## Usage
1919

20-
See [action.yml](action.yml)
21-
22-
### Minimal
23-
24-
```yaml
25-
on: [push]
26-
name: build
27-
jobs:
28-
runhaskell:
29-
name: Hello World
30-
runs-on: ubuntu-latest # or macOS-latest, or windows-latest
31-
steps:
32-
- uses: actions/checkout@v4
33-
- uses: haskell-actions/setup@v2
34-
- run: runhaskell Hello.hs
35-
```
36-
37-
### Basic
38-
39-
```yaml
40-
on: [push]
41-
name: build
42-
jobs:
43-
runhaskell:
44-
name: Hello World
45-
runs-on: ubuntu-latest # or macOS-latest, or windows-latest
46-
steps:
47-
- uses: actions/checkout@v4
48-
- uses: haskell-actions/setup@v2
49-
with:
50-
ghc-version: '8.8' # Resolves to the latest point release of GHC 8.8
51-
cabal-version: '3.0.0.0' # Exact version of Cabal
52-
- run: runhaskell Hello.hs
53-
```
54-
55-
### Basic with Stack
56-
57-
```yaml
58-
on: [push]
59-
name: build
60-
jobs:
61-
runhaskell:
62-
name: Hello World
63-
runs-on: ubuntu-latest # or macOS-latest, or windows-latest
64-
steps:
65-
- uses: actions/checkout@v4
66-
- uses: haskell-actions/setup@v2
67-
with:
68-
ghc-version: '8.8.4' # Exact version of ghc to use
69-
# cabal-version: 'latest'. Omitted, but defaults to 'latest'
70-
enable-stack: true
71-
stack-version: 'latest'
72-
- run: runhaskell Hello.hs
73-
```
74-
75-
### Matrix Testing
76-
77-
```yaml
78-
on: [push]
79-
name: build
80-
jobs:
81-
build:
82-
runs-on: ${{ matrix.os }}
83-
strategy:
84-
matrix:
85-
ghc: ['8.6.5', '8.8.4']
86-
cabal: ['2.4.1.0', '3.0.0.0']
87-
os: [ubuntu-latest, macOS-latest, windows-latest]
88-
exclude:
89-
# GHC 8.8+ only works with cabal v3+
90-
- ghc: 8.8.4
91-
cabal: 2.4.1.0
92-
name: Haskell GHC ${{ matrix.ghc }} sample
93-
steps:
94-
- uses: actions/checkout@v4
95-
- name: Setup Haskell
96-
uses: haskell-actions/setup@v2
97-
with:
98-
ghc-version: ${{ matrix.ghc }}
99-
cabal-version: ${{ matrix.cabal }}
100-
- run: runhaskell Hello.hs
101-
```
102-
103-
### Multiple GHC versions
104-
105-
If you need multiple versions of GHC installed at the same time, it is possible
106-
to run the action twice.
107-
108-
```yaml
109-
- uses: haskell-actions/setup@v2
110-
with:
111-
ghc-version: '9.8.2'
112-
113-
- uses: haskell-actions/setup@v2
114-
with:
115-
ghc-version: '8.10.7'
116-
```
117-
118-
### Model cabal workflow with caching
119-
120-
```yaml
121-
name: build
122-
on:
123-
push:
124-
branches: [main, master]
125-
pull_request:
126-
branches: [main, master]
127-
128-
# INFO: The following configuration block ensures that only one build runs per branch,
129-
# which may be desirable for projects with a costly build process.
130-
# Remove this block from the CI workflow to let each CI job run to completion.
131-
concurrency:
132-
group: build-${{ github.ref }}
133-
cancel-in-progress: true
134-
135-
jobs:
136-
build:
137-
name: GHC ${{ matrix.ghc-version }} on ${{ matrix.os }}
138-
runs-on: ${{ matrix.os }}
139-
strategy:
140-
fail-fast: false
141-
matrix:
142-
os: [ubuntu-latest]
143-
ghc-version: ['9.8', '9.6', '9.4', '9.2', '9.0']
144-
145-
include:
146-
- os: windows-latest
147-
ghc-version: '9.8'
148-
- os: macos-latest
149-
ghc-version: '9.8'
150-
151-
steps:
152-
- uses: actions/checkout@v4
153-
154-
- name: Set up GHC ${{ matrix.ghc-version }}
155-
uses: haskell-actions/setup@v2
156-
id: setup
157-
with:
158-
ghc-version: ${{ matrix.ghc-version }}
159-
# Defaults, added for clarity:
160-
cabal-version: 'latest'
161-
cabal-update: true
162-
163-
- name: Configure the build
164-
run: |
165-
cabal configure --enable-tests --enable-benchmarks --disable-documentation
166-
cabal build all --dry-run
167-
# The last step generates dist-newstyle/cache/plan.json for the cache key.
168-
169-
- name: Restore cached dependencies
170-
uses: actions/cache/restore@v4
171-
id: cache
172-
env:
173-
key: ${{ runner.os }}-ghc-${{ steps.setup.outputs.ghc-version }}-cabal-${{ steps.setup.outputs.cabal-version }}
174-
with:
175-
path: ${{ steps.setup.outputs.cabal-store }}
176-
key: ${{ env.key }}-plan-${{ hashFiles('**/plan.json') }}
177-
restore-keys: ${{ env.key }}-
178-
179-
- name: Install dependencies
180-
# If we had an exact cache hit, the dependencies will be up to date.
181-
if: steps.cache.outputs.cache-hit != 'true'
182-
run: cabal build all --only-dependencies
183-
184-
# Cache dependencies already here, so that we do not have to rebuild them should the subsequent steps fail.
185-
- name: Save cached dependencies
186-
uses: actions/cache/save@v4
187-
# If we had an exact cache hit, trying to save the cache would error because of key clash.
188-
if: steps.cache.outputs.cache-hit != 'true'
189-
with:
190-
path: ${{ steps.setup.outputs.cabal-store }}
191-
key: ${{ steps.cache.outputs.cache-primary-key }}
192-
193-
- name: Build
194-
run: cabal build all
195-
196-
- name: Run tests
197-
run: cabal test all
198-
199-
- name: Check cabal file
200-
run: cabal check
201-
202-
- name: Build documentation
203-
run:
204-
cabal haddock all --disable-documentation
205-
# --disable-documentation disables building documentation for dependencies.
206-
# The package's own documentation is still built,
207-
# yet contains no links to the documentation of the dependencies.
208-
```
209-
210-
Alternatively, the two occurrences of `--disable-documentation` can be changed to `--enable-documentation`, for resolving the external references to the documentation of the dependencies.
211-
This will increase build times a bit, though.
20+
See [action.yml](action.yml) and [docs/examples.md](docs/examples.md).
21221

21322
## Inputs
21423

docs/examples.md

+190
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
### Minimal
2+
3+
```yaml
4+
on: [push]
5+
name: build
6+
jobs:
7+
runhaskell:
8+
name: Hello World
9+
runs-on: ubuntu-latest # or macOS-latest, or windows-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: haskell-actions/setup@v2
13+
- run: runhaskell Hello.hs
14+
```
15+
16+
### Basic
17+
18+
```yaml
19+
on: [push]
20+
name: build
21+
jobs:
22+
runhaskell:
23+
name: Hello World
24+
runs-on: ubuntu-latest # or macOS-latest, or windows-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: haskell-actions/setup@v2
28+
with:
29+
ghc-version: '8.8' # Resolves to the latest point release of GHC 8.8
30+
cabal-version: '3.0.0.0' # Exact version of Cabal
31+
- run: runhaskell Hello.hs
32+
```
33+
34+
### Basic with Stack
35+
36+
```yaml
37+
on: [push]
38+
name: build
39+
jobs:
40+
runhaskell:
41+
name: Hello World
42+
runs-on: ubuntu-latest # or macOS-latest, or windows-latest
43+
steps:
44+
- uses: actions/checkout@v4
45+
- uses: haskell-actions/setup@v2
46+
with:
47+
ghc-version: '8.8.4' # Exact version of ghc to use
48+
# cabal-version: 'latest'. Omitted, but defaults to 'latest'
49+
enable-stack: true
50+
stack-version: 'latest'
51+
- run: runhaskell Hello.hs
52+
```
53+
54+
### Matrix Testing
55+
56+
```yaml
57+
on: [push]
58+
name: build
59+
jobs:
60+
build:
61+
runs-on: ${{ matrix.os }}
62+
strategy:
63+
matrix:
64+
ghc: ['8.6.5', '8.8.4']
65+
cabal: ['2.4.1.0', '3.0.0.0']
66+
os: [ubuntu-latest, macOS-latest, windows-latest]
67+
exclude:
68+
# GHC 8.8+ only works with cabal v3+
69+
- ghc: 8.8.4
70+
cabal: 2.4.1.0
71+
name: Haskell GHC ${{ matrix.ghc }} sample
72+
steps:
73+
- uses: actions/checkout@v4
74+
- name: Setup Haskell
75+
uses: haskell-actions/setup@v2
76+
with:
77+
ghc-version: ${{ matrix.ghc }}
78+
cabal-version: ${{ matrix.cabal }}
79+
- run: runhaskell Hello.hs
80+
```
81+
82+
### Multiple GHC versions
83+
84+
If you need multiple versions of GHC installed at the same time, it is possible
85+
to run the action twice.
86+
87+
```yaml
88+
- uses: haskell-actions/setup@v2
89+
with:
90+
ghc-version: '9.8.2'
91+
92+
- uses: haskell-actions/setup@v2
93+
with:
94+
ghc-version: '8.10.7'
95+
```
96+
97+
### Model cabal workflow with caching
98+
99+
```yaml
100+
name: build
101+
on:
102+
push:
103+
branches: [main, master]
104+
pull_request:
105+
branches: [main, master]
106+
107+
# INFO: The following configuration block ensures that only one build runs per branch,
108+
# which may be desirable for projects with a costly build process.
109+
# Remove this block from the CI workflow to let each CI job run to completion.
110+
concurrency:
111+
group: build-${{ github.ref }}
112+
cancel-in-progress: true
113+
114+
jobs:
115+
build:
116+
name: GHC ${{ matrix.ghc-version }} on ${{ matrix.os }}
117+
runs-on: ${{ matrix.os }}
118+
strategy:
119+
fail-fast: false
120+
matrix:
121+
os: [ubuntu-latest]
122+
ghc-version: ['9.8', '9.6', '9.4', '9.2', '9.0']
123+
124+
include:
125+
- os: windows-latest
126+
ghc-version: '9.8'
127+
- os: macos-latest
128+
ghc-version: '9.8'
129+
130+
steps:
131+
- uses: actions/checkout@v4
132+
133+
- name: Set up GHC ${{ matrix.ghc-version }}
134+
uses: haskell-actions/setup@v2
135+
id: setup
136+
with:
137+
ghc-version: ${{ matrix.ghc-version }}
138+
# Defaults, added for clarity:
139+
cabal-version: 'latest'
140+
cabal-update: true
141+
142+
- name: Configure the build
143+
run: |
144+
cabal configure --enable-tests --enable-benchmarks --disable-documentation
145+
cabal build all --dry-run
146+
# The last step generates dist-newstyle/cache/plan.json for the cache key.
147+
148+
- name: Restore cached dependencies
149+
uses: actions/cache/restore@v4
150+
id: cache
151+
env:
152+
key: ${{ runner.os }}-ghc-${{ steps.setup.outputs.ghc-version }}-cabal-${{ steps.setup.outputs.cabal-version }}
153+
with:
154+
path: ${{ steps.setup.outputs.cabal-store }}
155+
key: ${{ env.key }}-plan-${{ hashFiles('**/plan.json') }}
156+
restore-keys: ${{ env.key }}-
157+
158+
- name: Install dependencies
159+
# If we had an exact cache hit, the dependencies will be up to date.
160+
if: steps.cache.outputs.cache-hit != 'true'
161+
run: cabal build all --only-dependencies
162+
163+
# Cache dependencies already here, so that we do not have to rebuild them should the subsequent steps fail.
164+
- name: Save cached dependencies
165+
uses: actions/cache/save@v4
166+
# If we had an exact cache hit, trying to save the cache would error because of key clash.
167+
if: steps.cache.outputs.cache-hit != 'true'
168+
with:
169+
path: ${{ steps.setup.outputs.cabal-store }}
170+
key: ${{ steps.cache.outputs.cache-primary-key }}
171+
172+
- name: Build
173+
run: cabal build all
174+
175+
- name: Run tests
176+
run: cabal test all
177+
178+
- name: Check cabal file
179+
run: cabal check
180+
181+
- name: Build documentation
182+
run:
183+
cabal haddock all --disable-documentation
184+
# --disable-documentation disables building documentation for dependencies.
185+
# The package's own documentation is still built,
186+
# yet contains no links to the documentation of the dependencies.
187+
```
188+
189+
Alternatively, the two occurrences of `--disable-documentation` can be changed to `--enable-documentation`, for resolving the external references to the documentation of the dependencies.
190+
This will increase build times a bit, though.

0 commit comments

Comments
 (0)