Skip to content

Commit

Permalink
Add install-didc script (#5624)
Browse files Browse the repository at this point in the history
# Motivation

We have the same code to install `didc` in 5 different places.

# Changes

1. Add a script which can install `didc` on Mac or Linux.
2. Use it instead of the existing duplicated code.

# Tests

1. Ran manually on MacOS.
2. CI passes using the new script.

# Todos

- [ ] Add entry to changelog (if necessary).
not necessary
  • Loading branch information
dskloetd authored Oct 15, 2024
1 parent cd96669 commit f8109e4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 35 deletions.
24 changes: 3 additions & 21 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install didc
run: |
USER_BIN="$HOME/.local/bin"
mkdir -p "$USER_BIN"
echo "$USER_BIN" >> $GITHUB_PATH
version="$(jq -r .defaults.build.config.DIDC_RELEASE dfx.json)"
# TODO: Make `didc` support `binstall`, then use `binstall` here.
curl -Lf "https://github.com/dfinity/candid/releases/download/${version}/didc-linux64" | install -m 755 /dev/stdin "$USER_BIN/didc"
run: scripts/install-didc
- name: Check didc
run: command -v didc
- name: Run the ic_commit code generator for proposals
Expand All @@ -162,13 +156,7 @@ jobs:
with:
fetch-depth: 0
- name: Install didc
run: |
USER_BIN="$HOME/.local/bin"
mkdir -p "$USER_BIN"
echo "$USER_BIN" >> $GITHUB_PATH
version="$(jq -r .defaults.build.config.DIDC_RELEASE dfx.json)"
# TODO: Use `binstall`, once `didc` supports it.
curl -Lf "https://github.com/dfinity/candid/releases/download/${version}/didc-linux64" | install -m 755 /dev/stdin "$USER_BIN/didc"
run: scripts/install-didc
- name: Check didc
run: command -v didc
- name: Install dfx
Expand Down Expand Up @@ -217,13 +205,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install didc
run: |
USER_BIN="$HOME/.local/bin"
mkdir -p "$USER_BIN"
echo "$USER_BIN" >> $GITHUB_PATH
version="$(jq -r .defaults.build.config.DIDC_RELEASE dfx.json)"
# TODO: Make `didc` support `binstall`, then use `binstall` here.
curl -Lf "https://github.com/dfinity/candid/releases/download/${version}/didc-linux64" | install -m 755 /dev/stdin "$USER_BIN/didc"
run: scripts/install-didc
- name: Install cargo binstall
uses: ./.github/actions/install_binstall
- name: Install idl2json
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/update-aggregator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install didc
run: |
USER_BIN="$HOME/.local/bin"
mkdir -p "$USER_BIN"
echo "$USER_BIN" >> $GITHUB_PATH
version="$(jq -r .defaults.build.config.DIDC_RELEASE dfx.json)"
# TODO: Make `didc` support `binstall`, then use `binstall` here.
curl -Lf "https://github.com/dfinity/candid/releases/download/${version}/didc-linux64" | install -m 755 /dev/stdin "$USER_BIN/didc"
run: scripts/install-didc
- name: Find newer IC release, if any
id: update
run: |
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/update-proposals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install didc
run: |
USER_BIN="$HOME/.local/bin"
mkdir -p "$USER_BIN"
echo "$USER_BIN" >> $GITHUB_PATH
version="$(jq -r .defaults.build.config.DIDC_RELEASE dfx.json)"
# TODO: Make `didc` support `binstall`, then use `binstall` here.
curl -Lf "https://github.com/dfinity/candid/releases/download/${version}/didc-linux64" | install -m 755 /dev/stdin "$USER_BIN/didc"
run: scripts/install-didc
- name: Find newer IC release, if any
id: update
run: |
Expand Down
33 changes: 33 additions & 0 deletions scripts/install-didc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
set -euo pipefail

SOURCE_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"

# Source the clap.bash file ---------------------------------------------------
source "$SOURCE_DIR/clap.bash"
# Define options
clap.define short=r long=release desc="The didc release to install" variable=RELEASE default="pinned"
# Source the output file ----------------------------------------------------------
source "$(clap.build)"

if [[ "${RELEASE:-}" == "pinned" ]]; then
RELEASE="$(jq -r '.defaults.build.config.DIDC_RELEASE' "$SOURCE_DIR/../dfx.json")"
fi

echo "Installing didc release $RELEASE"

if [[ "$(uname)" == "Darwin" ]]; then
echo "Installing MacOS version"
DIDC_URL="https://github.com/dfinity/candid/releases/download/${RELEASE}/didc-macos"
else
echo "Installing Linux version"
DIDC_URL="https://github.com/dfinity/candid/releases/download/${RELEASE}/didc-linux64"
fi

USER_BIN="$HOME/.local/bin"
mkdir -p "$USER_BIN"
tmpfile="$(mktemp)"
curl -Lf "$DIDC_URL" >"$tmpfile"
install -m 755 "$tmpfile" "$USER_BIN/didc"

echo "Installed $("$USER_BIN/didc" --version)"

0 comments on commit f8109e4

Please sign in to comment.