From f81b1790d87a6a460ca65db14ecc9e9851227969 Mon Sep 17 00:00:00 2001 From: Daniel Lin Date: Fri, 1 Dec 2023 01:25:38 -0500 Subject: [PATCH] Haskell CI --- .github/workflows/get-inputs.yml | 49 +++++++++++++++++++++++ .github/workflows/hs.yml | 69 ++++++++++++++++++++++++++++++++ README.md | 2 +- hs/README.md | 2 +- hs/aoc2023.cabal | 3 +- 5 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/get-inputs.yml create mode 100644 .github/workflows/hs.yml diff --git a/.github/workflows/get-inputs.yml b/.github/workflows/get-inputs.yml new file mode 100644 index 00000000..2522a7d7 --- /dev/null +++ b/.github/workflows/get-inputs.yml @@ -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 diff --git a/.github/workflows/hs.yml b/.github/workflows/hs.yml new file mode 100644 index 00000000..9b03326c --- /dev/null +++ b/.github/workflows/hs.yml @@ -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 diff --git a/README.md b/README.md index abf6d593..f2b9e9a1 100644 --- a/README.md +++ b/README.md @@ -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)| diff --git a/hs/README.md b/hs/README.md index 4a9ce99b..f9f74a3f 100644 --- a/hs/README.md +++ b/hs/README.md @@ -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/). diff --git a/hs/aoc2023.cabal b/hs/aoc2023.cabal index 5c356103..278a9994 100644 --- a/hs/aoc2023.cabal +++ b/hs/aoc2023.cabal @@ -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: