Skip to content

Commit

Permalink
GitHub Actions: Replace workflows by a single one
Browse files Browse the repository at this point in the history
[Why]
Before, we had the following workflows:
* one to test yamerl
* 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 master branch before
the publish. So if a pull request broke the docs, we would not notice it
before the breakage was in master.

[How]
The new workflow was copied from horus 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 master.
  • Loading branch information
dumbbell committed Jan 29, 2025
1 parent a24f448 commit 2db7fce
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 129 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/docs.yaml

This file was deleted.

137 changes: 137 additions & 0 deletions .github/workflows/test-and-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
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
# TODO: run: rebar3 clean && rebar3 as test dialyzer
run: rebar3 clean && rebar3 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 == 'yakaz/yamerl' && github.ref == 'refs/heads/master'

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 == 'yakaz/yamerl' && (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 }}
52 changes: 52 additions & 0 deletions .github/workflows/test-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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: ['26', '27']
# TODO: os: [ubuntu-latest, windows-latest]
os: [ubuntu-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/yamerl.covertool.xml
flags: erlang-${{ matrix.otp_version }},os-${{ matrix.os }}
name: Erlang/OTP ${{ matrix.otp_version }} on ${{ matrix.os }}
verbose: true # optional (default = false)
63 changes: 0 additions & 63 deletions .github/workflows/test.yaml

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# yamerl: YAML 1.2 and JSON parser in Erlang

[![Build Status](https://travis-ci.org/yakaz/yamerl.svg?branch=master)](https://travis-ci.org/yakaz/yamerl)
[![Coverage Status](https://coveralls.io/repos/github/yakaz/yamerl/badge.svg?branch=master)](https://coveralls.io/github/yakaz/yamerl)
[![Hex version](https://img.shields.io/hexpm/v/yamerl.svg "Hex version")](https://hex.pm/packages/yamerl)
[![Hex.pm](https://img.shields.io/hexpm/v/yamerl)](https://hex.pm/packages/yamerl/)
[![Test](https://github.com/yakaz/yamerl/actions/workflows/test-and-release.yaml/badge.svg)](https://github.com/yakaz/yamerl/actions/workflows/test-and-release.yaml)
[![Codecov](https://codecov.io/gh/yakaz/yamerl/branch/master/graph/badge.svg?token=R0OGKZ2RK2)](https://codecov.io/gh/yakaz/yamerl)

YAML is a human-friendly data serialization format. The specification
for this language and many examples are available from the [Official
Expand Down
15 changes: 11 additions & 4 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

{minimum_otp_vsn, "18.0"}.

{project_plugins, [covertool,
rebar3_hex]}.


{erl_opts, [debug_info,
report,
verbose,
Expand All @@ -14,9 +18,7 @@
warn_untyped_record,
warn_unused_import]}.

%{dialyzer, [{warnings, [race_conditions,
% underspecs,
% unknown,
%{dialyzer, [{warnings, [underspecs,
% unmatched_returns]}]}.

{xref_checks, [undefined_function_calls,
Expand All @@ -26,8 +28,11 @@
deprecated_functions]}.

{cover_enabled, true}.
{cover_opts, [verbose]}.
{cover_print_enabled, true}.
{cover_export_enabled, true}.
{covertool, [{coverdata_files, ["eunit.coverdata",
"ct.coverdata"]}]}.

{alias, [{check, [xref,
{eunit, "-c"},
Expand All @@ -36,5 +41,7 @@
edoc]}]}.

{profiles,
[{test, [{extra_src_dirs, [{"test", [{recursive, true}]}]}]}
[{test, [{extra_src_dirs, [{"test", [{recursive, true}]}]}]},
{dialyzer, [{plt_extra_apps, [common_test,
eunit]}]}
]}.
31 changes: 0 additions & 31 deletions rebar.config.script

This file was deleted.

0 comments on commit 2db7fce

Please sign in to comment.