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

Add CI Job to check generate file changes #438

Merged
merged 7 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
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
66 changes: 65 additions & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,72 @@ jobs:
- name: Lint
run: npm run check

generate:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore Cargo cache
id: cargo-cache
uses: actions/cache/restore@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Add Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
targets: wasm32-unknown-unknown
- name: Install dependencies
run: npm ci
- name: Set env
run: |
release=$(curl --silent "https://api.github.com/repos/dfinity/candid/releases/latest" | grep -e '"tag_name"' | cut -c 16-25)
echo "DIDC_RELEASE=$(echo $release)" >> $GITHUB_ENV
- name: Restore didc cache
id: didc-cache
uses: actions/cache/restore@v4
with:
path: /usr/local/bin/didc
key: ${{ runner.os }}-didc-${{ env.DIDC_RELEASE }}
- name: Add didc dependency
if: steps.didc-cache.outputs.cache-hit != 'true'
run: |
curl -SL https://github.com/dfinity/candid/releases/download/$DIDC_RELEASE/didc-linux64 > /usr/local/bin/didc
chmod +x /usr/local/bin/didc
- name: Save didc
uses: actions/cache/save@v4
if: steps.didc-cache.outputs.cache-hit != 'true'
with:
path: /usr/local/bin/didc
key: ${{ runner.os }}-didc-${{ env.DIDC_RELEASE }}
- name: Install candid-extractor
if: steps.cargo-cache.outputs.cache-hit != 'true'
run: cargo install candid-extractor
- name: Generating candids
run: ENV=github npm run generate
- name: Save Cargo
uses: actions/cache/save@v4
if: steps.cargo-cache.outputs.cache-hit != 'true'
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Check if files are touched
run: if [[ -n $(git status --porcelain) ]]; then echo "Files diff. Failed. Exiting" >&2 && exit 1; else echo "PASSED"; fi

may-merge:
needs: ['check', 'lint']
needs: ['check', 'lint', 'generate']
runs-on: ubuntu-latest
steps:
- name: Cleared for merging
Expand Down
21 changes: 21 additions & 0 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This document explains how to run locally [Juno](https://juno.build).
- [Run locally](#run-locally)
- [Development](#development)
- [Top-up](#top-up)
- [Troubleshooting](#troubleshooting)

## Run locally

Expand Down Expand Up @@ -76,3 +77,23 @@ Top-up the local console with some cycles:
```
npm run console:topup
```

## Troubleshooting

### didc command not found

Go to [Candid releases](https://github.com/dfinity/candid/releases) page to download your OS version didc.

Example, for macos

```sh
release=$(curl --silent "https://api.github.com/repos/dfinity/candid/releases/latest" | grep -e '"tag_name"' | cut -c 16-25)
curl -fsSL https://github.com/dfinity/candid/releases/download/$release/didc-macos > ~/.cargo/bin/didc
chmod 755 ~/.cargo/bin/didc
```

### candid-extractor command not found

```sh
cargo install candid-extractor
```
12 changes: 9 additions & 3 deletions scripts/did.idl.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

function generate_did_idl() {
local canister=$1
local canister_root=$2
Expand All @@ -20,6 +22,10 @@ done

generate_did_idl "cmc" "candid"
generate_did_idl "ic" "candid"
generate_did_idl "index" "."
generate_did_idl "ledger" "."
generate_did_idl "internet_identity" "."

if [ "$ENV" != "github" ]
then
generate_did_idl "index" "."
generate_did_idl "ledger" "."
generate_did_idl "internet_identity" "."
fi