Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github Action improvements #624

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 46 additions & 53 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,60 +66,53 @@ jobs:
- name: Cabal update
run: cabal update

# A dry run `build all` operation does *NOT* downlaod anything, it just looks at the package
# indices to generate an install plan.
- name: Build dry run
run: cabal build all --dry-run --minimize-conflict-set
run: cabal build all --enable-tests --dry-run --minimize-conflict-set

# For users who fork cardano-cli and want to define a writable cache, then can set up their own
# S3 bucket then define in their forked repository settings the following secrets:
#
# CACHE_AWS_ACCESS_KEY_ID
# CACHE_AWS_SECRET_ACCESS_KEY
# CACHE_URI
# CACHE_AWS_REGION
- name: Cabal cache over S3
uses: action-works/cabal-cache-s3@v1
env:
AWS_ACCESS_KEY_ID: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
# From the install plan we generate a dependency list.
- name: Record dependencies
id: record-deps
run: |
# The tests call out to msys2 commands. We generally do not want to mix toolchains, so
# we are very deliberate about only adding msys64 to the path where absolutely necessary.
${{ (runner.os == 'Windows' && '$env:PATH=("C:\msys64\mingw64\bin;{0}" -f $env:PATH)') || '' }}
cat dist-newstyle/cache/plan.json | jq -r '."install-plan"[].id' | sort | uniq > dependencies.txt

# From the dependency list we restore the cached dependencies.
# We use the hash of `dependencies.txt` as part of the cache key because that will be stable
# until the `index-state` values in the `cabal.project` file changes.
- name: Restore cached dependencies
uses: actions/cache/restore@v4
id: cache
with:
region: ${{ vars.CACHE_AWS_REGION }}
dist-dir: dist-newstyle
store-path: ${{ steps.setup-haskell.outputs.cabal-store }}
threads: ${{ vars.CACHE_THREADS }}
archive-uri: ${{ vars.CACHE_URI }}/${{ env.CABAL_CACHE_VERSION }}/${{ runner.os }}/${{ matrix.cabal }}/${{ matrix.ghc }}
skip: "${{ vars.CACHE_URI == '' || env.CABAL_CACHE_VERSION == '' }}"

# It's important to ensure that people who fork this repository can not only successfully build in
# CI by default, but also have meaning cabal store caching.
#
# Because syncing with S3 requires credentials, we cannot rely on S3 for this. For this reason a
# https fallback is used. The https server mirrors the content of the S3 bucket. The https cabal
# store archive is read-only for security reasons.
#
# Users who fork this repository who want to have a writable cabal store archive are encouraged
# to set up their own S3 bucket.
- name: Cabal cache over HTTPS
uses: action-works/cabal-cache-s3@v1
path: |
${{ steps.setup-haskell.outputs.cabal-store }}
dist-newstyle
key: cache-${{ env.CABAL_CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('dependencies.txt') }}
restore-keys: |
Copy link
Contributor

@carbolymer carbolymer Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of of restore-keys here? Shouldn't key be enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. THis cache restoration code was cargo culted from elsewhere. I can try deleting it if you like, see if it still works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left over garbage from where I cargo-culted this from.

PR to remove it at: #628

${{ runner.os }}-ghc-${{ env.GHC_VERSION }}-cabal-${{ env.CABAL_VERSION }}-
cache-${{ env.CABAL_CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('dependencies.txt') }}

# Now we install the dependencies. If the cache was found and restored in the previous step,
# this should be a no-op, but if the cache key was not found we need to build stuff so we can
# cache it for the next step.
- name: Install dependencies
run: cabal build all --enable-tests --only-dependencies -j --ghc-option=-j4

# Always store the cabal cache.
- name: Cache Cabal store
uses: actions/cache/save@v4
with:
dist-dir: dist-newstyle
store-path: ${{ steps.setup-haskell.outputs.cabal-store }}
threads: 16
archive-uri: https://iohk.cache.haskellworks.io/${{ env.CABAL_CACHE_VERSION }}/${{ runner.os }}/${{ matrix.cabal }}/${{ matrix.ghc }}
skip: "${{ vars.CACHE_URI != '' || env.CABAL_CACHE_VERSION == '' }}"
enable-save: false
path: |
${{ steps.setup-haskell.outputs.cabal-store }}
dist-newstyle
key: cache-${{ env.CABAL_CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('dependencies.txt') }}

# Now we build.
- name: Build all
run: cabal build all

- name: Run tests
env:
# these two are msys2 env vars, they have no effect on non-msys2 installs.
MSYS2_PATH_TYPE: inherit
MSYSTEM: MINGW64
TMPDIR: ${{ runner.temp }}
TMP: ${{ runner.temp }}
KEEP_WORKSPACE: 1
run: cabal test all
run: cabal build all --enable-tests

- # Delete golden files and regenerate them in the next step to ensure
erikd marked this conversation as resolved.
Show resolved Hide resolved
# files that tests designate as golden files are actually golden files
Expand All @@ -138,7 +131,7 @@ jobs:
TMP: ${{ runner.temp }}
KEEP_WORKSPACE: 1
CREATE_GOLDEN_FILES: 1
run: cabal test all
run: cabal test all --enable-tests --test-show-details=direct -j1

- name: "Tar artifacts"
shell: bash
Expand All @@ -158,7 +151,7 @@ jobs:
done

- name: Save Artifact
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: artifacts-${{ matrix.os }}-${{ matrix.ghc }}
path: ./artifacts
Expand All @@ -175,9 +168,9 @@ jobs:
# and will silently fail if msys2 is not in path. See the "Run tests" step.
#
# - name: Setup tmate session
# if: ${{ failure() }}
# uses: mxschmitt/action-tmate@v3
# with:
# if: ${{ failure() }}
# uses: mxschmitt/action-tmate@v3
# with:
# limit-access-to-actor: true

build-complete:
Expand Down
Loading