Skip to content

Commit d594257

Browse files
authored
fix solc github action (#4426)
## Motivation The GH Action we use for downloading Solidity compiler (https://github.com/actions-marketplace-validations/pontem-network_get-solc) is broken ([example run](https://github.com/linera-io/linera-protocol/actions/runs/17267402272/job/49002750463)). The link returns **301** but original `curl` does not follow the redirections. ## Proposal Bring the action in and fix. The fix is ``` if [ -z $SECRET_TOKEN ]; then curl -o "$RELEASES_PATH.tmp" \ -s https://api.github.com/repos/ethereum/solidity/releases else curl -o "$RELEASES_PATH.tmp" \ -H "Authorization: Bearer ${SECRET_TOKEN}" \ -s https://api.github.com/repos/ethereum/solidity/releases fi ``` changed to ``` if [ -z $SECRET_TOKEN ]; then curl -sL -o "$RELEASES_PATH.tmp" \ -s https://api.github.com/repos/ethereum/solidity/releases else curl -sL -o "$RELEASES_PATH.tmp" \ -H "Authorization: Bearer ${SECRET_TOKEN}" \ -s https://api.github.com/repos/ethereum/solidity/releases fi ``` the `-sL` added configures `curl` to follow the redirections. ## Test Plan CI ## Release Plan - Nothing to do ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent 0d1ad45 commit d594257

File tree

3 files changed

+209
-1
lines changed

3 files changed

+209
-1
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Get Solc
2+
description: Download `solc` tool.
3+
author: Pontem Network team
4+
branding:
5+
icon: sunrise
6+
color: purple
7+
inputs:
8+
version:
9+
default: "latest"
10+
description: Solc version (ex. `v0.8.15` or default `latest`).
11+
required: false
12+
token:
13+
description: GITHUB_TOKEN. Optional
14+
required: false
15+
prerelease:
16+
default: "false"
17+
description: Allow pre-release. False by default.
18+
required: false
19+
runs:
20+
using: "composite"
21+
steps:
22+
- name: Download
23+
run: $GITHUB_ACTION_PATH/solc_download.sh
24+
shell: bash
25+
env:
26+
SOLC_VERSION: ${{inputs.version}}
27+
SOLC_PRERELEASE: ${{inputs.prerelease}}
28+
SECRET_TOKEN: ${{inputs.token}}
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
#!/bin/bash
2+
3+
# ======================================================================================================================
4+
# Solc folder
5+
# ======================================================================================================================
6+
SOLC_FOLDER="$HOME/.solc"
7+
if [ ! -e $SOLC_FOLDER ]; then
8+
echo "Create solc folder: $SOLC_FOLDER"
9+
mkdir -p $SOLC_FOLDER
10+
fi
11+
12+
# ======================================================================================================================
13+
# Token
14+
# ======================================================================================================================
15+
if [[ -z $SECRET_TOKEN ]]; then
16+
SECRET_TOKEN=""
17+
if [[ ! -z $2 ]]; then
18+
SECRET_TOKEN=$2
19+
fi
20+
fi
21+
if [[ ! -z $SECRET_TOKEN ]]; then
22+
echo "Token: ***"
23+
fi
24+
25+
# ======================================================================================================================
26+
# releases.json
27+
# ======================================================================================================================
28+
RELEASES_PATH="$SOLC_FOLDER/releases.json"
29+
if [ ! -e $RELEASES_PATH ] || [ $(($(date "+%s") - $(date -r $RELEASES_PATH "+%s"))) -ge 600 ]; then
30+
echo "Download: releases.json"
31+
if [ -z $SECRET_TOKEN ]; then
32+
curl -sL -o "$RELEASES_PATH.tmp" \
33+
-s https://api.github.com/repos/ethereum/solidity/releases
34+
else
35+
curl -sL -o "$RELEASES_PATH.tmp" \
36+
-H "Authorization: Bearer ${SECRET_TOKEN}" \
37+
-s https://api.github.com/repos/ethereum/solidity/releases
38+
fi
39+
mv "$RELEASES_PATH.tmp" $RELEASES_PATH
40+
fi
41+
42+
# check release.json
43+
MESSAGE=$(jq '.message?' -r $RELEASES_PATH)
44+
if [[ ! -z $MESSAGE ]]; then
45+
echo "Message: $MESSAGE"
46+
rm $RELEASES_PATH
47+
exit 5
48+
fi
49+
50+
# ======================================================================================================================
51+
# pre-release (prerelease=true)
52+
# ======================================================================================================================
53+
if [[ -z $SOLC_PRERELEASE ]]; then
54+
SOLC_PRERELEASE="false"
55+
if [[ ! -z $3 ]]; then
56+
SOLC_PRERELEASE=$3
57+
fi
58+
else
59+
if [ $SOLC_PRERELEASE != "true" ] && [ $SOLC_PRERELEASE != "false" ]; then
60+
SOLC_PRERELEASE="false"
61+
else
62+
SOLC_PRERELEASE="true"
63+
fi
64+
fi
65+
66+
echo "Pre-release: $SOLC_PRERELEASE"
67+
68+
SELECT_PRERELEASE=""
69+
if [ $SOLC_PRERELEASE == "false" ]; then
70+
SELECT_PRERELEASE=".prerelease==false"
71+
else
72+
SELECT_PRERELEASE="."
73+
fi
74+
75+
# ======================================================================================================================
76+
# Solc VERSION
77+
# ======================================================================================================================
78+
VERSION=""
79+
if [[ ! -z $SOLC_VERSION ]]; then
80+
VERSION=$SOLC_VERSION
81+
elif [[ ! -z $1 ]]; then
82+
VERSION=$1
83+
fi
84+
if [[ $VERSION == "latest" || $VERSION == "new" || $VERSION == "last" || -z $VERSION ]]; then
85+
# Get the latest VERSION
86+
VERSION=$(cat "$RELEASES_PATH" | jq -r '.[] | select(("${SELECT_PRERELEASE}") and .tag_name) .tag_name' | head -n1)
87+
if [[ -z $VERSION ]]; then
88+
echo "{$VERSION|$SOLC_PRERELEASE} The specified version of solc was not found"
89+
exit 6
90+
fi
91+
else
92+
if [ ! $(cat "$RELEASES_PATH" | jq ".[] | select("${SELECT_PRERELEASE}" and .tag_name==\"${VERSION}\") .tag_name") ]; then
93+
echo "{$VERSION} The specified version of solc was not found"
94+
exit 1
95+
fi
96+
fi
97+
echo "version: $VERSION"
98+
99+
if [[ "$OSTYPE" == "linux-gnu"* || "$OSTYPE" == "freebsd"* || "$OSTYPE" == "cygwin" ]]; then
100+
NAME="solc-static-linux"
101+
elif [[ "$OSTYPE" == "darwin"* ]]; then
102+
NAME="solc-macos"
103+
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
104+
NAME="solc-windows.exe"
105+
else
106+
echo "Unknown OS"
107+
exit 2
108+
fi
109+
110+
# ======================================================================================================================
111+
# Download
112+
# ======================================================================================================================
113+
DOWNLOAD_URL=$(
114+
cat "$RELEASES_PATH" |
115+
jq -r "
116+
.[]
117+
| select(${SELECT_PRERELEASE} and .tag_name==\"${VERSION}\") .assets
118+
| .[]
119+
| select(.name==\"${NAME}\")
120+
| .browser_download_url
121+
"
122+
)
123+
124+
if [ -z $DOWNLOAD_URL ]; then
125+
echo "Releases \"${VERSION}/${NAME}\" not found"
126+
exit 3
127+
fi
128+
129+
VERSION_DIR="$SOLC_FOLDER/$VERSION"
130+
if [ ! -e $VERSION_DIR ]; then
131+
if ! mkdir -p $VERSION_DIR; then
132+
echo "Failed to create a directory ${VERSION_DIR}"
133+
exit 7
134+
fi
135+
fi
136+
137+
FILE_PATH="$VERSION_DIR/$NAME"
138+
if [ ! -e $FILE_PATH ]; then
139+
echo "Download: $DOWNLOAD_URL"
140+
if [ -z $SECRET_TOKEN ]; then
141+
curl -sL --fail \
142+
-H "Accept: application/octet-stream" \
143+
-o "$FILE_PATH.tmp" \
144+
-s $DOWNLOAD_URL
145+
else
146+
curl -sL --fail \
147+
-H "Accept: application/octet-stream" \
148+
-H "Authorization: Bearer ${SECRET_TOKEN}" \
149+
-o "$FILE_PATH.tmp" \
150+
-s $DOWNLOAD_URL
151+
fi
152+
mv "$FILE_PATH.tmp" $FILE_PATH
153+
fi
154+
155+
echo "chmod 1755 $FILE_PATH"
156+
chmod 1755 $FILE_PATH
157+
echo "create link $FILE_PATH"
158+
echo "OS: ${OSTYPE}"
159+
160+
if [[ "$OSTYPE" == "linux-gnu"* || "$OSTYPE" == "freebsd"* || "$OSTYPE" == "cygwin" ]]; then
161+
mkdir -p $HOME/.local/bin
162+
ln -sf "$FILE_PATH" $HOME/.local/bin/solc
163+
echo "$HOME/.local/bin" >>$GITHUB_PATH
164+
elif [[ "$OSTYPE" == "darwin"* ]]; then
165+
ln -sf "$FILE_PATH" /usr/local/bin/solc
166+
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
167+
mkdir -p "$HOME/.local/bin"
168+
ln -sf "$FILE_PATH" "$HOME/.local/bin/solc"
169+
echo "$HOME/.local/bin" >>$GITHUB_PATH
170+
else
171+
echo "Unknown OS"
172+
exit 4
173+
fi
174+
175+
# ======================================================================================================================
176+
# run
177+
# ======================================================================================================================
178+
echo "run: $FILE_PATH --version"
179+
$FILE_PATH --version
180+
solc --version

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ jobs:
229229
restore-keys: solc-
230230
- name: Get Solc
231231
if: ${{ steps.cache-solc.outputs.cache-hit != 'true' }}
232-
uses: pontem-network/get-solc@master
232+
uses: ./.github/actions/get-solc
233233
with:
234234
version: v0.8.25
235235
- name: Add Solc to PATH

0 commit comments

Comments
 (0)