From ec3ba3d47baa89c9d54d81025369b21662619356 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Tue, 30 Apr 2024 14:17:23 +0800 Subject: [PATCH 01/20] Try DevX shell for linux+macos --- .github/workflows/haskell.yml | 44 ++++++++++++++--------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index 3b9bf800118..6f5327df4e3 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -18,23 +18,19 @@ on: required: false default: some +defaults: + run: + shell: devx {0} + jobs: build: - runs-on: ${{ matrix.os }} + runs-on: ${{ matrix.platform == 'x86_64-linux' && 'ubuntu-latest' || 'macos-latest' }} strategy: fail-fast: false matrix: - # If you edit these versions, make sure the version in the lonely macos-latest job below is updated accordingly - ghc: ["9.6.4", "9.8.1"] - cabal: ["3.10.2.1"] - os: [windows-latest, ubuntu-latest] - include: - # Using include, to make sure there will only be one macOS job, even if the matrix gets expanded later on. - # We want a single job, because macOS runners are scarce. - - os: macos-latest - cabal: "3.10.2.1" - ghc: "9.6.4" + platform: [ x86_64-linux, x86_64-darwin ] + compiler-nix-name: [ ghc96, ghc98 ] # , ghc810 ] env: # Modify this value to "invalidate" the cabal cache. @@ -63,25 +59,22 @@ jobs: f+${{ matrix.os }} g+${{ (startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && github.run_id) || github.event.pull_request.number || github.ref }} - - name: Install Haskell - uses: input-output-hk/actions/haskell@latest - id: setup-haskell - with: - ghc-version: ${{ matrix.ghc }} - cabal-version: ${{ matrix.cabal }} - - - name: Install system dependencies - uses: input-output-hk/actions/base@latest - with: - use-sodium-vrf: true # default is true - - uses: actions/checkout@v4 + - name: Install GHC and Cabal + uses: input-output-hk/actions/devx@latest + with: + platform: ${{ matrix.platform }} + target-platform: ${{ matrix.target-platform }} + compiler-nix-name: ${{ matrix.compiler-nix-name }} + # for now we'll set minimal to false, as minimal-iog images don't exist. + minimal: false + iog: true + - name: Cabal update run: cabal update - name: Configure build - shell: bash run: | cp .github/workflows/cabal.project.local.ci cabal.project.local echo "# cabal.project.local" @@ -145,7 +138,6 @@ jobs: if: ${{ failure() }} env: TMP: ${{ runner.temp }} - shell: bash run: | cd $TMP find . -name 'module' -type f -exec dirname {} \; | xargs -L1 basename | sort -u | xargs tar -czvf workspaces.tgz @@ -158,7 +150,6 @@ jobs: path: ${{ runner.temp }}/workspaces.tgz - name: "Tar artifacts" - shell: bash run: | mkdir -p artifacts @@ -176,7 +167,6 @@ jobs: - name: Delete socket files in chairman tests in preparation for uploading artifacts if: ${{ always() }} - shell: bash run: | if [ -d "${{ runner.temp }}/chairman" ]; then find "${{ runner.temp }}/chairman" -type s -exec rm -f {} \; From 1b5e8b03ac3b05f169d50180e034a3b0ba68ea0e Mon Sep 17 00:00:00 2001 From: Sean D Gillespie Date: Mon, 29 Apr 2024 16:39:17 -0400 Subject: [PATCH 02/20] fix(ci): Fix a handful of GH actions errors * devx: command not found * jq: error (at :0): Cannot index array with string "style" --- .github/workflows/haskell.yml | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index 6f5327df4e3..45b2c88ea9d 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -41,26 +41,12 @@ jobs: a+${{ github.event_name }} b+${{ github.workflow_ref }} c+${{ github.job }} - d+${{ matrix.ghc }} - e+${{ matrix.cabal }} - f+${{ matrix.os }} - g+${{ (startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && github.run_id) || github.event.pull_request.number || github.ref }} + d+${{ matrix.compiler-nix-name }} + e+${{ matrix.platform }} + f+${{ (startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && github.run_id) || github.event.pull_request.number || github.ref }} cancel-in-progress: true steps: - - name: Concurrency group - run: > - echo - a+${{ github.event_name }} - b+${{ github.workflow_ref }} - c+${{ github.job }} - d+${{ matrix.ghc }} - e+${{ matrix.cabal }} - f+${{ matrix.os }} - g+${{ (startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && github.run_id) || github.event.pull_request.number || github.ref }} - - - uses: actions/checkout@v4 - - name: Install GHC and Cabal uses: input-output-hk/actions/devx@latest with: @@ -70,7 +56,19 @@ jobs: # for now we'll set minimal to false, as minimal-iog images don't exist. minimal: false iog: true - + + - name: Concurrency group + run: > + echo + a+${{ github.event_name }} + b+${{ github.workflow_ref }} + c+${{ github.job }} + d+${{ matrix.compiler-nix-name }} + e+${{ matrix.platform }} + f+${{ (startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && github.run_id) || github.event.pull_request.number || github.ref }} + + - uses: actions/checkout@v4 + - name: Cabal update run: cabal update From 3b6baa2bbb19cdfc13dade20bb06c1d8e47f1499 Mon Sep 17 00:00:00 2001 From: Sean D Gillespie Date: Mon, 6 May 2024 14:10:17 -0400 Subject: [PATCH 03/20] REMOVEME: Try to shorten $TMPDIR a bit --- .github/workflows/haskell.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index 45b2c88ea9d..20994f643a4 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -124,10 +124,14 @@ jobs: - name: Build all run: cabal build all --enable-tests + - name: Hack around TMP paths + run: | + mkdir -p /home/runner/_ + - name: Run tests env: - TMPDIR: ${{ runner.temp }} - TMP: ${{ runner.temp }} + TMPDIR: /home/runner/_ + TMP: /home/runner/_ KEEP_WORKSPACE: 1 run: | cabal test cardano-testnet cardano-node cardano-node-chairman cardano-submit-api From fa7630b92d66587b14272d8b348d05fc7dc0f621 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Tue, 7 May 2024 08:12:31 +0800 Subject: [PATCH 04/20] Update haskell.yml --- .github/workflows/haskell.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index 20994f643a4..a1a9c58c94c 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -74,6 +74,10 @@ jobs: - name: Configure build run: | + echo "${{ runner.temp }}" + echo "$TMPDIR" + echo "$TMP" + cp .github/workflows/cabal.project.local.ci cabal.project.local echo "# cabal.project.local" cat cabal.project.local @@ -134,6 +138,9 @@ jobs: TMP: /home/runner/_ KEEP_WORKSPACE: 1 run: | + echo "${{ runner.temp }}" + echo "$TMPDIR" + echo "$TMP" cabal test cardano-testnet cardano-node cardano-node-chairman cardano-submit-api - name: Tar failed tests workspaces From bab147299773a56dbcaa2e46d87ca119db2b6a96 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Tue, 7 May 2024 08:16:37 +0800 Subject: [PATCH 05/20] Update haskell.yml --- .github/workflows/haskell.yml | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index a1a9c58c94c..27e63a7f7af 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -29,7 +29,7 @@ jobs: strategy: fail-fast: false matrix: - platform: [ x86_64-linux, x86_64-darwin ] + platform: [ x86_64-linux, x86_64-darwin, aarch64-darwin ] compiler-nix-name: [ ghc96, ghc98 ] # , ghc810 ] env: @@ -73,11 +73,7 @@ jobs: run: cabal update - name: Configure build - run: | - echo "${{ runner.temp }}" - echo "$TMPDIR" - echo "$TMP" - + run: | cp .github/workflows/cabal.project.local.ci cabal.project.local echo "# cabal.project.local" cat cabal.project.local @@ -128,19 +124,12 @@ jobs: - name: Build all run: cabal build all --enable-tests - - name: Hack around TMP paths - run: | - mkdir -p /home/runner/_ - - name: Run tests env: - TMPDIR: /home/runner/_ - TMP: /home/runner/_ KEEP_WORKSPACE: 1 run: | - echo "${{ runner.temp }}" - echo "$TMPDIR" - echo "$TMP" + export TMPDIR="${{ runner.temp }}" + export TMP="${{ runner.temp }}" cabal test cardano-testnet cardano-node cardano-node-chairman cardano-submit-api - name: Tar failed tests workspaces From 749e1e486557e1b40d329176f6929e8b50c3717e Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Tue, 7 May 2024 11:15:51 +0800 Subject: [PATCH 06/20] Update and rename haskell.yml to devx.yml --- .github/workflows/{haskell.yml => devx.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{haskell.yml => devx.yml} (99%) diff --git a/.github/workflows/haskell.yml b/.github/workflows/devx.yml similarity index 99% rename from .github/workflows/haskell.yml rename to .github/workflows/devx.yml index 27e63a7f7af..2d897dceb0b 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/devx.yml @@ -1,4 +1,4 @@ -name: Haskell CI +name: Haskell CI (DevX Shell) on: pull_request: # Required for workflows to be able to be approved from forks From 0a92e285881e3faccf1cb047916a37624672aea3 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Tue, 7 May 2024 11:17:23 +0800 Subject: [PATCH 07/20] Create haskell.yaml --- .github/workflows/haskell.yaml | 257 +++++++++++++++++++++++++++++++++ 1 file changed, 257 insertions(+) create mode 100644 .github/workflows/haskell.yaml diff --git a/.github/workflows/haskell.yaml b/.github/workflows/haskell.yaml new file mode 100644 index 00000000000..2c2c194f470 --- /dev/null +++ b/.github/workflows/haskell.yaml @@ -0,0 +1,257 @@ +name: Haskell CI + +on: + pull_request: # Required for workflows to be able to be approved from forks + merge_group: + + # DO NOT DELETE. + # This is required for nightly builds and is invoked by nightly-trigger.yml + # on a schedule trigger. + workflow_dispatch: + inputs: + reason: + description: 'Reason' + required: false + default: manual + tests: + description: 'Tests' + required: false + default: some + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + # If you edit these versions, make sure the version in the lonely macos-latest job below is updated accordingly + # Linux / macOS are in devx.yaml, please ensure the GHC versions line up. + ghc: ["9.6.4", "9.8.1"] + cabal: ["3.10.2.1"] + os: [windows-latest] + + env: + # Modify this value to "invalidate" the cabal cache. + CABAL_CACHE_VERSION: "2024-04-24" + + concurrency: + group: > + a+${{ github.event_name }} + b+${{ github.workflow_ref }} + c+${{ github.job }} + d+${{ matrix.ghc }} + e+${{ matrix.cabal }} + f+${{ matrix.os }} + g+${{ (startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && github.run_id) || github.event.pull_request.number || github.ref }} + cancel-in-progress: true + + steps: + - name: Concurrency group + run: > + echo + a+${{ github.event_name }} + b+${{ github.workflow_ref }} + c+${{ github.job }} + d+${{ matrix.ghc }} + e+${{ matrix.cabal }} + f+${{ matrix.os }} + g+${{ (startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && github.run_id) || github.event.pull_request.number || github.ref }} + + - name: Install Haskell + uses: input-output-hk/actions/haskell@latest + id: setup-haskell + with: + ghc-version: ${{ matrix.ghc }} + cabal-version: ${{ matrix.cabal }} + + - name: Install system dependencies + uses: input-output-hk/actions/base@latest + with: + use-sodium-vrf: true # default is true + + - uses: actions/checkout@v4 + + - name: Cabal update + run: cabal update + + - name: Configure build + shell: bash + run: | + cp .github/workflows/cabal.project.local.ci cabal.project.local + echo "# cabal.project.local" + cat cabal.project.local + + # 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 --enable-tests --dry-run --minimize-conflict-set + + # 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"[] | select(.style != "local") | .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: + path: | + ${{ steps.setup-haskell.outputs.cabal-store }} + dist-newstyle + key: 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. + # This can fail (benign failure) if there is already a hash at that key. + - name: Cache Cabal store + uses: actions/cache/save@v4 + with: + 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 --enable-tests + + - name: Run tests + env: + TMPDIR: ${{ runner.temp }} + TMP: ${{ runner.temp }} + KEEP_WORKSPACE: 1 + run: | + cabal test cardano-testnet cardano-node cardano-node-chairman cardano-submit-api + + - name: Tar failed tests workspaces + if: ${{ failure() }} + env: + TMP: ${{ runner.temp }} + shell: bash + run: | + cd $TMP + find . -name 'module' -type f -exec dirname {} \; | xargs -L1 basename | sort -u | xargs tar -czvf workspaces.tgz + + - name: Upload workspaces on tests failure + if: ${{ failure() }} + uses: actions/upload-artifact@v4 + with: + name: failed-test-workspaces-${{ matrix.os }}-ghc${{ matrix.ghc }}-cabal${{ matrix.cabal }}.tgz + path: ${{ runner.temp }}/workspaces.tgz + + - name: "Tar artifacts" + shell: bash + run: | + mkdir -p artifacts + + for exe in $(cat dist-newstyle/cache/plan.json | jq -r '."install-plan"[] | select(.style == "local" and (."component-name" | startswith("exe:"))) | ."bin-file"'); do + if [ -f $exe ]; then + echo "Including artifact $exe" + + ( cd artifacts + tar -C "$(dirname $exe)" -czf "$(basename $exe).tar.gz" "$(basename $exe)" + ) + else + echo "Skipping artifact $exe" + fi + done + + - name: Delete socket files in chairman tests in preparation for uploading artifacts + if: ${{ always() }} + shell: bash + run: | + if [ -d "${{ runner.temp }}/chairman" ]; then + find "${{ runner.temp }}/chairman" -type s -exec rm -f {} \; + fi + + - name: Save Artifact + uses: actions/upload-artifact@v4 + if: ${{ always() }} + continue-on-error: true + with: + name: chairman-test-artifacts-${{ matrix.os }}-${{ matrix.ghc }} + path: ${{ runner.temp }}/chairman/ + + # Uncomment the following back in for debugging. Remember to launch a `pwsh` from + # the tmux session to debug `pwsh` issues. And be reminded that the `/msys2` and + # `/msys2/mingw64` paths are not in PATH by default for the workflow, but tmate + # will put them in. + # You may also want to run + # + # $env:PATH=("C:\Program Files\PowerShell\7;{0}" -f $env:ORIGINAL_PATH) + # + # to restore the original path. Do note that some test might need msys2 + # 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: + # limit-access-to-actor: true + + build-complete: + needs: [build] + if: ${{ always() }} + runs-on: ubuntu-latest + steps: + - name: Check if any previous job failed + run: | + if [[ "${{ needs.build.result }}" == "failure" ]]; then + # this ignores skipped dependencies + echo 'Required jobs failed to build.' + exit 1 + else + echo 'Build complete' + fi + + release: + needs: [build] + if: ${{ startsWith(github.ref, 'refs/tags') }} + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Create Release Tag + id: create_release_tag + run: | + echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: true + prerelease: false + + - name: Download Artifact + uses: actions/download-artifact@v1 + with: + name: artifacts-ubuntu-latest + + - name: Upload Release Asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./artifacts-ubuntu-latest/cardano-submit-api.tar.gz + asset_name: cardano-submit-api_${{ steps.create_release_tag.outputs.TAG }}-linux.tar.gz + asset_content_type: application/gzip From be23da8f09c6b3bbd6c9e4c88dd8585a5455d0f1 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Tue, 7 May 2024 11:20:13 +0800 Subject: [PATCH 08/20] Update nightly-trigger.yml --- .github/workflows/nightly-trigger.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nightly-trigger.yml b/.github/workflows/nightly-trigger.yml index 452077f08e3..0843e5e20c3 100644 --- a/.github/workflows/nightly-trigger.yml +++ b/.github/workflows/nightly-trigger.yml @@ -23,10 +23,18 @@ jobs: git checkout -b nightly git push origin nightly --force - - name: Invoke workflow + - name: Invoke workflow (Windows) uses: input-output-hk/workflow-dispatch@v1 with: workflow: .github/workflows/haskell.yml ref: nightly token: ${{ secrets.MACHINE_TOKEN }} inputs: '{ "reason": "nightly", "tests": "all" }' + + - name: Invoke workflow (macOS & Linux) + uses: input-output-hk/workflow-dispatch@v1 + with: + workflow: .github/workflows/devx.yml + ref: nightly + token: ${{ secrets.MACHINE_TOKEN }} + inputs: '{ "reason": "nightly", "tests": "all" }' From e35f263e5bd64ce6e2c9c8816d3277cdff2996be Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Tue, 7 May 2024 17:41:58 +0800 Subject: [PATCH 09/20] Update devx.yml Set shell to devx only for the build job. --- .github/workflows/devx.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/devx.yml b/.github/workflows/devx.yml index 2d897dceb0b..057566cb930 100644 --- a/.github/workflows/devx.yml +++ b/.github/workflows/devx.yml @@ -18,12 +18,12 @@ on: required: false default: some -defaults: - run: - shell: devx {0} - jobs: build: + defaults: + run: + shell: devx {0} + runs-on: ${{ matrix.platform == 'x86_64-linux' && 'ubuntu-latest' || 'macos-latest' }} strategy: From 5dfab6ef4d077765369bc8c510a04787cd80004c Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Wed, 8 May 2024 11:53:14 +0800 Subject: [PATCH 10/20] Update devx.yml Let's try this. Will blow up on anything but x86_64-linux, but let's see. --- .github/workflows/devx.yml | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/devx.yml b/.github/workflows/devx.yml index 057566cb930..21666ff5577 100644 --- a/.github/workflows/devx.yml +++ b/.github/workflows/devx.yml @@ -23,6 +23,9 @@ jobs: defaults: run: shell: devx {0} + env: + CABAL_AWS_ACCESS_KEY_ID: ${{ secrets.CABAL_AWS_ACCESS_KEY_ID }} + CABAL_AWS_SECRET_ACCESS_KEY: ${{ secrets.CABAL_AWS_SECRET_ACCESS_KEY }} runs-on: ${{ matrix.platform == 'x86_64-linux' && 'ubuntu-latest' || 'macos-latest' }} @@ -69,8 +72,17 @@ jobs: - uses: actions/checkout@v4 + - name: add patched cabal + run: | + mkdir ~/bin + mkdir cabalHooks + curl -L https://ci.zw3rk.com/job/input-output-hk-haskell-nix-example/pullrequest-2/x86_64-linux.cabal-install-static/latest/download/1 | gunzip > ~/bin/cabal + curl -L https://ci.zw3rk.com/job/input-output-hk-haskell-nix-example/pullrequest-2/x86_64-linux.cabal-install-hooks/latest/download/1 | tar xzf - -C ./cabalHooks + chmod +x ~/bin/cabal + chmod +x ./cabalHooks/*Hook* + - name: Cabal update - run: cabal update + run: ~/bin/cabal update - name: Configure build run: | @@ -81,7 +93,7 @@ jobs: # 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 --enable-tests --dry-run --minimize-conflict-set + run: ~/bin/cabal build all --enable-tests --dry-run --minimize-conflict-set # From the install plan we generate a dependency list. - name: Record dependencies @@ -108,7 +120,7 @@ jobs: # 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 + run: ~/bin/cabal build all --enable-tests --only-dependencies -j --ghc-option=-j4 # Always store the cabal cache. # This can fail (benign failure) if there is already a hash at that key. @@ -122,7 +134,7 @@ jobs: # Now we build. - name: Build all - run: cabal build all --enable-tests + run: ~/bin/cabal build all --enable-tests - name: Run tests env: @@ -130,7 +142,7 @@ jobs: run: | export TMPDIR="${{ runner.temp }}" export TMP="${{ runner.temp }}" - cabal test cardano-testnet cardano-node cardano-node-chairman cardano-submit-api + ~/bin/cabal test cardano-testnet cardano-node cardano-node-chairman cardano-submit-api - name: Tar failed tests workspaces if: ${{ failure() }} From ae42acf982dd6b540973e567eb23bf64891521ad Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Wed, 8 May 2024 16:06:35 +0800 Subject: [PATCH 11/20] Update devx.yml --- .github/workflows/devx.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/devx.yml b/.github/workflows/devx.yml index 21666ff5577..c6dc18830bb 100644 --- a/.github/workflows/devx.yml +++ b/.github/workflows/devx.yml @@ -26,6 +26,8 @@ jobs: env: CABAL_AWS_ACCESS_KEY_ID: ${{ secrets.CABAL_AWS_ACCESS_KEY_ID }} CABAL_AWS_SECRET_ACCESS_KEY: ${{ secrets.CABAL_AWS_SECRET_ACCESS_KEY }} + # Modify this value to "invalidate" the cabal cache. + CABAL_CACHE_VERSION: "2024-04-24" runs-on: ${{ matrix.platform == 'x86_64-linux' && 'ubuntu-latest' || 'macos-latest' }} @@ -35,10 +37,6 @@ jobs: platform: [ x86_64-linux, x86_64-darwin, aarch64-darwin ] compiler-nix-name: [ ghc96, ghc98 ] # , ghc810 ] - env: - # Modify this value to "invalidate" the cabal cache. - CABAL_CACHE_VERSION: "2024-04-24" - concurrency: group: > a+${{ github.event_name }} From 45759954e4ec5f05bcdef629f7e87b2c191b491d Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Wed, 8 May 2024 16:20:23 +0800 Subject: [PATCH 12/20] add hooks directly to PR --- .github/workflows/devx.yml | 3 --- cabalHooks/postBuildHook | 4 ++++ cabalHooks/postBuildHook.local | 10 ++++++++++ cabalHooks/postBuildHook.s3 | 10 ++++++++++ cabalHooks/preBuildHook | 4 ++++ cabalHooks/preBuildHook.local | 14 ++++++++++++++ cabalHooks/preBuildHook.s3 | 16 ++++++++++++++++ cabalHooks/s3-credentials.bash | 5 +++++ 8 files changed, 63 insertions(+), 3 deletions(-) create mode 100755 cabalHooks/postBuildHook create mode 100755 cabalHooks/postBuildHook.local create mode 100755 cabalHooks/postBuildHook.s3 create mode 100755 cabalHooks/preBuildHook create mode 100755 cabalHooks/preBuildHook.local create mode 100755 cabalHooks/preBuildHook.s3 create mode 100644 cabalHooks/s3-credentials.bash diff --git a/.github/workflows/devx.yml b/.github/workflows/devx.yml index c6dc18830bb..aa3901f0ab9 100644 --- a/.github/workflows/devx.yml +++ b/.github/workflows/devx.yml @@ -73,11 +73,8 @@ jobs: - name: add patched cabal run: | mkdir ~/bin - mkdir cabalHooks curl -L https://ci.zw3rk.com/job/input-output-hk-haskell-nix-example/pullrequest-2/x86_64-linux.cabal-install-static/latest/download/1 | gunzip > ~/bin/cabal - curl -L https://ci.zw3rk.com/job/input-output-hk-haskell-nix-example/pullrequest-2/x86_64-linux.cabal-install-hooks/latest/download/1 | tar xzf - -C ./cabalHooks chmod +x ~/bin/cabal - chmod +x ./cabalHooks/*Hook* - name: Cabal update run: ~/bin/cabal update diff --git a/cabalHooks/postBuildHook b/cabalHooks/postBuildHook new file mode 100755 index 00000000000..d6ad9a99271 --- /dev/null +++ b/cabalHooks/postBuildHook @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +#./postBuildHook.local "$@" +postBuildHook.s3 "$@" \ No newline at end of file diff --git a/cabalHooks/postBuildHook.local b/cabalHooks/postBuildHook.local new file mode 100755 index 00000000000..f206383991c --- /dev/null +++ b/cabalHooks/postBuildHook.local @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +CACHE=$HOME/.cabal-build-cache + +mkdir -p $CACHE + +echo "Uploading $1 to $CACHE" +tar -czf $CACHE/$1.tar.gz --exclude=$3/setup-config $3 +exit 0 + diff --git a/cabalHooks/postBuildHook.s3 b/cabalHooks/postBuildHook.s3 new file mode 100755 index 00000000000..41774a5723e --- /dev/null +++ b/cabalHooks/postBuildHook.s3 @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +. "$(dirname "${BASH_SOURCE[0]}")/s3-credentials.bash" + +CACHE_KEY="$1.tar.gz" + +echo "Compressing and uploading $1 to S3" +tar -czf $CACHE_KEY --exclude=$3/setup-config $3 +aws s3 cp $CACHE_KEY s3://$CACHE_BUCKET/devx-shell/$CACHE_KEY --endpoint-url $AWS_ENDPOINT +rm $CACHE_KEY # Optional: Cleanup local file \ No newline at end of file diff --git a/cabalHooks/preBuildHook b/cabalHooks/preBuildHook new file mode 100755 index 00000000000..2ba5e1b1cb6 --- /dev/null +++ b/cabalHooks/preBuildHook @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +#./preBuildHook.local "$@" +preBuildHook.s3 "$@" \ No newline at end of file diff --git a/cabalHooks/preBuildHook.local b/cabalHooks/preBuildHook.local new file mode 100755 index 00000000000..d01c7dbb4ba --- /dev/null +++ b/cabalHooks/preBuildHook.local @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +CACHE=$HOME/.cabal-build-cache + +mkdir -p $CACHE + +if [ -f $CACHE/$1.tar.gz ]; then + echo "Cache hit" + tar -xzf $CACHE/$1.tar.gz + exit 0 +else + echo "Cache miss" + exit 1 +fi \ No newline at end of file diff --git a/cabalHooks/preBuildHook.s3 b/cabalHooks/preBuildHook.s3 new file mode 100755 index 00000000000..636c810b015 --- /dev/null +++ b/cabalHooks/preBuildHook.s3 @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +. "$(dirname "${BASH_SOURCE[0]}")/s3-credentials.bash" + +CACHE_KEY="$1.tar.gz" + +# Check if artifact exists in S3 (with endpoint and credentials) +aws s3 ls s3://$CACHE_BUCKET/devx-shell/$CACHE_KEY --endpoint-url $AWS_ENDPOINT > /dev/null 2>&1 + +if [ $? -eq 0 ]; then + echo "Cache hit - downloading from S3" + aws s3 cp s3://$CACHE_BUCKET/devx-shell/$CACHE_KEY - --endpoint-url $AWS_ENDPOINT | tar -xz +else + echo "Cache miss" + exit 1 +fi \ No newline at end of file diff --git a/cabalHooks/s3-credentials.bash b/cabalHooks/s3-credentials.bash new file mode 100644 index 00000000000..577c7d7067c --- /dev/null +++ b/cabalHooks/s3-credentials.bash @@ -0,0 +1,5 @@ +CACHE_BUCKET="cabal-cache" # Replace with your bucket name +export AWS_ACCESS_KEY_ID=$CABAL_AWS_ACCESS_KEY_ID +export AWS_SECRET_ACCESS_KEY=$CABAL_AWS_SECRET_ACCESS_KEY +export AWS_DEFAULT_REGION=auto +AWS_ENDPOINT="https://c1fe99e5a421ac98af478e51dda5db4f.r2.cloudflarestorage.com" From d17176b69b2fc166645607650ea210504e214f73 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 9 May 2024 12:57:10 +0800 Subject: [PATCH 13/20] Update preBuildHook.s3 --- cabalHooks/preBuildHook.s3 | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cabalHooks/preBuildHook.s3 b/cabalHooks/preBuildHook.s3 index 636c810b015..a52a4c1faeb 100755 --- a/cabalHooks/preBuildHook.s3 +++ b/cabalHooks/preBuildHook.s3 @@ -1,16 +1,18 @@ #!/usr/bin/env bash -. "$(dirname "${BASH_SOURCE[0]}")/s3-credentials.bash" +# shellcheck disable=SC1091,SC2046 +. $(dirname "${BASH_SOURCE[0]}")/s3-credentials.bash CACHE_KEY="$1.tar.gz" # Check if artifact exists in S3 (with endpoint and credentials) -aws s3 ls s3://$CACHE_BUCKET/devx-shell/$CACHE_KEY --endpoint-url $AWS_ENDPOINT > /dev/null 2>&1 +aws s3 ls s3://"$CACHE_BUCKET"/"$CACHE_KEY" --endpoint-url "$AWS_ENDPOINT" > /dev/null 2>&1 +# shellcheck disable=SC2181 if [ $? -eq 0 ]; then - echo "Cache hit - downloading from S3" - aws s3 cp s3://$CACHE_BUCKET/devx-shell/$CACHE_KEY - --endpoint-url $AWS_ENDPOINT | tar -xz + echo "S3 hit $1" + aws s3 cp s3://"$CACHE_BUCKET"/"$CACHE_KEY" - --endpoint-url "$AWS_ENDPOINT" | tar -xz else - echo "Cache miss" + echo "S3 miss $1" exit 1 -fi \ No newline at end of file +fi From 5127cb0474b78731fd3cc7066d9d25be1a4bfb1c Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 9 May 2024 12:58:23 +0800 Subject: [PATCH 14/20] Update postBuildHook.s3 --- cabalHooks/postBuildHook.s3 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cabalHooks/postBuildHook.s3 b/cabalHooks/postBuildHook.s3 index 41774a5723e..06344812509 100755 --- a/cabalHooks/postBuildHook.s3 +++ b/cabalHooks/postBuildHook.s3 @@ -1,10 +1,11 @@ #!/usr/bin/env bash +# shellcheck disable=SC1091,SC2046 . "$(dirname "${BASH_SOURCE[0]}")/s3-credentials.bash" CACHE_KEY="$1.tar.gz" -echo "Compressing and uploading $1 to S3" -tar -czf $CACHE_KEY --exclude=$3/setup-config $3 -aws s3 cp $CACHE_KEY s3://$CACHE_BUCKET/devx-shell/$CACHE_KEY --endpoint-url $AWS_ENDPOINT -rm $CACHE_KEY # Optional: Cleanup local file \ No newline at end of file +echo "S3 upload $1" +tar -czf "$CACHE_KEY" --exclude="$3/setup-config" "$3" +aws s3 cp "$CACHE_KEY" s3://"$CACHE_BUCKET"/devx-shell/"$CACHE_KEY" --endpoint-url "$AWS_ENDPOINT" +rm "$CACHE_KEY" # Optional: Cleanup local file From 8f82a211458ac90dfef077cd333bf092f8f03f01 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 9 May 2024 12:58:46 +0800 Subject: [PATCH 15/20] Update preBuildHook.s3 --- cabalHooks/preBuildHook.s3 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cabalHooks/preBuildHook.s3 b/cabalHooks/preBuildHook.s3 index a52a4c1faeb..86330b61108 100755 --- a/cabalHooks/preBuildHook.s3 +++ b/cabalHooks/preBuildHook.s3 @@ -6,12 +6,12 @@ CACHE_KEY="$1.tar.gz" # Check if artifact exists in S3 (with endpoint and credentials) -aws s3 ls s3://"$CACHE_BUCKET"/"$CACHE_KEY" --endpoint-url "$AWS_ENDPOINT" > /dev/null 2>&1 +aws s3 ls s3://"$CACHE_BUCKET"/devx-shell/"$CACHE_KEY" --endpoint-url "$AWS_ENDPOINT" > /dev/null 2>&1 # shellcheck disable=SC2181 if [ $? -eq 0 ]; then echo "S3 hit $1" - aws s3 cp s3://"$CACHE_BUCKET"/"$CACHE_KEY" - --endpoint-url "$AWS_ENDPOINT" | tar -xz + aws s3 cp s3://"$CACHE_BUCKET"/devx-shell/"$CACHE_KEY" - --endpoint-url "$AWS_ENDPOINT" | tar -xz else echo "S3 miss $1" exit 1 From 6e16924e01044d9b79a01032ccbd8af411532962 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 9 May 2024 12:59:26 +0800 Subject: [PATCH 16/20] Update preBuildHook --- cabalHooks/preBuildHook | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabalHooks/preBuildHook b/cabalHooks/preBuildHook index 2ba5e1b1cb6..874201d5380 100755 --- a/cabalHooks/preBuildHook +++ b/cabalHooks/preBuildHook @@ -1,4 +1,4 @@ #!/usr/bin/env bash #./preBuildHook.local "$@" -preBuildHook.s3 "$@" \ No newline at end of file +$(dirname "${BASH_SOURCE[0]}")/preBuildHook.s3 "$@" From 85cbbdde38a7dd5c5bc4d59fff796ec879e37bb9 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 9 May 2024 12:59:42 +0800 Subject: [PATCH 17/20] Update postBuildHook --- cabalHooks/postBuildHook | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabalHooks/postBuildHook b/cabalHooks/postBuildHook index d6ad9a99271..1c0dd11ad47 100755 --- a/cabalHooks/postBuildHook +++ b/cabalHooks/postBuildHook @@ -1,4 +1,4 @@ #!/usr/bin/env bash #./postBuildHook.local "$@" -postBuildHook.s3 "$@" \ No newline at end of file +$(dirname "${BASH_SOURCE[0]}")/postBuildHook.s3 "$@" From f923c9d51ef0af16051f283ea35df649203c874f Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 9 May 2024 13:08:25 +0800 Subject: [PATCH 18/20] Update devx.yml --- .github/workflows/devx.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/devx.yml b/.github/workflows/devx.yml index aa3901f0ab9..24bcbd6aec1 100644 --- a/.github/workflows/devx.yml +++ b/.github/workflows/devx.yml @@ -73,7 +73,17 @@ jobs: - name: add patched cabal run: | mkdir ~/bin - curl -L https://ci.zw3rk.com/job/input-output-hk-haskell-nix-example/pullrequest-2/x86_64-linux.cabal-install-static/latest/download/1 | gunzip > ~/bin/cabal + case "$(uname -m)-$(uname -o)" in + arm64-Darwin) + curl -L https://ci.zw3rk.com/job/input-output-hk-haskell-nix-example/pullrequest-2/aarch64-darwin.cabal-install-static/latest/download/1 | gunzip > ~/bin/cabal + ;; + x86_64-Darwin) + curl -L https://ci.zw3rk.com/job/input-output-hk-haskell-nix-example/pullrequest-2/x86_64-darwin.cabal-install-static/latest/download/1 | gunzip > ~/bin/cabal + ;; + x86_64-GNU/Linux) + curl -L https://ci.zw3rk.com/job/input-output-hk-haskell-nix-example/pullrequest-2/x86_64-linux.cabal-install-static/latest/download/1 | gunzip > ~/bin/cabal + ;; + esac chmod +x ~/bin/cabal - name: Cabal update From 4918dbc0bfc4d2c90fa8308c6997be708022d4cc Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 9 May 2024 14:52:57 +0800 Subject: [PATCH 19/20] Only upload if the key doesn't already exist locally. --- cabalHooks/postBuildHook.s3 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cabalHooks/postBuildHook.s3 b/cabalHooks/postBuildHook.s3 index 06344812509..d3465643003 100755 --- a/cabalHooks/postBuildHook.s3 +++ b/cabalHooks/postBuildHook.s3 @@ -5,7 +5,9 @@ CACHE_KEY="$1.tar.gz" -echo "S3 upload $1" -tar -czf "$CACHE_KEY" --exclude="$3/setup-config" "$3" -aws s3 cp "$CACHE_KEY" s3://"$CACHE_BUCKET"/devx-shell/"$CACHE_KEY" --endpoint-url "$AWS_ENDPOINT" -rm "$CACHE_KEY" # Optional: Cleanup local file +if ! test -f "$CACHE_KEY" ; then + echo "S3 upload $1" + tar -czf "$CACHE_KEY" --exclude="$3/setup-config" "$3" + aws s3 cp "$CACHE_KEY" s3://"$CACHE_BUCKET"/devx-shell/"$CACHE_KEY" --endpoint-url "$AWS_ENDPOINT" + rm "$CACHE_KEY" # Optional: Cleanup local file +fi From eea95cbb300895bacf6947eb5f96a456596382b9 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 9 May 2024 14:57:38 +0800 Subject: [PATCH 20/20] Update preBuildHook.s3 --- cabalHooks/preBuildHook.s3 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cabalHooks/preBuildHook.s3 b/cabalHooks/preBuildHook.s3 index 86330b61108..7b3da382c1c 100755 --- a/cabalHooks/preBuildHook.s3 +++ b/cabalHooks/preBuildHook.s3 @@ -12,6 +12,8 @@ aws s3 ls s3://"$CACHE_BUCKET"/devx-shell/"$CACHE_KEY" --endpoint-url "$AWS_ENDP if [ $? -eq 0 ]; then echo "S3 hit $1" aws s3 cp s3://"$CACHE_BUCKET"/devx-shell/"$CACHE_KEY" - --endpoint-url "$AWS_ENDPOINT" | tar -xz + # leave an empty $CACHE_KEY file for the postBuildHook to see and not re-upload. + touch "$CACHE_KEY" else echo "S3 miss $1" exit 1