-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: David Dal Busco <[email protected]>
- Loading branch information
1 parent
ab079bc
commit cee9e74
Showing
5 changed files
with
299 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env bash | ||
|
||
download_did() { | ||
local raw_url="$1" | ||
local out_filename="$2" | ||
local folder="$3" | ||
|
||
local out_path="${folder}/${out_filename}" | ||
|
||
# Extract repository, branch, and file path from the raw URL | ||
local repo=$(echo "$raw_url" | awk -F '/' '{print $4"/"$5}') | ||
local branch=$(echo "$raw_url" | awk -F '/' '{print $6}') | ||
local file_path=$(echo "$raw_url" | awk -F "$branch/" '{print $2}') | ||
|
||
# Get the latest commit hash for the specified file | ||
local api_url="https://api.github.com/repos/${repo}/commits?path=${file_path}&sha=${branch}" | ||
local commit_hash=$(curl -s "$api_url" | jq -r '.[0].sha') | ||
|
||
if [ -z "$commit_hash" ]; then | ||
echo "Failed to retrieve commit hash for ${file_path} in ${repo}." | ||
return 1 | ||
fi | ||
|
||
echo "Downloading ${raw_url} -> REPO_ROOT/${out_path}" | ||
{ | ||
echo "// Generated from ${repo} commit ${commit_hash} for file '${file_path}'" | ||
curl -s "$raw_url" | ||
} >"${out_path}" | ||
} | ||
|
||
download_did https://raw.githubusercontent.com/dfinity/portal/master/docs/references/_attachments/ic.did "ic.did" "candid" |
Oops, something went wrong.