Skip to content

Commit

Permalink
Haskell CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ephemient committed Dec 1, 2023
1 parent 590e891 commit f81b179
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 4 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/get-inputs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Get inputs

on:
workflow_call:
inputs:
year:
required: false
type: number
secrets:
SESSION:
required: true

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Get Day
id: get-day
run: |
from datetime import datetime, timedelta, timezone
import os
tz = timezone(timedelta(hours=-5))
year = ${{ inputs.year }} or 2023
day = max(0, min(25, (datetime.now(tz) - datetime(year, 12, 1, 0, 0, 0, 0, tz)).days + 1))
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
print("year=" + str(year), file=f)
print("day=" + str(min(25, max(0, day))), file=f)
print("days=" + ' '.join(map(str, range(1, day + 1))), file=f)
shell: python
- id: cache
uses: actions/cache@v3
with:
key: inputs-${{ steps.get-day.outputs.day }}
restore-keys: inputs-
path: day*.txt
- name: Download inputs
if: steps.cache.outputs.cache-hit != 'true'
run: |
for day in ${{ steps.get-day.outputs.days }}; do
[[ -e day$day.txt ]] || curl -A https://github.com/ephemient/aoc2023/blob/main/.github/workflows/get-inputs.yml -b session=$SESSION -o day$day.txt -f https://adventofcode.com/${{ steps.get-day.outputs.year }}/day/$day/input
done
shell: bash --noprofile --norc -euxo pipefail {0}
env:
SESSION: ${{ secrets.SESSION }}
- uses: actions/upload-artifact@v3
with:
name: inputs
path: day*.txt
69 changes: 69 additions & 0 deletions .github/workflows/hs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Haskell CI

on:
push:
branches: [ main ]
paths: [ hs/** ]
pull_request:
branches: [ main ]
paths: [ hs/** ]

workflow_dispatch:

jobs:
get-inputs:
uses: ephemient/aoc2023/.github/workflows/get-inputs.yml@main
secrets:
SESSION: ${{ secrets.SESSION }}

build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: haskell-actions/setup@v2
id: setup
with:
ghc-version: 9.4.7
- run: |
cabal configure --enable-tests
cabal build all --dry-run
working-directory: hs
- uses: actions/cache/restore@v3
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('hs/dist-newstyle/cache/plan.json') }}
restore-keys: ${{ env.key }}-
- run: cabal build all --only-dependencies
if: steps.cache.outputs.cache-hit != 'true'
working-directory: hs
- uses: actions/cache/save@v3
if: steps.cache.outputs.cache-hit != 'true'
with:
path: ${{ steps.setup.outputs.cabal-store }}
key: ${{ steps.cache.outputs.cache-primary-key }}
- id: build
run: |
cabal build all
echo "::set-output name=exe::$(cabal list-bin aoc2023)"
working-directory: hs
- run: cabal test all --test-show-details=direct
working-directory: hs
- uses: actions/upload-artifact@v3
with:
name: aoc2023-hs
path: ${{ steps.build.outputs.exe }}

run:
needs: [ get-inputs, build ]
runs-on: ubuntu-latest

steps:
- uses: actions/download-artifact@v3
- run: chmod +x aoc2023-hs/aoc2023
- run: aoc2023-hs/aoc2023
env:
AOC2023_DATADIR: inputs
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

Development occurs in language-specific directories:

|[Haskell](hs)|
|[Haskell](hs) ![Haskell CI](https://github.com/ephemient/aoc2023/workflows/Haskell%20CI/badge.svg)|
|--:|
|[Day1.hs](hs/src/Day1.hs)|
2 changes: 1 addition & 1 deletion hs/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# [Advent of Code 2023](https://adventofcode.com/2023)
### my answers in [Haskell](https://www.haskell.org/)
### my answers in [Haskell](https://www.haskell.org/) ![Haskell CI](https://github.com/ephemient/aoc2023/workflows/Haskell%20CI/badge.svg)

This project builds with [The Haskell Cabal](https://www.haskell.org/cabal/).

Expand Down
3 changes: 1 addition & 2 deletions hs/aoc2023.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ library
Day1

-- Modules included in this library but not exported.
other-modules:
Common
-- other-modules:

-- LANGUAGE extensions used by modules in this package.
-- other-extensions:
Expand Down

0 comments on commit f81b179

Please sign in to comment.