Skip to content

Commit

Permalink
Refactoring CI workflows (#199)
Browse files Browse the repository at this point in the history
Co-authored-by: Cristhian Motoche <[email protected]>
Co-authored-by: David Mazarro <[email protected]>
  • Loading branch information
3 people authored Jun 9, 2022
1 parent 0054efc commit e80dc22
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 158 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# CI Workflows

## Overview

- [Build](build.yml)
- Build and test Haskell code
- Build Docker image
- [Draft](draft.yml)
- Create a GH draft release with a static binary
- [Release](release.yml)
- Upload the Docker image ghcr.io
- Upload the package and docs to Hackage

## Events

```mermaid
graph LR
event[GH Event]-->|on push|Build
event-->|tag created|Draft
Draft-->|create draft release|End
event-->|release published|Release
Release-->|upload artifacts to Hackage/GHCR|End
Build-->End
```
68 changes: 68 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# The present workflow was made based on the following references:
# - https://github.com/actions/cache/blob/main/examples.md#haskell---cabal
# - https://github.com/haskell/time/blob/master/.github/workflows/ci.yml
# - https://github.com/stackbuilders/stache/blob/master/.github/workflows/ci.yaml
# - https://markkarpov.com/post/github-actions-for-haskell-ci.html
---
name: Build

on: push

concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true

jobs:
haskell:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
ghc:
- "9.0"
- "8.10"

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install dependencies (Linux)
if: ${{ runner.os == 'Linux' }}
run: |
sudo apt-get update
sudo apt-get install zsh
- name: Install dependencies (macOS)
if: ${{ runner.os == 'macOS' }}
run: |
brew update
brew install zsh
- name: Install Haskell tooling
uses: haskell/actions/setup@v2
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: "3.6"
- name: Configure project
run: cabal configure --enable-tests
- name: Freeze dependencies
run: cabal freeze
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cabal/package
~/.cabal/store
dist-newstyle
key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }}
restore-keys: ${{ runner.os }}-${{ matrix.ghc }}-
- name: Build project
run: cabal build
- name: Run tests
run: cabal test
- name: Check documentation
run: ./script/haddock

docker:
uses: ./.github/workflows/reusable-docker.yml
with:
push: false
80 changes: 0 additions & 80 deletions .github/workflows/ci.yml

This file was deleted.

75 changes: 0 additions & 75 deletions .github/workflows/docker.yml

This file was deleted.

60 changes: 60 additions & 0 deletions .github/workflows/draft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# The present workflow was made based on the following references:
# - https://evilmartians.com/chronicles/build-images-on-github-actions-with-docker-layer-caching
# - https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md
# - https://github.com/commercialhaskell/stack/blob/master/.github/workflows/integration-tests.yml
---
name: Draft

on:
create:
tags:
- v*

concurrency:
group: draft-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: ${{ runner.os }}-buildx-
- name: Build Docker image
uses: docker/build-push-action@v2
with:
context: .
load: true
tags: ${{ github.repository }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
- name: Copy static binary
run: |
docker run \
--entrypoint cp \
--volume $PWD/bin:/root/bin \
${{ github.repository }} \
/usr/local/bin/hap \
/root/bin/hap-${{ github.ref_name }}-linux-x86_64-bin
- name: Create draft release
uses: softprops/action-gh-release@v1
with:
files: |
bin/hap-*
LICENSE
draft: true
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
60 changes: 60 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# The present workflow was made based on the following references:
# - https://github.com/tfausak/strive/blob/main/.github/workflows/ci.yaml
# - https://hackage.haskell.org/upload
---
name: Release

on:
release:
types:
- published

concurrency:
group: release-${{ github.ref }}
cancel-in-progress: true

jobs:
ghcr:
uses: ./.github/workflows/reusable-docker.yml
with:
push: true

hackage:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Haskell tooling
uses: haskell/actions/setup@v2
with:
ghc-version: "8.10"
cabal-version: "3.6"
- name: Freeze dependencies
run: cabal freeze
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cabal/package
~/.cabal/store
dist-newstyle
key: ${{ runner.os }}-${{ hashFiles('cabal.project.freeze') }}
restore-keys: ${{ runner.os }}-
- name: Generate a source distribution file
run: cabal sdist
- name: Upload package to Hackage
run: |
cabal upload --publish \
--username "${{ secrets.HACKAGE_USERNAME }}" \
--password "${{ secrets.HACKAGE_PASSWORD }}" \
dist-newstyle/sdist/hapistrano-*.tar.gz || \
echo "Already exists"
- name: Build Haddock documentation
run: cabal v2-haddock --haddock-for-hackage --enable-documentation
- name: Upload Haddock docs to Hackage
run: |
cabal upload --publish \
--username "${{ secrets.HACKAGE_USERNAME }}" \
--password "${{ secrets.HACKAGE_PASSWORD }}" \
--documentation \
dist-newstyle/hapistrano-*-docs.tar.gz
Loading

0 comments on commit e80dc22

Please sign in to comment.