From bf8e973c08214a36650d1346c9a833fd1097e6b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Date: Mon, 28 Oct 2024 17:51:32 +0100 Subject: [PATCH 1/2] Docs: Use rebar3_edoc_extensions 1.6.1 It fixes the build of the docs with Erlang/OTP 27.1. --- rebar.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rebar.config b/rebar.config index 32083e3..ce22cff 100644 --- a/rebar.config +++ b/rebar.config @@ -5,7 +5,7 @@ {project_plugins, [covertool, rebar3_hex, - {rebar3_edoc_extensions, "1.6.0"}]}. + {rebar3_edoc_extensions, "1.6.1"}]}. {erl_opts, [debug_info, warn_export_vars, From 97b488c6dea785d4b28b044b6fc2fb03bdd5f7fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Date: Mon, 28 Oct 2024 17:32:53 +0100 Subject: [PATCH 2/2] GitHub Actions: Replace workflows by a single one [Why] Before, we had the following workflows: * one to test Horus * one to generage and publish docs * one to publish a release to Hex.pm One problem was that the docs and the release workflows didn't depend on the test results. Another one was that the docs was only built for the main branch before the publish. So if a pull request broke the docs, we would not notice it before the breakage was in main. [How] The new workflow was copied from Khepri where the initial work happened. All workflows are combined into a single workflow with the correct dependencies. Also, the docs are always generated regardless of the branch and published only it is main. --- .github/workflows/docs.yaml | 31 ------ .github/workflows/release.yaml | 26 ----- .github/workflows/test-and-release.yaml | 136 ++++++++++++++++++++++++ .github/workflows/test-job.yaml | 51 +++++++++ .github/workflows/test.yaml | 65 ----------- 5 files changed, 187 insertions(+), 122 deletions(-) delete mode 100644 .github/workflows/docs.yaml delete mode 100644 .github/workflows/release.yaml create mode 100644 .github/workflows/test-and-release.yaml create mode 100644 .github/workflows/test-job.yaml delete mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml deleted file mode 100644 index 54bcee3..0000000 --- a/.github/workflows/docs.yaml +++ /dev/null @@ -1,31 +0,0 @@ -name: Documentation - -on: - push: - branches: - - 'main' - -jobs: - Documentation: - name: Generate and publish documentation - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - uses: erlef/setup-beam@v1 - with: - otp-version: 27 - rebar3-version: '3.23.0' - - - name: Change doc version to "Development branch" - run: sed -E -i -e 's/^@version.*/@version Development branch/' doc/overview.edoc - - - name: Generate - run: rebar3 edoc - - - name: Publish - uses: peaceiris/actions-gh-pages@v4 - if: ${{ github.ref == 'refs/heads/main' }} - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./doc diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index c59b9a7..0000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,26 +0,0 @@ -name: Publish release - -on: - push: - tags: - - v0* - - v1* - - v2* - - v3* - - v4* - - v5* - - v6* - - v7* - - v8* - - v9* - -jobs: - Publish: - name: Publish release - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Publish to Hex.pm - uses: erlangpack/github-action@v3 - env: - HEX_API_KEY: ${{ secrets.HEX_API_KEY }} diff --git a/.github/workflows/test-and-release.yaml b/.github/workflows/test-and-release.yaml new file mode 100644 index 0000000..1333164 --- /dev/null +++ b/.github/workflows/test-and-release.yaml @@ -0,0 +1,136 @@ +name: Test → Docs → Release + +on: + - pull_request + - push + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +env: + REBAR_VERSION: '3.23.0' + LATEST_ERLANG_VERSION: '27' + +jobs: + # `env_to_output` works around a limitation of GitHub Actions that prevents + # the use of environment variables in places such as a workflow call's `with` + # arguments. + # + # https://github.com/actions/runner/issues/1189#issuecomment-1832389701 + env_to_output: + name: Env. variable to outputs + runs-on: ubuntu-latest + outputs: + REBAR_VERSION: ${{ steps.from_env.outputs.REBAR_VERSION }} + steps: + - id: from_env + run: | + vars=" + REBAR_VERSION + " + setOutput() { + echo "${1}=${!1}" >> "${GITHUB_OUTPUT}" + } + for name in $vars; do + setOutput $name + done + + test: + name: Test + needs: env_to_output + uses: ./.github/workflows/test-job.yaml + with: + rebar_version: ${{ needs.env_to_output.outputs.REBAR_VERSION }} + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + + dialyzer: + name: Dialyzer + runs-on: ubuntu-latest + needs: env_to_output + + steps: + - uses: actions/checkout@v4 + - uses: erlef/setup-beam@v1 + id: install-erlang + with: + otp-version: ${{ env.LATEST_ERLANG_VERSION }} + rebar3-version: ${{ env.REBAR_VERSION }} + + - name: Restore Dialyzer PLT files from cache + uses: actions/cache@v4 + with: + path: _build/*/rebar3_*_plt + key: dialyzer-plt-cache-${{ steps.install-erlang.outputs.otp-version }}-${{ runner.os }}-${{ hashFiles('rebar.config*') }}-v1 + + - name: Dialyzer + run: rebar3 clean && rebar3 as test dialyzer + + build_docs: + name: Generate docs + runs-on: ubuntu-latest + needs: + - test + - dialyzer + + steps: + - uses: actions/checkout@v4 + - uses: erlef/setup-beam@v1 + with: + otp-version: ${{ env.LATEST_ERLANG_VERSION }} + rebar3-version: ${{ env.REBAR_VERSION }} + + - name: Change doc version to "Development branch" + run: sed -E -i -e 's/^@version.*/@version Development branch/' doc/overview.edoc + + - name: Generate + run: rebar3 edoc + + - name: Ensure HTML files are there + run: ls -l doc && test -f doc/index.html + + - name: Upload docs for next job + uses: actions/upload-artifact@v4 + with: + name: docs_dir + path: ./doc + if-no-files-found: error + + publish_docs: + name: Publish docs + runs-on: ubuntu-latest + needs: build_docs + if: github.repository == 'rabbitmq/horus' && github.ref == 'refs/heads/main' + + steps: + - name: Download docs from previous job + uses: actions/download-artifact@v4 + with: + name: docs_dir + path: ./doc + + - name: Ensure HTML files are there + run: ls -l doc && test -f doc/index.html + + - name: Publish + uses: peaceiris/actions-gh-pages@v4 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./doc + + publish_release: + name: Publish release + runs-on: ubuntu-latest + needs: + - test + - dialyzer + - build_docs + if: github.repository == 'rabbitmq/horus' && (startsWith(github.ref, 'refs/tags/v0') || startsWith(github.ref, 'refs/tags/v1') || startsWith(github.ref, 'refs/tags/v2') || startsWith(github.ref, 'refs/tags/v3') || startsWith(github.ref, 'refs/tags/v4') || startsWith(github.ref, 'refs/tags/v5') || startsWith(github.ref, 'refs/tags/v6') || startsWith(github.ref, 'refs/tags/v7') || startsWith(github.ref, 'refs/tags/v8') || startsWith(github.ref, 'refs/tags/v9')) + + steps: + - uses: actions/checkout@v4 + - name: Publish to Hex.pm + uses: erlangpack/github-action@v3 + env: + HEX_API_KEY: ${{ secrets.HEX_API_KEY }} diff --git a/.github/workflows/test-job.yaml b/.github/workflows/test-job.yaml new file mode 100644 index 0000000..7e7bbfa --- /dev/null +++ b/.github/workflows/test-job.yaml @@ -0,0 +1,51 @@ +name: Single test job + +on: + workflow_call: + inputs: + rebar_version: + required: true + type: string + secrets: + CODECOV_TOKEN: + required: true + +jobs: + test: + name: "Erlang/OTP ${{ matrix.otp_version }} + ${{ matrix.os }}" + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + otp_version: ['25', '26', '27'] + os: [ubuntu-latest, windows-latest] + + steps: + - uses: actions/checkout@v4 + - uses: erlef/setup-beam@v1 + id: install-erlang + with: + otp-version: ${{ matrix.otp_version }} + rebar3-version: ${{ inputs.rebar_version }} + + - name: Compile + run: rebar3 compile + + - name: Xref + run: rebar3 xref + - name: EUnit (unit tests) + run: env ERL_FLAGS='-enable-feature maybe_expr' rebar3 eunit --verbose --cover + - name: Common test (integration tests) + run: rebar3 ct --verbose --cover --sname ct + + - name: Generate code coverage report + run: rebar3 as test covertool generate + + - name: Upload code coverage to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: _build/test/covertool/horus.covertool.xml + flags: erlang-${{ matrix.otp_version }},os-${{ matrix.os }} + name: Erlang/OTP ${{ matrix.otp_version }} on ${{ matrix.os }} + verbose: true # optional (default = false) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml deleted file mode 100644 index 583659b..0000000 --- a/.github/workflows/test.yaml +++ /dev/null @@ -1,65 +0,0 @@ -name: Test - -on: - - pull_request - - push - -jobs: - Test: - name: Test on Erlang/OTP ${{ matrix.otp_version }} and ${{ matrix.os }} - runs-on: ${{ matrix.os }} - - strategy: - matrix: - otp_version: [24, 25, 26, 27] - os: [ubuntu-latest, windows-latest] - exclude: - # `ct_slave` fails to start Erlang nodes on Windows with Erlang 24. - - otp_version: 24 - os: windows-latest - # setup-beam currently hangs for 30+ minutes for Windows builds and - # Erlang/OTP 26.0. - - otp_version: 26 - os: windows-latest - - env: - RUN_DIALYZER_ON_OTP_RELEASE: 27 - - steps: - - uses: actions/checkout@v4 - - uses: erlef/setup-beam@v1 - id: install-erlang - with: - otp-version: ${{matrix.otp_version}} - rebar3-version: '3.23.0' - - - name: Restore Dialyzer PLT files from cache - uses: actions/cache@v4 - if: ${{ matrix.otp_version == env.RUN_DIALYZER_ON_OTP_RELEASE && matrix.os == 'ubuntu-latest' }} - with: - path: _build/*/rebar3_*_plt - key: dialyzer-plt-cache-${{ steps.install-erlang.outputs.otp-version }}-${{ runner.os }}-${{ hashFiles('rebar.config*') }}-v1 - - - name: Compile - run: rebar3 compile - - - name: Xref - run: rebar3 xref - - name: EUnit (unit tests) - run: env ERL_FLAGS='-enable-feature maybe_expr' rebar3 eunit --verbose --cover - - - name: Dialyzer - if: ${{ matrix.otp_version == env.RUN_DIALYZER_ON_OTP_RELEASE && matrix.os == 'ubuntu-latest' }} - run: rebar3 clean && rebar3 as test dialyzer - - - name: Generate code coverage report - run: rebar3 as test covertool generate - - - name: Upload code coverage to Codecov - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: _build/test/covertool/horus.covertool.xml - flags: erlang-${{ matrix.otp_version }},os-${{ matrix.os }} - name: Erlang/OTP ${{ matrix.otp_version }} on ${{ matrix.os }} - verbose: true # optional (default = false)