Skip to content

Commit

Permalink
Separate examples.md file
Browse files Browse the repository at this point in the history
  • Loading branch information
ysangkok authored and andreasabel committed Jan 23, 2025
1 parent cbf8b7a commit 2f031e6
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 192 deletions.
193 changes: 1 addition & 192 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,198 +17,7 @@ For all other versions, this action utilizes

## Usage

See [action.yml](action.yml)

### Minimal

```yaml
on: [push]
name: build
jobs:
runhaskell:
name: Hello World
runs-on: ubuntu-latest # or macOS-latest, or windows-latest
steps:
- uses: actions/checkout@v4
- uses: haskell-actions/setup@v2
- run: runhaskell Hello.hs
```
### Basic
```yaml
on: [push]
name: build
jobs:
runhaskell:
name: Hello World
runs-on: ubuntu-latest # or macOS-latest, or windows-latest
steps:
- uses: actions/checkout@v4
- uses: haskell-actions/setup@v2
with:
ghc-version: '8.8' # Resolves to the latest point release of GHC 8.8
cabal-version: '3.0.0.0' # Exact version of Cabal
- run: runhaskell Hello.hs
```
### Basic with Stack
```yaml
on: [push]
name: build
jobs:
runhaskell:
name: Hello World
runs-on: ubuntu-latest # or macOS-latest, or windows-latest
steps:
- uses: actions/checkout@v4
- uses: haskell-actions/setup@v2
with:
ghc-version: '8.8.4' # Exact version of ghc to use
# cabal-version: 'latest'. Omitted, but defaults to 'latest'
enable-stack: true
stack-version: 'latest'
- run: runhaskell Hello.hs
```
### Matrix Testing
```yaml
on: [push]
name: build
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
ghc: ['8.6.5', '8.8.4']
cabal: ['2.4.1.0', '3.0.0.0']
os: [ubuntu-latest, macOS-latest, windows-latest]
exclude:
# GHC 8.8+ only works with cabal v3+
- ghc: 8.8.4
cabal: 2.4.1.0
name: Haskell GHC ${{ matrix.ghc }} sample
steps:
- uses: actions/checkout@v4
- name: Setup Haskell
uses: haskell-actions/setup@v2
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}
- run: runhaskell Hello.hs
```
### Multiple GHC versions
If you need multiple versions of GHC installed at the same time, it is possible
to run the action twice.
```yaml
- uses: haskell-actions/setup@v2
with:
ghc-version: '9.8.2'

- uses: haskell-actions/setup@v2
with:
ghc-version: '8.10.7'
```
### Model cabal workflow with caching
```yaml
name: build
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

# INFO: The following configuration block ensures that only one build runs per branch,
# which may be desirable for projects with a costly build process.
# Remove this block from the CI workflow to let each CI job run to completion.
concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: GHC ${{ matrix.ghc-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
ghc-version: ['9.8', '9.6', '9.4', '9.2', '9.0']

include:
- os: windows-latest
ghc-version: '9.8'
- os: macos-latest
ghc-version: '9.8'

steps:
- uses: actions/checkout@v4

- name: Set up GHC ${{ matrix.ghc-version }}
uses: haskell-actions/setup@v2
id: setup
with:
ghc-version: ${{ matrix.ghc-version }}
# Defaults, added for clarity:
cabal-version: 'latest'
cabal-update: true

- name: Configure the build
run: |
cabal configure --enable-tests --enable-benchmarks --disable-documentation
cabal build all --dry-run
# The last step generates dist-newstyle/cache/plan.json for the cache key.

- name: Restore cached dependencies
uses: actions/cache/restore@v4
id: cache
env:
key: ${{ runner.os }}-ghc-${{ steps.setup.outputs.ghc-version }}-cabal-${{ steps.setup.outputs.cabal-version }}
with:
path: ${{ steps.setup.outputs.cabal-store }}
key: ${{ env.key }}-plan-${{ hashFiles('**/plan.json') }}
restore-keys: ${{ env.key }}-

- name: Install dependencies
# If we had an exact cache hit, the dependencies will be up to date.
if: steps.cache.outputs.cache-hit != 'true'
run: cabal build all --only-dependencies

# Cache dependencies already here, so that we do not have to rebuild them should the subsequent steps fail.
- name: Save cached dependencies
uses: actions/cache/save@v4
# If we had an exact cache hit, trying to save the cache would error because of key clash.
if: steps.cache.outputs.cache-hit != 'true'
with:
path: ${{ steps.setup.outputs.cabal-store }}
key: ${{ steps.cache.outputs.cache-primary-key }}

- name: Build
run: cabal build all

- name: Run tests
run: cabal test all

- name: Check cabal file
run: cabal check

- name: Build documentation
run:
cabal haddock all --disable-documentation
# --disable-documentation disables building documentation for dependencies.
# The package's own documentation is still built,
# yet contains no links to the documentation of the dependencies.
```

Alternatively, the two occurrences of `--disable-documentation` can be changed to `--enable-documentation`, for resolving the external references to the documentation of the dependencies.
This will increase build times a bit, though.
See [action.yml](action.yml) and [docs/examples.md](docs/examples.md).

## Inputs

Expand Down
190 changes: 190 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
### Minimal

```yaml
on: [push]
name: build
jobs:
runhaskell:
name: Hello World
runs-on: ubuntu-latest # or macOS-latest, or windows-latest
steps:
- uses: actions/checkout@v4
- uses: haskell-actions/setup@v2
- run: runhaskell Hello.hs
```
### Basic
```yaml
on: [push]
name: build
jobs:
runhaskell:
name: Hello World
runs-on: ubuntu-latest # or macOS-latest, or windows-latest
steps:
- uses: actions/checkout@v4
- uses: haskell-actions/setup@v2
with:
ghc-version: '8.8' # Resolves to the latest point release of GHC 8.8
cabal-version: '3.0.0.0' # Exact version of Cabal
- run: runhaskell Hello.hs
```
### Basic with Stack
```yaml
on: [push]
name: build
jobs:
runhaskell:
name: Hello World
runs-on: ubuntu-latest # or macOS-latest, or windows-latest
steps:
- uses: actions/checkout@v4
- uses: haskell-actions/setup@v2
with:
ghc-version: '8.8.4' # Exact version of ghc to use
# cabal-version: 'latest'. Omitted, but defaults to 'latest'
enable-stack: true
stack-version: 'latest'
- run: runhaskell Hello.hs
```
### Matrix Testing
```yaml
on: [push]
name: build
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
ghc: ['8.6.5', '8.8.4']
cabal: ['2.4.1.0', '3.0.0.0']
os: [ubuntu-latest, macOS-latest, windows-latest]
exclude:
# GHC 8.8+ only works with cabal v3+
- ghc: 8.8.4
cabal: 2.4.1.0
name: Haskell GHC ${{ matrix.ghc }} sample
steps:
- uses: actions/checkout@v4
- name: Setup Haskell
uses: haskell-actions/setup@v2
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}
- run: runhaskell Hello.hs
```
### Multiple GHC versions
If you need multiple versions of GHC installed at the same time, it is possible
to run the action twice.
```yaml
- uses: haskell-actions/setup@v2
with:
ghc-version: '9.8.2'

- uses: haskell-actions/setup@v2
with:
ghc-version: '8.10.7'
```
### Model cabal workflow with caching
```yaml
name: build
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

# INFO: The following configuration block ensures that only one build runs per branch,
# which may be desirable for projects with a costly build process.
# Remove this block from the CI workflow to let each CI job run to completion.
concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: GHC ${{ matrix.ghc-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
ghc-version: ['9.8', '9.6', '9.4', '9.2', '9.0']

include:
- os: windows-latest
ghc-version: '9.8'
- os: macos-latest
ghc-version: '9.8'

steps:
- uses: actions/checkout@v4

- name: Set up GHC ${{ matrix.ghc-version }}
uses: haskell-actions/setup@v2
id: setup
with:
ghc-version: ${{ matrix.ghc-version }}
# Defaults, added for clarity:
cabal-version: 'latest'
cabal-update: true

- name: Configure the build
run: |
cabal configure --enable-tests --enable-benchmarks --disable-documentation
cabal build all --dry-run
# The last step generates dist-newstyle/cache/plan.json for the cache key.

- name: Restore cached dependencies
uses: actions/cache/restore@v4
id: cache
env:
key: ${{ runner.os }}-ghc-${{ steps.setup.outputs.ghc-version }}-cabal-${{ steps.setup.outputs.cabal-version }}
with:
path: ${{ steps.setup.outputs.cabal-store }}
key: ${{ env.key }}-plan-${{ hashFiles('**/plan.json') }}
restore-keys: ${{ env.key }}-

- name: Install dependencies
# If we had an exact cache hit, the dependencies will be up to date.
if: steps.cache.outputs.cache-hit != 'true'
run: cabal build all --only-dependencies

# Cache dependencies already here, so that we do not have to rebuild them should the subsequent steps fail.
- name: Save cached dependencies
uses: actions/cache/save@v4
# If we had an exact cache hit, trying to save the cache would error because of key clash.
if: steps.cache.outputs.cache-hit != 'true'
with:
path: ${{ steps.setup.outputs.cabal-store }}
key: ${{ steps.cache.outputs.cache-primary-key }}

- name: Build
run: cabal build all

- name: Run tests
run: cabal test all

- name: Check cabal file
run: cabal check

- name: Build documentation
run:
cabal haddock all --disable-documentation
# --disable-documentation disables building documentation for dependencies.
# The package's own documentation is still built,
# yet contains no links to the documentation of the dependencies.
```

Alternatively, the two occurrences of `--disable-documentation` can be changed to `--enable-documentation`, for resolving the external references to the documentation of the dependencies.
This will increase build times a bit, though.

0 comments on commit 2f031e6

Please sign in to comment.