name: 📦 Upload Bytecode
on:
  push:
    branches:
      - main
jobs:
  upload-bytecode:
    runs-on: "ubuntu-latest"
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: recursive
      - name: Install Foundry
        uses: foundry-rs/foundry-toolchain@v1
        with:
          version: nightly
      - name: "Generate and prepare the contract artifacts"
        run: |
          mkdir bytecode
          for file in $(find src -name '*.sol'); do
            if grep -q "interface " "$file" || grep -q "library " "$file"; then
              continue
            fi
            contract_name=$(basename "$file" .sol)
            forge inspect "$contract_name" bytecode > bytecode/"$contract_name".json
          done
      - name: "Store the contract artifacts in CI"
        uses: "actions/upload-artifact@v4"
        with:
          name: "contract-bytecode"
          path: "bytecode"
