Skip to content
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
22 changes: 20 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
test:
runs-on: ubuntu-latest
name: test-all # PRs can require just this job to pass, regardless of matrix changes below
needs: [test_matrix]
needs: [test_matrix, test_multi]
steps:
- run: echo "Test-matrix successful" # anything with zero exit code

Expand All @@ -20,7 +20,7 @@ jobs:
matrix:
os: [macos-15-intel, ubuntu-latest] # arm64 and Windows aren't supported
solc: ['0.8.30', '0.8.25'] # arbitrary, but different
name: setup-solc
name: setup-solc_${{matrix.solc}}_${{matrix.os}}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v5
Expand All @@ -32,3 +32,21 @@ jobs:

- name: Check version
run: solc --version | grep "${{matrix.solc}}"

test_multi:
name: setup-solc-multi-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5

- id: setup
uses: ./
with:
version: 0.8.30
versions: '0.8.30,0.8.29'

- name: Check versions
run: |
solc --version | grep 0.8.30;
solc-v0.8.30 --version | grep 0.8.30;
solc-v0.8.29 --version | grep 0.8.29;
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ jobs:
name: print-solc-version
runs-on: ubuntu-latest
steps:
- uses: arr4n/setup-solc@main # TODO: use a commit hash for better security
- uses: arr4n/setup-solc@v0.2.0
with:
version: 0.8.30
version: 0.8.30 # installed as solc
versions: '0.8.25,0.8.28' # installed as solc-v0.8.25 and solc-v0.8.28

- run: solc --version
- run: |
solc --version;
solc-v0.8.25 --version;
solc-v0.8.28 --version;
```

The specified version MUST be a specific semver (without a "v" prefix).
The specified version(s) MUST be specific semver (without a "v" prefix).
Caret (^), tilde (~) and keyword (e.g. "latest") versions are deliberately unsupported because blockchain development requires precision.

10 changes: 5 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ branding:
color: blue
inputs:
version:
description: 'Specific solc version'
required: true
outputs:
solc:
description: 'Path to solc binary'
description: 'Version to be installed as `solc`'
default: ''
versions:
description: 'Comma-separated list of versions to be installed as `solc-v<ver>'
default: ''
runs:
using: 'node20'
main: 'dist/index.js'
61 changes: 44 additions & 17 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29819,9 +29819,6 @@ function requireToolCache () {
var toolCacheExports = requireToolCache();

try {
const version = coreExports.getInput('version');
coreExports.info(`Setting up solc version ${version}`);

if (process.arch != 'x64') {
throw Error(`Unsupported architecture ${process.arch}`)
}
Expand All @@ -29839,27 +29836,57 @@ try {
}

const constructURL = (fileName) => `https://binaries.soliditylang.org/${pathPrefix}/${fileName}`;

const list = await fetch(constructURL('list.json')).then(res => res.json());

const build = list.builds.find((build) => build.version == version);
if (build === undefined) {
throw Error(`Version ${version} not found`);
}

const downloaded = await toolCacheExports.downloadTool(constructURL(build.path));

const destDir = path.join(process.cwd(), 'setup-solc_downloads');
await fs.mkdir(destDir);
const solc = path.join(destDir, 'solc');
await fs.rename(downloaded, solc);
await fs.chmod(solc, 0o555);

coreExports.addPath(destDir);
coreExports.setOutput('solc', solc);
coreExports.info(`solc at ${solc}`);

for (const [version, outs] of Object.entries(parseVersionInputs())) {
coreExports.info(`Setting up solc version ${version}`);

const build = list.builds.find((build) => build.version == version);
if (build === undefined) {
throw Error(`Version ${version} not found`);
}

const downloaded = await toolCacheExports.downloadTool(constructURL(build.path));
await fs.chmod(downloaded, 0o555);

await Promise.all(
outs.map((out) => fs.copyFile(
downloaded,
path.join(destDir, out)
))
);
console.info(`${version} at ${outs}`);
}

} catch (error) {
coreExports.setFailed(error.message);
}

function parseVersionInputs() {
let versions = {};

const v = coreExports.getInput('version');
if (v != '') {
versions[v] = ['solc'];
}

const multi = coreExports.getInput('versions');
if (multi == '') {
return versions
}
multi.split(',').forEach((v) => {
const out = `solc-v${v}`;
if (v in versions) {
versions[v].push(out);
} else {
versions[v] = [out];
}
});

return versions;
}
//# sourceMappingURL=index.js.map
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "setup-solc",
"version": "0.1.0",
"version": "0.2.0",
"type": "module",
"author": "github.com/arr4n",
"license": "MIT",
"description": "A GitHub action for installing the Solidity compiler, solc.",
"dependencies": {
"@actions/core": "^1.11.1",
Expand Down
61 changes: 44 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import * as core from "@actions/core";
import * as tc from "@actions/tool-cache";

try {
const version = core.getInput('version');
core.info(`Setting up solc version ${version}`);

if (process.arch != 'x64') {
throw Error(`Unsupported architecture ${process.arch}`)
}
Expand All @@ -24,26 +21,56 @@ try {
}

const constructURL = (fileName) => `https://binaries.soliditylang.org/${pathPrefix}/${fileName}`;

const list = await fetch(constructURL('list.json')).then(res => res.json());

const build = list.builds.find((build) => build.version == version);
if (build === undefined) {
throw Error(`Version ${version} not found`);
}

const downloaded = await tc.downloadTool(constructURL(build.path));

const destDir = path.join(process.cwd(), 'setup-solc_downloads');
await fs.mkdir(destDir);
const solc = path.join(destDir, 'solc')
await fs.rename(downloaded, solc);
await fs.chmod(solc, 0o555);

core.addPath(destDir);
core.setOutput('solc', solc);
core.info(`solc at ${solc}`);

for (const [version, outs] of Object.entries(parseVersionInputs())) {
core.info(`Setting up solc version ${version}`);

const build = list.builds.find((build) => build.version == version);
if (build === undefined) {
throw Error(`Version ${version} not found`);
}

const downloaded = await tc.downloadTool(constructURL(build.path));
await fs.chmod(downloaded, 0o555);

await Promise.all(
outs.map((out) => fs.copyFile(
downloaded,
path.join(destDir, out)
))
);
console.info(`${version} at ${outs}`);
}

} catch (error) {
core.setFailed(error.message)
}

function parseVersionInputs() {
let versions = {};

const v = core.getInput('version');
if (v != '') {
versions[v] = ['solc'];
}

const multi = core.getInput('versions');
if (multi == '') {
return versions
}
multi.split(',').forEach((v) => {
const out = `solc-v${v}`;
if (v in versions) {
versions[v].push(out);
} else {
versions[v] = [out];
}
})

return versions;
}