Skip to content

Commit

Permalink
ci: test
Browse files Browse the repository at this point in the history
  • Loading branch information
metaclips committed Oct 2, 2023
1 parent 29f8884 commit e24c0b1
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 49 deletions.
28 changes: 20 additions & 8 deletions .github/actions/nix_installer_and_cache/action.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
name: Nix Installer
description: Nix Installer

inputs:
cache-unique-id:
description: Unique ID to differentiate caches
required: true

outputs:
cache-hit:
description: "Indicate if cache is hit"
description: Whether the cache was restored or not
value: ${{ steps.nix-cache.outputs.cache-hit }}

runs:
Expand All @@ -11,14 +17,20 @@ runs:
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@3ebd1aebb47f95493b62de6eec0cac3cd74e50a9

- name: Cache Nix Store
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
- name: Cache nix env take N+1
uses: actions/cache@v2
id: nix-cache
with:
path: /tmp/nixcache
key: cache-nix-${{ github.workflow }}-${{ github.job }}-${{ hashFiles('**/flake.lock') }}
path: |
/tmp/nix-cache
key: nix-cache-${{ runner.os }}-${{ github.workflow }}-${{ github.job }}-${{ inputs.cache-unique-id }}-${{ hashFiles('**/flake.lock') }}

- name: Restore Nix Cache
shell: bash
- name: cache hit
if: steps.nix-cache.outputs.cache-hit == 'true'
run: nix copy --from /tmp/nixcache
shell: bash
run: |
sudo systemctl stop nix-daemon
sudo chown -R 777 /tmp/nix-cache
sudo chown -R 777 /nix
sudo cp -fRT /tmp/nix-cache/ /nix/
sudo systemctl start nix-daemon
19 changes: 19 additions & 0 deletions .github/actions/nix_upload_store/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Nix Cache
description: Cache Nix File To Temporary Directory

runs:
using: composite
steps:
- shell: bash
run: |
sudo cp -r /nix /tmp/nix-cache
sudo rm -rf /tmp/nix-cache/var/nix/daemon-socket/socket
sudo rm -rf /tmp/nix-cache/var/nix/userpool
sudo rm -rf /tmp/nix-cache/var/nix/gc.lock
sudo rm -rf /tmp/nix-cache/var/nix/db/big-lock
sudo rm -rf /tmp/nix-cache/var/nix/db/reserved
sudo rm -rf /tmp/nix-cache/var/nix/userpool2/slot-0
sudo chown -R 777 /tmp/nix-cache
sudo systemctl stop nix-daemon
13 changes: 0 additions & 13 deletions .github/actions/upload_nix_store/action.yml

This file was deleted.

4 changes: 3 additions & 1 deletion .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ jobs:
with:
ref: ${{ github.event.inputs.commit_sha }}
- uses: ./.github/actions/nix_installer_and_cache
with:
cache-unique-id: elixir
id: nix-installer
- uses: ./.github/actions/elixir_cache
- run: make test
working-directory: implementations/elixir
- run: make lint
working-directory: implementations/elixir
- uses: ./.github/actions/upload_nix_store
- uses: ./.github/actions/nix_upload_store
if: ${{ steps.nix-installer.outputs.cache-hit != 'true' }}
7 changes: 6 additions & 1 deletion .github/workflows/make.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ jobs:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
with:
ref: ${{ github.event.inputs.commit_sha }}
- uses: ./.github/actions/nix_installer
- uses: ./.github/actions/nix_installer_and_cache
with:
cache-unique-id: elixir
id: nix-installer
- uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43
- uses: ./.github/actions/elixir_cache
- run: make
- uses: ./.github/actions/nix_upload_store
if: ${{ steps.nix-installer.outputs.cache-hit != 'true' }}
60 changes: 35 additions & 25 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ jobs:

- name: Install Nix
uses: ./.github/actions/nix_installer_and_cache
with:
cache-unique-id: ${{ matrix.lint_projects }}
id: nix-installer

- uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43
Expand All @@ -80,14 +82,13 @@ jobs:

- name: Run lint ${{ matrix.lint_projects }}
run: make -f implementations/rust/Makefile lint_${{ matrix.lint_projects }}

- name: Upload Nix Store
uses: ./.github/actions/upload_nix_store
with:
flake_nix_path: ./tools/nix

- name: Nix Upload Store
uses: ./.github/actions/nix_upload_store
if: ${{ steps.nix-installer.outputs.cache-hit != 'true' }}



build:
name: Rust - build${{ matrix.build_projects != 'packages' && format('_{0}', matrix.build_projects) || '' }}
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -115,6 +116,8 @@ jobs:

- name: Install Nix
uses: ./.github/actions/nix_installer_and_cache
with:
cache-unique-id: ${{ matrix.build_projects }}
id: nix-installer

- uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43
Expand All @@ -124,12 +127,12 @@ jobs:
- name: Run build ${{ matrix.build_projects }}
run: make -f implementations/rust/Makefile ${{ matrix.make_name }}

- uses: ./.github/actions/upload_nix_store
with:
flake_nix_path: ./tools/nix
- name: Nix Upload Store
uses: ./.github/actions/nix_upload_store
if: ${{ steps.nix-installer.outputs.cache-hit != 'true' }}



test:
name: Rust - test${{ matrix.test_projects != 'stable' && format('_{0}', matrix.test_projects) || '' }}
runs-on: ubuntu-22.04
Expand All @@ -154,6 +157,8 @@ jobs:

- name: Install Nix
uses: ./.github/actions/nix_installer_and_cache
with:
cache-unique-id: ${{ matrix.test_projects }}
id: nix-installer

- uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43
Expand All @@ -163,12 +168,12 @@ jobs:
- name: Run test on ${{ matrix.test_projects }}
run: make -f implementations/rust/Makefile test

- uses: ./.github/actions/upload_nix_store
with:
flake_nix_path: ./tools/nix
- name: Nix Upload Store
uses: ./.github/actions/nix_upload_store
if: ${{ steps.nix-installer.outputs.cache-hit != 'true' }}



check:
name: Rust - check_${{ matrix.check_projects }}
runs-on: ubuntu-22.04
Expand All @@ -195,6 +200,8 @@ jobs:

- name: Install Nix
uses: ./.github/actions/nix_installer_and_cache
with:
cache-unique-id: ${{ matrix.check_projects }}
id: nix-installer

- uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43
Expand All @@ -204,14 +211,13 @@ jobs:
- name: Run check on ${{ matrix.check_projects }}
run: |
make -f implementations/rust/Makefile check${{ matrix.check_projects != 'nightly' && format('_{0}', matrix.check_projects) || '' }}
echo "kkddkk ${{ steps.nix-installer.outputs.cache-hit }}"
- uses: ./.github/actions/upload_nix_store
with:
flake_nix_path: ./tools/nix
- name: Nix Upload Store
uses: ./.github/actions/nix_upload_store
if: ${{ steps.nix-installer.outputs.cache-hit != 'true' }}



test_ockam_command:
name: Rust - test_ockam_command
strategy:
Expand Down Expand Up @@ -243,6 +249,8 @@ jobs:

- name: Install Nix
uses: ./ockam_bats/.github/actions/nix_installer_and_cache
with:
cache-unique-id: test_ockam_command
id: nix-installer

- name: Build Binary
Expand All @@ -269,11 +277,11 @@ jobs:
OCKAM_DISABLE_UPGRADE_CHECK: 1
BATS_TEST_RETRIES: 2

- uses: ./ockam_bats/.github/actions/upload_nix_store
with:
flake_nix_path: ./tools/nix
- name: Nix Upload Store
uses: ./ockam_bats/.github/actions/nix_upload_store
if: ${{ steps.nix-installer.outputs.cache-hit != 'true' }}


ockam_command_cross_build:
name: Rust - ockam_command_cross_build
strategy:
Expand Down Expand Up @@ -344,6 +352,8 @@ jobs:

- name: Install Nix
uses: ./ockam_library/.github/actions/nix_installer_and_cache
with:
cache-unique-id: test_docs_rust_library_examples
id: nix-installer

- uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43
Expand All @@ -359,11 +369,11 @@ jobs:
shell: nix develop ./tools/nix#rust --keep CI --ignore-environment --command bash {0}
run: cargo test -p hello_ockam

- uses: ./ockam_library/.github/actions/upload_nix_store
with:
flake_nix_path: ./tools/nix
- name: Nix Upload Store
uses: ./.github/actions/nix_upload_store
if: ${{ steps.nix-installer.outputs.cache-hit != 'true' }}


lint_docs_ockam_io_rust_examples:
name: Rust - lint_docs_ockam_io_rust_examples
runs-on: ubuntu-22.04
Expand All @@ -383,6 +393,8 @@ jobs:

- name: Install Nix
uses: ./ockam/.github/actions/nix_installer_and_cache
with:
cache-unique-id: lint_docs_ockam_io_rust_examples
id: nix-installer

- name: Build Example Blocks
Expand All @@ -394,8 +406,6 @@ jobs:
run: |
CHECK_MD_DIR="ockam-documentation/reference/libraries/rust" CHECK_MD_DIR_RUST_EXAMPLE="ockam/examples/rust/get_started" OCKAM_HOME="ockam" ockam/tools/docs/check_documentation.sh
- uses: ./ockam/.github/actions/upload_nix_store
with:
flake_nix_path: ./tools/nix
- name: Nix Upload Store
uses: ./.github/actions/nix_upload_store
if: ${{ steps.nix-installer.outputs.cache-hit != 'true' }}

9 changes: 8 additions & 1 deletion .github/workflows/shell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ jobs:
ref: ${{ github.event.inputs.commit_sha }}

- name: Install Nix
uses: ./.github/actions/nix_installer
uses: ./.github/actions/nix_installer_and_cache
with:
cache-unique-id: shell
id: nix-installer

- name: Run Shfmt Check
run: nix run ./tools/nix#shfmt-all

- name: Nix Upload Store
uses: ./.github/actions/nix_upload_store
if: ${{ steps.nix-installer.outputs.cache-hit != 'true' }}

0 comments on commit e24c0b1

Please sign in to comment.