abi-typegen 0.3.1

Generate bindings from Solidity ABI artifacts (Foundry, Hardhat)
name: Coverage

on:
  workflow_dispatch:
  push:
    branches: [main]
  pull_request:

permissions:
  contents: read
  pages: write
  id-token: write

concurrency:
  group: pages
  cancel-in-progress: false

env:
  CARGO_TERM_COLOR: always

jobs:
  doublcov:
    name: Doublcov
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: llvm-tools-preview

      - name: Cache Rust
        uses: Swatinem/rust-cache@v2

      - name: Install cargo-llvm-cov
        uses: taiki-e/install-action@cargo-llvm-cov

      - name: Restore Doublcov history
        uses: actions/cache/restore@v4
        with:
          path: .doublcov/history.json
          key: doublcov-history-${{ github.ref_name }}-${{ github.run_id }}-${{ github.run_attempt }}
          restore-keys: |
            doublcov-history-${{ github.ref_name }}-
            doublcov-history-

      - name: Generate Doublcov report
        uses: doublesharp/doublcov@v0
        with:
          version: latest
          command: cargo-llvm-cov
          args: --mode static -- --workspace

      - name: Save Doublcov history
        if: always() && hashFiles('.doublcov/history.json') != ''
        uses: actions/cache/save@v4
        with:
          path: .doublcov/history.json
          key: doublcov-history-${{ github.ref_name }}-${{ github.run_id }}-${{ github.run_attempt }}

      - name: Upload Doublcov report
        if: always() && hashFiles('coverage/report/index.html') != ''
        uses: actions/upload-artifact@v4
        with:
          name: doublcov-report
          path: coverage/report
          if-no-files-found: error

      - name: Upload coverage data
        if: always() && hashFiles('coverage/lcov.info') != ''
        uses: actions/upload-artifact@v4
        with:
          name: doublcov-data
          path: |
            coverage/lcov.info
            .doublcov/history.json
          if-no-files-found: warn
          include-hidden-files: true

      - name: Prepare Pages artifact
        if: github.event_name != 'pull_request' && hashFiles('coverage/report/index.html') != ''
        run: |
          mkdir -p pages/coverage
          cp -R coverage/report/. pages/coverage/
          cat > pages/index.html <<'HTML'
          <!doctype html>
          <meta charset="utf-8">
          <title>abi-typegen coverage</title>
          <script>location.replace("coverage/" + location.hash);</script>
          <meta http-equiv="refresh" content="0; url=coverage/">
          <a href="coverage/">abi-typegen coverage report</a>
          HTML

      - name: Upload Pages artifact
        if: github.event_name != 'pull_request' && hashFiles('pages/coverage/index.html') != ''
        uses: actions/upload-pages-artifact@v3
        with:
          path: pages

      - name: Write summary
        if: always() && hashFiles('coverage/report/index.html') != ''
        run: |
          {
            echo "## Doublcov coverage"
            echo
            if [ "${{ github.event_name }}" = "pull_request" ]; then
              echo "Download and extract the \`doublcov-report\` artifact, then preview it with \`npx @0xdoublesharp/doublcov@0 open coverage/report\`."
            else
              echo "This run also publishes the report to GitHub Pages."
            fi
            echo
            echo "History is restored from and saved to the \`doublcov-history-*\` Actions cache keys."
          } >> "$GITHUB_STEP_SUMMARY"

  pages:
    name: Publish coverage page
    needs: doublcov
    if: github.event_name != 'pull_request'
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}coverage/
    steps:
      - name: Configure Pages
        uses: actions/configure-pages@v5

      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v5

      - name: Write Pages summary
        run: |
          {
            echo "## Published coverage"
            echo
            echo "${{ steps.deployment.outputs.page_url }}coverage/"
          } >> "$GITHUB_STEP_SUMMARY"