Skip to content

Commit

Permalink
Steal Hydra's ci
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch committed Aug 13, 2023
1 parent a990ecb commit f4aef61
Show file tree
Hide file tree
Showing 5 changed files with 275 additions and 0 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/actions/setup_dev_ubuntu/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: 'Setup dev environment'
description: 'Setup a dev environment for gh-action Ubuntu'
inputs:
version_ghc:
description: 'GHC version needed'
required: false
default: 9.2.8
version_cabal:
description: 'Cabal version needed'
required: false
default: 3.10.1.0
clean_caches:
description: 'Should we clean old caches for this branch and keep only the last one?'
require: false
default: false
runs:
using: "composite"
steps:

- name: "Clear old caches"
if: ${{ inputs.clean_caches == 'true' }}
shell: bash
run: |
.github/workflows/actions/setup_dev_ubuntu/clear_caches
env:
GH_TOKEN: ${{ github.token }}

- name: Cache environment setup
id: cache_env
uses: actions/cache@v3
with:
path: |
/usr/local/.ghcup/ghc/${{ inputs.version_ghc }}
/usr/local/.ghcup/bin/cabal-${{ inputs.version_cabal }}
/usr/local/.ghcup/bin/cabal
/usr/local/.ghcup/bin/ghc
${{ github.workspace }}/srv/
key: env-${{ runner.os }}-${{ hashFiles('.github/workflows/actions/setup_dev_ubuntu/install_libraries') }}

- name: Cache cabal storage
id: cache_cabal
uses: actions/cache@v3
with:
path: |
~/.cache/cabal/packages
~/.local/state/cabal
key: cabal-${{ runner.os }}-${{ hashFiles('**/*.cabal', '**/cabal.project', '**/cabal.project.freeze') }}
restore-keys: cabal-${{ runner.os }}-

- name: Cache cabal compilation directory
id: cache_dist
uses: actions/cache@v3
with:
path: |
dist-newstyle
key: dist-${{ runner.os }}-${{ github.run_id }}
restore-keys: dist-${{ runner.os }}-

- name: "Install packages"
shell: bash
run: |
.github/workflows/actions/setup_dev_ubuntu/install_packages
env:
VERSION_GHC: ${{ inputs.version_ghc }}

- name: "Setup build environment"
if: ${{ steps.cache_env.outputs.cache-hit != 'true' }}
shell: bash
run: |
.github/workflows/actions/setup_dev_ubuntu/install_libraries
- name: "Setup Environment"
shell: bash
run: |
echo "$(realpath $PWD/srv)/bin" >> $GITHUB_PATH
- name: cabal update
if: ${{ steps.cache_cabal.outputs.cache-hit != 'true' }}
shell: bash
run: |
cabal update
38 changes: 38 additions & 0 deletions .github/workflows/actions/setup_dev_ubuntu/clean_caches
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

set -euxo pipefail

main() {
gh extension install --force actions/gh-actions-cache

local repo="$GITHUB_REPOSITORY"
local branch="$GITHUB_REF"

list_caches $repo $branch dist \
| all_but_the_first_one \
| delete_cache $repo $branch
}

list_caches() {
local repo="$1"
local branch="$2"
local cache="$3"
gh actions-cache list -R "$repo" -B "$branch" --key "$cache" --order desc | cut -f 1
}

all_but_the_first_one() {
sed 1d
}

delete_cache() {
local repo="$1"
local branch="$2"

while read cache
do
echo "I could delete this cache (but I won't) if needed: $cache" >&2
echo gh actions-cache delete "$cache" -R "$repo" -B "$branch" --confirm
done
}

main "$@"
38 changes: 38 additions & 0 deletions .github/workflows/actions/setup_dev_ubuntu/install_libraries
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

set -euxo pipefail

main() {
gh extension install --force actions/gh-actions-cache

local repo="$GITHUB_REPOSITORY"
local branch="$GITHUB_REF"

list_caches $repo $branch dist \
| all_but_the_first_one \
| delete_cache $repo $branch
}

list_caches() {
local repo="$1"
local branch="$2"
local cache="$3"
gh actions-cache list -R "$repo" -B "$branch" --key "$cache" --order desc | cut -f 1
}

all_but_the_first_one() {
sed 1d
}

delete_cache() {
local repo="$1"
local branch="$2"

while read cache
do
echo "I could delete this cache (but I won't) if needed: $cache" >&2
echo gh actions-cache delete "$cache" -R "$repo" -B "$branch" --confirm
done
}

main "$@"
38 changes: 38 additions & 0 deletions .github/workflows/actions/setup_dev_ubuntu/install_packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

set -euxo pipefail

main() {
gh extension install --force actions/gh-actions-cache

local repo="$GITHUB_REPOSITORY"
local branch="$GITHUB_REF"

list_caches $repo $branch dist \
| all_but_the_first_one \
| delete_cache $repo $branch
}

list_caches() {
local repo="$1"
local branch="$2"
local cache="$3"
gh actions-cache list -R "$repo" -B "$branch" --key "$cache" --order desc | cut -f 1
}

all_but_the_first_one() {
sed 1d
}

delete_cache() {
local repo="$1"
local branch="$2"

while read cache
do
echo "I could delete this cache (but I won't) if needed: $cache" >&2
echo gh actions-cache delete "$cache" -R "$repo" -B "$branch" --confirm
done
}

main "$@"
80 changes: 80 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: "CI"

# Limit concurrent runs of this workflow within a single PR
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

on:
push:
branches:
- master
- release
pull_request:

env:
LD_LIBRARY_PATH: ${{ github.workspace }}/srv/lib
PKG_CONFIG_PATH: ${{ github.workspace }}/srv/lib/pkgconfig

jobs:
build:
name: "Build"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: setup dev environment
uses: ./.github/workflows/actions/setup_dev_ubuntu
with:
clean_caches: true
version_ghc: 9.2.8

- name: cabal build
run: |
cabal build all
test:
name: "Test"
needs: [build]
runs-on: ubuntu-latest
strategy:
matrix:
include:
- package: cardano-lab
steps:
- uses: actions/checkout@v3

- name: setup dev environment
uses: ./.github/workflows/actions/setup_dev_ubuntu
with:
version_ghc: 9.2.8

- name: ❓ Test
if: ${{ matrix.package != 'cardano-lab' }}
run: |
cabal test ${{ matrix.package }}
haddock:
name: "Haddock"
needs: [build]

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: setup dev environment
uses: ./.github/workflows/actions/setup_dev_ubuntu
with:
version_ghc: 9.2.8

- name: 📚 Documentation (Haddock)
run: |
.github/workflows/ci-haddock.sh
- name: 💾 Upload build & test artifacts
uses: actions/upload-artifact@v3
with:
name: haddocks
path: ./docs/static/haddock

0 comments on commit f4aef61

Please sign in to comment.