Skip to content

Commit

Permalink
♻️ Just use env
Browse files Browse the repository at this point in the history
instead of having to pass all the variables
  • Loading branch information
boredland committed Oct 17, 2024
1 parent 1b85ef7 commit 20e468b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 60 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ jobs:
- name: test action
uses: ./
with:
ALCHEMY_API_KEY: "bla"
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}
env:
RPC_POLYGON: "https://rpc.polygon.com"

- name: test action (assertion)
run: |
test "${{env.RPC_POLYGON}}" = "https://rpc.polygon.com"
test "${{env.RPC_MAINNET}}" = "https://eth-mainnet.g.alchemy.com/v2/bla"
test "${{env.RPC_MAINNET}}" = "https://eth-mainnet.g.alchemy.com/v2/${{ secrets.ALCHEMY_API_KEY }}"
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Action: `action-rpc-env`

This action iterates over the supported chain ids and sets the corresponding env var.

## Inputs

### `ALCHEMY_API_KEY`

Alchemy API key

If given, the action substitute missing RPC_URLs with one constructed from the given key.

### Usage

```
- uses: bgd-labs/action-rpc-env@main
with:
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}
env:
RPC_POLYGON: "https://rpc.polygon.com"
```
29 changes: 1 addition & 28 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,7 @@ description: "Iterates over the supported chain ids and sets the corresponding e
inputs:
ALCHEMY_API_KEY:
description: "Alchemy API key"
RPC_MAINNET:
description: "RPC for mainnet"
RPC_POLYGON:
description: "RPC for polygon"
RPC_AVALANCHE:
description: "RPC for avalanche"
RPC_OPTIMISM:
description: "RPC for optimism"
RPC_ARBITRUM:
description: "RPC for arbitrum"
RPC_METIS:
description: "RPC for metis"
RPC_BASE:
description: "RPC for base"
RPC_FANTOM:
description: "RPC for fantom"
RPC_BNB:
description: "RPC for bnb"
RPC_GNOSIS:
description: "RPC for gnosis"
RPC_ZKEVM:
description: "RPC for polygon zk evm"
RPC_SCROLL:
description: "RPC for scroll"
RPC_ZKSYNC:
description: "RPC for zksync"
RPC_SEPOLIA:
description: "RPC for sepolia"
required: false

runs:
using: "node20"
Expand Down
10 changes: 1 addition & 9 deletions dist/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -23770,15 +23770,7 @@ var getRPCUrl = (chainId, alchemyKey2) => {
var alchemyKey = (0, import_core.getInput)("ALCHEMY_API_KEY") !== "" ? (0, import_core.getInput)("ALCHEMY_API_KEY") : void 0;
for (const chainId of supportedChainIds) {
const envVarName = networkEnv[chainId];
const input = (0, import_core.getInput)(envVarName);
const hasEnvVar = input && input !== "";
if (hasEnvVar) {
(0, import_core.debug)(`Found '${envVarName}' env var and using it.`);
(0, import_core.exportVariable)(networkEnv[chainId], input);
} else {
(0, import_core.debug)(`No '${envVarName}; env var, using alchemy.`);
(0, import_core.exportVariable)(networkEnv[chainId], getRPCUrl(chainId, alchemyKey));
}
(0, import_core.exportVariable)(envVarName, getRPCUrl(chainId, alchemyKey));
}
/*! Bundled license information:

Expand Down
10 changes: 1 addition & 9 deletions dist/action.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23775,15 +23775,7 @@ var getRPCUrl = (chainId, alchemyKey2) => {
var alchemyKey = (0, import_core.getInput)("ALCHEMY_API_KEY") !== "" ? (0, import_core.getInput)("ALCHEMY_API_KEY") : void 0;
for (const chainId of supportedChainIds) {
const envVarName = networkEnv[chainId];
const input = (0, import_core.getInput)(envVarName);
const hasEnvVar = input && input !== "";
if (hasEnvVar) {
(0, import_core.debug)(`Found '${envVarName}' env var and using it.`);
(0, import_core.exportVariable)(networkEnv[chainId], input);
} else {
(0, import_core.debug)(`No '${envVarName}; env var, using alchemy.`);
(0, import_core.exportVariable)(networkEnv[chainId], getRPCUrl(chainId, alchemyKey));
}
(0, import_core.exportVariable)(envVarName, getRPCUrl(chainId, alchemyKey));
}
/*! Bundled license information:

Expand Down
13 changes: 1 addition & 12 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,5 @@ const alchemyKey =
*/
for (const chainId of supportedChainIds) {
const envVarName = networkEnv[chainId];

const input = getInput(envVarName);

const hasEnvVar = input && input !== "";

if (hasEnvVar) {
debug(`Found '${envVarName}' env var and using it.`);
exportVariable(networkEnv[chainId], input);
} else {
debug(`No '${envVarName}; env var, using alchemy.`);
exportVariable(networkEnv[chainId], getRPCUrl(chainId, alchemyKey));
}
exportVariable(envVarName, getRPCUrl(chainId, alchemyKey));
}

0 comments on commit 20e468b

Please sign in to comment.