scaffold-eth-2 icon indicating copy to clipboard operation
scaffold-eth-2 copied to clipboard

gh-actions fails for foundry

Open JacobHomanics opened this issue 1 year ago • 12 comments

Is there an existing issue for this?

Current Behavior

When using a project built with "npx create-eth@latest" and the selected option for "What solidity framework do you want to use" is "Foundry", then any time successfully push commit to GitHub, the Git Hooks will fail on the step "Run hardhat node, deploy contracts (& generate contracts typescript output)".

Expected Behavior

When pushing a commit to GitHub while using a project built from "npx create-eth@latest" and Foundry is the selected Solidity Framework, then the Git Hooks should succeed in deploying a local foundry chain and deploy contracts (& generate contracts typescript output).

Steps To Reproduce

  1. Go to: https://scaffoldeth.io/.
  2. Open CLI.
  3. Run command "npx create-eth@latest" from "https://scaffoldeth.io" in CLI.
  4. In CLI, enter any project name.
  5. In CLI, Select "Foundry" as the selected Solidity Framework.
  6. In CLI, Select "yes" to Install packages.
  7. Wait for packages to install, and observe the created project files on your local machine.
  8. Clone an empty repository from Github to local machine.
  9. Move the created project files from local machine into the local empty repository.
  10. Observe changes, commit changes, push changes.
  11. Wait for Git hooks to be ran on Github.com. Should fail.

Anything else?

You can see my current implementation in my own project here: https://github.com/ATXDAO/reputation-and-roles-monorepo/actions/runs/6869607334/job/18682721792

JacobHomanics avatar Nov 14 '23 22:11 JacobHomanics

No. 8 and 9 are not necessary, change the GitHub URL directly from the project rather than copying the whole files into another folder After having your project dependencies installed run "git remote set-url origin new.git.url/here"

KcPele avatar Nov 15 '23 04:11 KcPele

Thanks for reporting this @Hotmanics !

You are right! Since the GitHub action env doesn't have anvil / forge installed, it can't init the local node + deploy contracts

I think the solution might be to use https://github.com/marketplace/actions/foundry-toolchain on the projects using the foundry template.

carletex avatar Nov 15 '23 09:11 carletex

I'm using npx create-eth@latest with foundry option for the current Chainlink hackathon, and experienced these errors as well.

I ended up coming up with some hacky work-around for the build stage that was also failing (unmet dependency from another package).

  • essentially, had to manually edit the yarn.lock file with this small change added from https://github.com/timolins/react-hot-toast/pull/262, as the underlying package hasn't closed this old PR yet.

I do have the CI lint stage fully passing and working with foundry now though.

Do you want me to open a PR with my changes made?

Hampton-Black avatar Nov 17 '23 20:11 Hampton-Black

I do have the CI lint stage fully passing and working with foundry now though.

That's great. I saw that you added foundry toolchain.

It'd be great if you could make a PR. Take a look at the CLI branch and the docs for devs, which explain a bit how to contribute to the CLI branch (it's trickier than contributing to main since we are using a template engine)

I ended up coming up with some hacky work-around for the build stage that was also failing (unmet dependency from another package). essentially, had to manually edit the yarn.lock file with this small change added from https://github.com/timolins/react-hot-toast/pull/262, as the underlying package hasn't closed this old PR yet.

Never happened before to me (but similar ones did happen). Since we don't have a yarn.lock file on the CLI branch (it'd depend on the CLI user selection), the solution could be to lock the dep in package.json file (eg. 2.0.0 instead of ~2.0.0).

If you open a PR we can assist you there too!

Thanks @Hampton-Black !!

carletex avatar Nov 20 '23 10:11 carletex

Thanks for reporting this @Hotmanics !

You are right! Since the GitHub action env doesn't have anvil / forge installed, it can't init the local node + deploy contracts

I think the solution might be to use https://github.com/marketplace/actions/foundry-toolchain on the projects using the foundry template.

Attempting to do this...

I added

      - name: Install Foundry
        uses: foundry-rs/foundry-toolchain@v1

      - name: Run tests
        run: forge test -vvv

      - name: Run snapshot
        run: forge snapshot

to the lint.yaml file and that works perfectly fine!

however when I try

      - name: Run hardhat node, deploy contracts (& generate contracts typescript output)
        run: yarn chain & yarn deploy 

It errors out when looking for an etherscan environment variable (obviously, since .env files do not get pushed to github). Not sure on the best plan of action there...?

Additionally, modifying the command to be

      - name: Run hardhat node, deploy contracts (& generate contracts typescript output)
        run: yarn chain

leaves the check stuck in a never-ending check that never progresses to the next job.

Anyone have any suggestions for this?

JacobHomanics avatar Nov 29 '23 08:11 JacobHomanics

Hey @Hotmanics !

You could do something like (got it from @Hampton-Black repo):

      - name: Run foundry node, deploy contracts (& generate contracts typescript output)
        env:
          ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}
        run: yarn chain & yarn deploy
        id: build

Where you specify the env variable there (using GitHub secrets in this case). I guess you could even have a random/fake API KEY (so it won't complain) since this is just deploying it on the local chain that spins for checking the linting.

Let us know how it goes! Thanks.

carletex avatar Nov 29 '23 10:11 carletex

Sorry I haven't done the PR yet for this.

I'm still planning to, but might have to wait until after the hackathon is finished (next weekend).

Hampton-Black avatar Nov 30 '23 00:11 Hampton-Black

Hey @Hotmanics !

You could do something like (got it from @Hampton-Black repo):

      - name: Run foundry node, deploy contracts (& generate contracts typescript output)
        env:
          ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}
        run: yarn chain & yarn deploy
        id: build

Where you specify the env variable there (using GitHub secrets in this case). I guess you could even have a random/fake API KEY (so it won't complain) since this is just deploying it on the local chain that spins for checking the linting.

Let us know how it goes! Thanks.

Seems to of fixed the issue regarding the env variable thank you.

But now getting stuck for HOURS on the yarn chain aspect. You can check my failed job run here: https://github.com/ATXDAO/reputation-and-roles-monorepo/actions/runs/7035555721/job/19146198098

JacobHomanics avatar Nov 30 '23 07:11 JacobHomanics

Sorry I haven't done the PR yet for this.

I'm still planning to, but might have to wait until after the hackathon is finished (next weekend).

will be eagerly anticipating this and glad to help push it forward however I can.

JacobHomanics avatar Nov 30 '23 07:11 JacobHomanics

Hey @Hampton-Black, please let us know if you need any help / stuck with cli branch also this DEVELOPER-GUIDE.md might be helpful, but yeah please feel free to drop any issues/doubts 🙌

technophile-04 avatar Dec 17 '23 16:12 technophile-04

Might need some help.

I have it splitting up the github workflow files how I want now, but I'm getting errors with initializing the repo now via the CLI tool.

Here's my fork: https://github.com/Hampton-Black/scaffold-eth-2/tree/607-gh-actions-lint-split

and a sample actions pipeline: https://github.com/Hampton-Black/cli-test-5/actions/runs/7304157195

Hampton-Black avatar Dec 22 '23 22:12 Hampton-Black

I think its better if we keep it simple for the first PR.

We don't want to split job as I see in https://github.com/Hampton-Black/cli-test-5/actions/runs/7304157195, Actually we want to run frontend lint after yarn deploy (since this generate necessary types for frontend ).

So for initial draft PR:

  1. Copy our current main branch lint.yaml inside templates/extensions/hardhat/.github/workflows

  2. Copy this foundry version lint.yaml inside templates/extensions/foundry/.github/workflows

next we can iterate on created PR, Thanks @Hampton-Black 🙌

technophile-04 avatar Dec 23 '23 05:12 technophile-04

Completed at https://github.com/scaffold-eth/create-eth/pull/38

technophile-04 avatar May 27 '24 23:05 technophile-04