Skip to content

Instantly share code, notes, and snippets.

@KtorZ
Last active October 21, 2022 15:38
Show Gist options
  • Save KtorZ/ee63855c893747f5156da171027793e8 to your computer and use it in GitHub Desktop.
Save KtorZ/ee63855c893747f5156da171027793e8 to your computer and use it in GitHub Desktop.
Drop-in Github workflow for Haskell projects using stack.
name: Code Style
on:
pull_request:
branches: [ "master" ]
push:
branches: [ "master" ]
tags: [ "*.*.*" ]
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: πŸ“₯ Checkout repository
uses: actions/checkout@v1
- name: ✍ Check hlint and stylish
run: |
curl -sSL https://raw.github.com/ndmitchell/hlint/master/misc/run.sh | sh -s .
curl -sSL https://raw.github.com/jaspervdj/stylish-haskell/master/scripts/latest.sh | sh -s $(find . -type f -name "*.hs" ! -path "*.stack-work*") -i
if [ -z "$(git status --porcelain)" ]; then
echo "No style errors detected."
else
echo "Style errors detected:"
git --no-pager diff
exit 1
fi
name: Continuous Integration
on:
pull_request:
branches: [ "master" ]
push:
branches: [ "master" ]
tags: [ "*.*.*" ]
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: πŸ’½ Install OS Packages
uses: mstksg/get-package@v1
with:
apt-get: libgmp-dev
- name: πŸ“₯ Checkout repository
uses: actions/checkout@v1
- name: 🧰 Setup Stack
uses: mstksg/setup-stack@v1
- name: πŸ”‘ Cache Key
id: cache_key
run: echo ::set-output name=key::$(md5sum stack.yaml | awk '{print $1}')
- name: πŸ’Ύ Cache Dependencies
id: cache
uses: actions/cache@v1
with:
path: ~/.stack
key: ${{ matrix.os }}-${{ steps.cache_key.outputs.key }}
- name: 🏷️ Variables
id: variables
run: |
echo ::set-output name=pkg_name::$(cat *.cabal | grep "name:" | sed "s/name:\s*\(.*\)/\1/")
- name: πŸ“Έ Build Snapshot
if: steps.cache.outputs.cache-hit != 'true'
run: |
stack --no-terminal test --bench --only-snapshot
- name: πŸ”¨ Build & Test
run: |
stack --no-terminal test --bench --haddock --no-haddock-deps --no-run-benchmarks
mkdir -p dist/haddock && mv $(stack path --local-install-root)/doc/* dist/haddock
sed -i 's@href="[^"]*/doc/\([^"]*.html\)"@href="\1"@g' dist/haddock/index.html
wget -O Makefile https://gist.githubusercontent.com/KtorZ/0c7411f9bda2db1b3e0ded2ef0c40381/raw/1f818bd0385d8d917903e3f67ee3bfee3002de7a/Makefile
mkdir -p .coverage && touch .coverage/template.overlay
DESTDIR=dist/coverage make report && DESTDIR=dist/coverage make badge
env:
PKG_NAME: ${{ steps.variables.outputs.pkg_name }}
- name: πŸ“˜ Publish Documentation
if: matrix.os == 'ubuntu-latest' && github.event_name == 'push'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: dist
enable_jekyll: true
release:
needs: [build]
if: ${{ startsWith(github.ref, 'refs/tags') }}
runs-on: ubuntu-latest
steps:
- name: πŸ“₯ Checkout repository
uses: actions/checkout@v1
- name: πŸš€ Release
uses: docker://antonyurchenko/git-release:latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DRAFT_RELEASE: "true"
PRE_RELEASE: "false"
CHANGELOG_FILE: "ChangeLog.md"
ALLOW_EMPTY_CHANGELOG: "false"
ALLOW_TAG_PREFIX: "true"
@cad0p
Copy link

cad0p commented Oct 21, 2022

I would suggest to change the script in line 24 to this one, as github changed the way it works now to retrieve the latest stylish-haskell release file.

https://raw.githubusercontent.com/cad0p/uu-afp-2021-assign2/master/scripts/stylish-haskell.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment