From 6ec038d29ac73fee62f0d4cf500cc5c7e99e8baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lex?= Date: Tue, 6 Aug 2024 16:24:13 +0200 Subject: [PATCH] chore: Cleanup CI (#1117) * Standardise names * Update actions versions * Update parameter handling * Split jobs into steps --------- Co-authored-by: kaiserd <1684595+kaiserd@users.noreply.github.com> --- .github/actions/install_nim/action.yml | 4 +- .github/workflows/ci.yml | 65 +++++++------------ .../workflows/{codecov.yml => coverage.yml} | 27 ++++---- .github/workflows/daily.yml | 12 ---- .github/workflows/daily_amd64.yml | 14 ++++ .github/workflows/daily_common.yml | 43 ++++++------ .github/workflows/daily_devel.yml | 14 ++++ .github/workflows/daily_i386.yml | 8 ++- .github/workflows/daily_nim_devel.yml | 12 ---- .../{bumper.yml => dependencies.yml} | 34 ++++++---- .../workflows/{doc.yml => documentation.yml} | 11 ++-- .github/workflows/interop.yml | 3 +- .github/workflows/linters.yml | 32 +++++++++ 13 files changed, 159 insertions(+), 120 deletions(-) rename .github/workflows/{codecov.yml => coverage.yml} (79%) delete mode 100644 .github/workflows/daily.yml create mode 100644 .github/workflows/daily_amd64.yml create mode 100644 .github/workflows/daily_devel.yml delete mode 100644 .github/workflows/daily_nim_devel.yml rename .github/workflows/{bumper.yml => dependencies.yml} (51%) rename .github/workflows/{doc.yml => documentation.yml} (93%) create mode 100644 .github/workflows/linters.yml diff --git a/.github/actions/install_nim/action.yml b/.github/actions/install_nim/action.yml index 1bb49fcb8..83de4f313 100644 --- a/.github/actions/install_nim/action.yml +++ b/.github/actions/install_nim/action.yml @@ -61,7 +61,7 @@ runs: - name: Restore Nim DLLs dependencies (Windows) from cache if: inputs.os == 'Windows' id: windows-dlls-cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: external/dlls key: 'dlls' @@ -114,7 +114,7 @@ runs: - name: Restore Nim from cache id: nim-cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: '${{ github.workspace }}/nim' key: ${{ inputs.os }}-${{ inputs.cpu }}-nim-${{ inputs.nim_branch }}-cache-${{ env.cache_nonce }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 413dc56c7..fcc8ed1cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,5 @@ -name: CI +name: Continuous Integration + on: push: branches: @@ -11,37 +12,41 @@ concurrency: cancel-in-progress: true jobs: - build: + test: timeout-minutes: 90 strategy: fail-fast: false matrix: - target: + platform: - os: linux cpu: amd64 - os: linux cpu: i386 - - os: ubuntu-24-gcc-14 + - os: linux-gcc-14 cpu: amd64 - os: macos cpu: amd64 - os: windows cpu: amd64 - branch: [version-1-6, version-2-0] + nim: + - branch: version-1-6 + memory_management: refc + - branch: version-2-0 + memory_management: refc include: - - target: + - platform: os: linux builder: ubuntu-22.04 shell: bash - - target: - os: ubuntu-24-gcc-14 + - platform: + os: linux-gcc-14 builder: ubuntu-24.04 shell: bash - - target: + - platform: os: macos builder: macos-13 shell: bash - - target: + - platform: os: windows builder: windows-2022 shell: msys2 {0} @@ -50,25 +55,24 @@ jobs: run: shell: ${{ matrix.shell }} - name: '${{ matrix.target.os }}-${{ matrix.target.cpu }} (Nim ${{ matrix.branch }})' + name: '${{ matrix.platform.os }}-${{ matrix.platform.cpu }} (Nim ${{ matrix.nim.branch }})' runs-on: ${{ matrix.builder }} - continue-on-error: ${{ matrix.branch == 'devel' }} steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: submodules: true - name: Setup Nim uses: "./.github/actions/install_nim" with: - os: ${{ matrix.target.os }} - cpu: ${{ matrix.target.cpu }} + os: ${{ matrix.platform.os }} + cpu: ${{ matrix.platform.cpu }} shell: ${{ matrix.shell }} - nim_branch: ${{ matrix.branch }} + nim_branch: ${{ matrix.nim.branch }} - name: Setup Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: go-version: '~1.15.5' @@ -83,7 +87,7 @@ jobs: path: nimbledeps # Using nim.branch as a simple way to differentiate between nimble using the "pkgs" or "pkgs2" directories. # The change happened on Nimble v0.14.0. - key: nimbledeps-${{ matrix.branch }}-${{ hashFiles('.pinned') }} # hashFiles returns a different value on windows + key: nimbledeps-${{ matrix.nim.branch }}-${{ hashFiles('.pinned') }} # hashFiles returns a different value on windows - name: Install deps if: ${{ steps.deps-cache.outputs.cache-hit != 'true' }} @@ -91,7 +95,7 @@ jobs: nimble install_pinned - name: Use gcc 14 - if : ${{ matrix.target.os == 'ubuntu-24-gcc-14'}} + if : ${{ matrix.platform.os == 'linux-gcc-14'}} run: | # Add GCC-14 to alternatives sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 14 @@ -104,26 +108,5 @@ jobs: nim --version nimble --version gcc --version + NIMFLAGS="${NIMFLAGS} --mm:${{ matrix.nim.memory_management }}" nimble test - - lint: - name: "Lint" - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 2 # In PR, has extra merge commit: ^1 = PR, ^2 = base - - - name: Check nph formatting - # Pin nph to a specific version to avoid sudden style differences. - # Updating nph version should be accompanied with running the new - # version on the fluffy directory. - run: | - VERSION="v0.5.1" - ARCHIVE="nph-linux_x64.tar.gz" - curl -L "https://github.com/arnetheduck/nph/releases/download/${VERSION}/${ARCHIVE}" -o ${ARCHIVE} - tar -xzf ${ARCHIVE} - shopt -s extglob # Enable extended globbing - ./nph examples libp2p tests tools *.@(nim|nims|nimble) - git diff --exit-code diff --git a/.github/workflows/codecov.yml b/.github/workflows/coverage.yml similarity index 79% rename from .github/workflows/codecov.yml rename to .github/workflows/coverage.yml index 3c43efacb..062ed8fbc 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/coverage.yml @@ -1,7 +1,7 @@ -name: nim-libp2p codecov builds +name: Coverage on: - #On push to common branches, this computes the "bases stats" for PRs + # On push to common branches, this computes the coverage that PRs will use for diff push: branches: - master @@ -13,12 +13,13 @@ concurrency: cancel-in-progress: true jobs: - Coverage: + codecov: + name: Run coverage and upload to codecov runs-on: ubuntu-22.04 env: CICOV: YES steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 @@ -31,7 +32,7 @@ jobs: - name: Restore deps from cache id: deps-cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: nimbledeps key: nimbledeps-${{ hashFiles('.pinned') }} @@ -41,24 +42,28 @@ jobs: run: | nimble install_pinned - - name: Run + - name: Setup coverage run: | sudo apt-get update sudo apt-get install -y lcov build-essential git curl mkdir coverage + + - name: Run test suite with coverage flags + run: | export NIMFLAGS="--lineDir:on --passC:-fprofile-arcs --passC:-ftest-coverage --passL:-fprofile-arcs --passL:-ftest-coverage" nimble testnative nimble testpubsub nimble testfilter + + - name: Run coverage + run: | find nimcache -name *.c -delete lcov --capture --directory nimcache --output-file coverage/coverage.info shopt -s globstar ls `pwd`/libp2p/{*,**/*}.nim lcov --extract coverage/coverage.info `pwd`/libp2p/{*,**/*}.nim --output-file coverage/coverage.f.info genhtml coverage/coverage.f.info --output-directory coverage/output - bash <(curl -s https://codecov.io/bash) -f coverage/coverage.f.info || echo "Codecov did not collect coverage reports" - #- uses: actions/upload-artifact@master - # with: - # name: coverage - # path: coverage + - name: Upload coverage to codecov + run: | + bash <(curl -s https://codecov.io/bash) -f coverage/coverage.f.info || echo "Codecov did not collect coverage reports" diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml deleted file mode 100644 index 572b0e554..000000000 --- a/.github/workflows/daily.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: Daily -on: - schedule: - - cron: "30 6 * * *" - workflow_dispatch: - -jobs: - call-multi-nim-common: - uses: ./.github/workflows/daily_common.yml - with: - nim-branch: "['version-1-6','version-2-0']" - cpu: "['amd64']" diff --git a/.github/workflows/daily_amd64.yml b/.github/workflows/daily_amd64.yml new file mode 100644 index 000000000..a4031d768 --- /dev/null +++ b/.github/workflows/daily_amd64.yml @@ -0,0 +1,14 @@ +name: Daily amd64 + +on: + schedule: + - cron: "30 6 * * *" + workflow_dispatch: + +jobs: + test_amd64: + name: Daily amd64 + uses: ./.github/workflows/base_daily_tests.yml + with: + nim: "[{'branch': 'version-1-6', 'memory_management': 'refc'}, {'branch': 'version-2-0', 'memory_management': 'refc'}]" + cpu: "['amd64']" diff --git a/.github/workflows/daily_common.yml b/.github/workflows/daily_common.yml index e6a56ae40..0b2e0d619 100644 --- a/.github/workflows/daily_common.yml +++ b/.github/workflows/daily_common.yml @@ -1,12 +1,13 @@ -name: daily-common +name: Daily Common +# Serves as base workflow for daily tasks, it's not run by itself. on: workflow_call: inputs: - nim-branch: - description: 'Nim branch' + nim: + description: 'Nim Configuration' required: true - type: string + type: string # Following this format: [{"branch": ..., "memory_management": ...}, ...] cpu: description: 'CPU' required: true @@ -17,15 +18,20 @@ on: type: string default: "[]" +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + jobs: - delete-cache: + delete_cache: + name: Delete github action's branch cache runs-on: ubuntu-latest steps: - uses: snnaplab/delete-branch-cache-action@v1 - build: - needs: delete-cache - timeout-minutes: 120 + test: + needs: delete_cache + timeout-minutes: 90 strategy: fail-fast: false matrix: @@ -39,7 +45,7 @@ jobs: - os: windows builder: windows-2022 shell: msys2 {0} - branch: ${{ fromJSON(inputs.nim-branch) }} + nim: ${{ fromJSON(inputs.nim) }} cpu: ${{ fromJSON(inputs.cpu) }} exclude: ${{ fromJSON(inputs.exclude) }} @@ -47,9 +53,9 @@ jobs: run: shell: ${{ matrix.platform.shell }} - name: '${{ matrix.platform.os }}-${{ matrix.cpu }} (Nim ${{ matrix.branch }})' + name: '${{ matrix.platform.os }}-${{ matrix.cpu }} (Nim ${{ matrix.nim.branch }})' runs-on: ${{ matrix.platform.builder }} - continue-on-error: ${{ matrix.branch == 'devel' || matrix.branch == 'version-2-0' }} + continue-on-error: ${{ matrix.nim.branch == 'devel' || matrix.nim.branch == 'version-2-0' }} steps: - name: Checkout uses: actions/checkout@v4 @@ -59,11 +65,11 @@ jobs: with: os: ${{ matrix.platform.os }} shell: ${{ matrix.platform.shell }} - nim_branch: ${{ matrix.branch }} + nim_branch: ${{ matrix.nim.branch }} cpu: ${{ matrix.cpu }} - name: Setup Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: '~1.15.5' cache: false @@ -71,14 +77,13 @@ jobs: - name: Install p2pd run: | V=1 bash scripts/build_p2pd.sh p2pdCache 124530a3 + + - name: Install dependencies + run: | + nimble install -y --depsOnly - name: Run tests run: | nim --version nimble --version - nimble install -y --depsOnly - NIMFLAGS="${NIMFLAGS} --mm:refc" nimble test - if [[ "${{ matrix.branch }}" == "devel" ]]; then - echo -e "\nTesting with '--mm:orc':\n" - NIMFLAGS="${NIMFLAGS} --mm:orc" nimble test - fi + NIMFLAGS="${NIMFLAGS} --mm:${{ matrix.nim.memory_management }}" nimble test diff --git a/.github/workflows/daily_devel.yml b/.github/workflows/daily_devel.yml new file mode 100644 index 000000000..391494036 --- /dev/null +++ b/.github/workflows/daily_devel.yml @@ -0,0 +1,14 @@ +name: Daily Nim Devel + +on: + schedule: + - cron: "30 6 * * *" + workflow_dispatch: + +jobs: + test_nim_devel: + name: Daily Nim Devel + uses: ./.github/workflows/base_daily_tests.yml + with: + nim: "[{'branch': 'devel', 'memory_management': 'orc'}]" + cpu: "['amd64']" diff --git a/.github/workflows/daily_i386.yml b/.github/workflows/daily_i386.yml index 23aa07597..649c37b80 100644 --- a/.github/workflows/daily_i386.yml +++ b/.github/workflows/daily_i386.yml @@ -1,13 +1,15 @@ name: Daily i386 + on: schedule: - cron: "30 6 * * *" workflow_dispatch: jobs: - call-multi-nim-common: - uses: ./.github/workflows/daily_common.yml + test_i386: + name: Daily i386 (Linux) + uses: ./.github/workflows/base_daily_tests.yml with: - nim-branch: "['version-1-6','version-2-0', 'devel']" + nim: "[{'branch': 'version-1-6', 'memory_management': 'refc'}, {'branch': 'version-2-0', 'memory_management': 'refc'}, {'branch': 'devel', 'memory_management': 'orc'}]" cpu: "['i386']" exclude: "[{'platform': {'os':'macos'}}, {'platform': {'os':'windows'}}]" diff --git a/.github/workflows/daily_nim_devel.yml b/.github/workflows/daily_nim_devel.yml deleted file mode 100644 index d27ae5f1e..000000000 --- a/.github/workflows/daily_nim_devel.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: Daily Nim Devel -on: - schedule: - - cron: "30 6 * * *" - workflow_dispatch: - -jobs: - call-multi-nim-common: - uses: ./.github/workflows/daily_common.yml - with: - nim-branch: "['devel']" - cpu: "['amd64']" diff --git a/.github/workflows/bumper.yml b/.github/workflows/dependencies.yml similarity index 51% rename from .github/workflows/bumper.yml rename to .github/workflows/dependencies.yml index 14d5026eb..00d97be9b 100644 --- a/.github/workflows/bumper.yml +++ b/.github/workflows/dependencies.yml @@ -1,4 +1,5 @@ -name: Bumper +name: Dependencies + on: push: branches: @@ -6,34 +7,38 @@ on: workflow_dispatch: jobs: - bumpProjects: + bumper: + # Pushes new refs to interested external repositories, so they can do early testing against libp2p's newer versions runs-on: ubuntu-latest + name: Bump libp2p's version for ${{ matrix.target.repository }}:${{ matrix.target.ref }} strategy: fail-fast: false matrix: - target: [ - { repo: status-im/nimbus-eth2, branch: unstable }, - { repo: waku-org/nwaku, branch: master }, - { repo: codex-storage/nim-codex, branch: master } - ] + target: + - repository: status-im/nimbus-eth2 + ref: unstable + - repository: waku-org/nwaku + ref: master + - repository: codex-storage/nim-codex + ref: master steps: - - name: Clone repo - uses: actions/checkout@v2 + - name: Clone target repository + uses: actions/checkout@v4 with: - repository: ${{ matrix.target.repo }} - ref: ${{ matrix.target.branch }} + repository: ${{ matrix.target.repository }} + ref: ${{ matrix.target.ref}} path: nbc fetch-depth: 0 - token: ${{ secrets.ACTIONS_GITHUB_TOKEN }} + token: ${{ secrets.ACTIONS_GITHUB_TOKEN }} - - name: Checkout this ref + - name: Checkout this ref in target repository run: | cd nbc git submodule update --init vendor/nim-libp2p cd vendor/nim-libp2p git checkout $GITHUB_SHA - - name: Commit this bump + - name: Push this ref to target repository run: | cd nbc git config --global user.email "${{ github.actor }}@users.noreply.github.com" @@ -42,3 +47,4 @@ jobs: git branch -D nim-libp2p-auto-bump-${GITHUB_REF##*/} || true git switch -c nim-libp2p-auto-bump-${GITHUB_REF##*/} git push -f origin nim-libp2p-auto-bump-${GITHUB_REF##*/} + diff --git a/.github/workflows/doc.yml b/.github/workflows/documentation.yml similarity index 93% rename from .github/workflows/doc.yml rename to .github/workflows/documentation.yml index 42f6a8837..fd4525509 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/documentation.yml @@ -1,4 +1,5 @@ -name: Docgen +name: Documentation Generation And Publishing + on: push: branches: @@ -14,7 +15,7 @@ jobs: continue-on-error: true steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: submodules: true @@ -34,7 +35,7 @@ jobs: ls ${GITHUB_REF##*/} - name: Clone the gh-pages branch - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: vacp2p/nim-libp2p ref: gh-pages @@ -65,7 +66,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - uses: actions/setup-python@v2 with: @@ -79,7 +80,7 @@ jobs: run: pip install mkdocs-material && nimble -y website - name: Clone the gh-pages branch - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: vacp2p/nim-libp2p ref: gh-pages diff --git a/.github/workflows/interop.yml b/.github/workflows/interop.yml index ecdb6c438..57c5eb05f 100644 --- a/.github/workflows/interop.yml +++ b/.github/workflows/interop.yml @@ -1,4 +1,5 @@ -name: Interoperability Testing +name: Interoperability Tests + on: pull_request: push: diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml new file mode 100644 index 000000000..e572d11cd --- /dev/null +++ b/.github/workflows/linters.yml @@ -0,0 +1,32 @@ +name: Linters + +on: + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + nph: + name: NPH + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 2 # In PR, has extra merge commit: ^1 = PR, ^2 = base + + - name: Setup NPH + # Pin nph to a specific version to avoid sudden style differences. + # Updating nph version should be accompanied with running the new version on the fluffy directory. + run: | + VERSION="v0.5.1" + ARCHIVE="nph-linux_x64.tar.gz" + curl -L "https://github.com/arnetheduck/nph/releases/download/${VERSION}/${ARCHIVE}" -o ${ARCHIVE} + tar -xzf ${ARCHIVE} + + - name: Check style + run: | + shopt -s extglob # Enable extended globbing + ./nph --check examples libp2p tests tools *.@(nim|nims|nimble)