Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
directories:
- "/"
- "/actions/*"
schedule:
interval: "weekly"
cooldown:
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/test-actions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SPDX-FileCopyrightText: SUSE LLC
# SPDX-License-Identifier: Apache-2.0

---
name: Test actions

on:
push:
branches: [main]
paths:
- actions/**
- .github/workflows/test-actions.yaml
pull_request:
paths:
- actions/**
- .github/workflows/test-actions.yaml

permissions:
contents: read

env:
BATS_VERSION: "1.14.0" # https://github.com/bats-core/bats-core/releases

jobs:
test:
name: Lint and test action scripts
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup BATS
uses: bats-core/bats-action@77d6fb60505b4d0d1d73e48bd035b55074bbfb43 # v4.0.0
with:
bats-version: ${{ env.BATS_VERSION }}
- name: Run shellcheck
run: shellcheck actions/*/*.sh
- name: Run bats tests
run: bats actions/*/tests/*.bats
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bats 1.14.0
shellcheck 0.10.0
50 changes: 50 additions & 0 deletions actions/elixir-toolchain/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# SPDX-FileCopyrightText: SUSE LLC
# SPDX-License-Identifier: Apache-2.0

---
name: Compute OTP/Elixir toolchain
description: >-
Read Erlang/OTP and Elixir from `.tool-versions` in the working directory,
and build the toolchain list for an Elixir job matrix.

inputs:
elixir-bc:
description: Elixir version of the backward compatibility toolchain. Required when `bc-enabled` is "true".
required: false
default: ""
erlang-bc:
description: Erlang/OTP version of the backward compatibility toolchain. Required when `bc-enabled` is "true".
required: false
default: ""
bc-enabled:
description: Set to "true" to add the backward compatibility toolchain.
required: false
default: "false"

outputs:
ELIXIR_DEV:
description: Elixir version from `.tool-versions`.
value: ${{ steps.compute.outputs.ELIXIR_DEV }}
ERLANG_DEV:
description: Erlang/OTP version from `.tool-versions`.
value: ${{ steps.compute.outputs.ERLANG_DEV }}
TOOLCHAINS:
description: JSON array of `{elixir, otp}` objects, the backward compatibility toolchain first when enabled.
value: ${{ steps.compute.outputs.TOOLCHAINS }}

runs:
using: composite
steps:
- name: Read .tool-versions
id: parse
uses: endorama/asdf-parse-tool-versions@115a5df5884438dfd08a3a21e9c9efdf06dd907e # v1.7.0
- name: Compute toolchain
id: compute
shell: bash
env:
ELIXIR_VERSION: ${{ fromJson(steps.parse.outputs.tools).elixir }}
ERLANG_VERSION: ${{ fromJson(steps.parse.outputs.tools).erlang }}
ELIXIR_BC: ${{ inputs.elixir-bc }}
ERLANG_BC: ${{ inputs.erlang-bc }}
BC_ENABLED: ${{ inputs.bc-enabled }}
run: '"${{ github.action_path }}/compute-toolchain.sh"'
29 changes: 29 additions & 0 deletions actions/elixir-toolchain/compute-toolchain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

# SPDX-FileCopyrightText: SUSE LLC
# SPDX-License-Identifier: Apache-2.0

set -euo pipefail

if [[ -z "${ELIXIR_VERSION:-}" || -z "${ERLANG_VERSION:-}" ]]; then
echo "::error::.tool-versions must define both elixir and erlang"
exit 1
fi
if [[ "${BC_ENABLED:-}" == "true" && ( -z "${ELIXIR_BC:-}" || -z "${ERLANG_BC:-}" ) ]]; then
echo "::error::bc-enabled requires elixir-bc and erlang-bc"
exit 1
fi
TOOLCHAINS=$(jq -cn \
--arg elixir_bc "${ELIXIR_BC:-}" --arg otp_bc "${ERLANG_BC:-}" \
--arg elixir_dev "$ELIXIR_VERSION" --arg otp_dev "$ERLANG_VERSION" \
--arg bc_enabled "${BC_ENABLED:-}" '
[
{elixir: $elixir_bc, otp: $otp_bc},
{elixir: $elixir_dev, otp: $otp_dev}
]
| if $bc_enabled == "true" then . else .[1:] end')
{
echo "ELIXIR_DEV=$ELIXIR_VERSION"
echo "ERLANG_DEV=$ERLANG_VERSION"
echo "TOOLCHAINS=$TOOLCHAINS"
} >> "$GITHUB_OUTPUT"
82 changes: 82 additions & 0 deletions actions/elixir-toolchain/tests/compute-toolchain.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env bats

# SPDX-FileCopyrightText: SUSE LLC
# SPDX-License-Identifier: Apache-2.0

setup() {
SCRIPT="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)/compute-toolchain.sh"
export GITHUB_OUTPUT="$BATS_TEST_TMPDIR/github_output"
: > "$GITHUB_OUTPUT"
unset ELIXIR_BC ERLANG_BC BC_ENABLED
export ELIXIR_VERSION=1.19.5-otp-27
export ERLANG_VERSION=27.3.4.11
}

DEV='{"elixir":"1.19.5-otp-27","otp":"27.3.4.11"}'
BC='{"elixir":"1.15.7-otp-26","otp":"26.2.1"}'

set_bc() {
export ELIXIR_BC=1.15.7-otp-26
export ERLANG_BC=26.2.1
}

@test "script is executable" {
[ -x "$SCRIPT" ]
}

@test "no BC variables set: dev toolchain only" {
run "$SCRIPT"
[ "$status" -eq 0 ]
[ "$(cat "$GITHUB_OUTPUT")" = "ELIXIR_DEV=1.19.5-otp-27
ERLANG_DEV=27.3.4.11
TOOLCHAINS=[$DEV]" ]
}

@test "BC enabled: BC toolchain first, then dev" {
set_bc
export BC_ENABLED=true
run "$SCRIPT"
[ "$status" -eq 0 ]
grep -qxF "TOOLCHAINS=[$BC,$DEV]" "$GITHUB_OUTPUT"
}

@test "BC versions set, BC disabled: dev toolchain only" {
set_bc
export BC_ENABLED=false
run "$SCRIPT"
[ "$status" -eq 0 ]
grep -qxF "TOOLCHAINS=[$DEV]" "$GITHUB_OUTPUT"
}

@test "BC enabled without elixir-bc: fails" {
set_bc
unset ELIXIR_BC
export BC_ENABLED=true
run "$SCRIPT"
[ "$status" -eq 1 ]
[ "$output" = "::error::bc-enabled requires elixir-bc and erlang-bc" ]
[ ! -s "$GITHUB_OUTPUT" ]
}

@test "BC enabled without erlang-bc: fails" {
set_bc
export ERLANG_BC=""
export BC_ENABLED=true
run "$SCRIPT"
[ "$status" -eq 1 ]
[ "$output" = "::error::bc-enabled requires elixir-bc and erlang-bc" ]
}

@test "no elixir in .tool-versions: fails" {
unset ELIXIR_VERSION
run "$SCRIPT"
[ "$status" -eq 1 ]
[ "$output" = "::error::.tool-versions must define both elixir and erlang" ]
}

@test "no erlang in .tool-versions: fails" {
export ERLANG_VERSION=""
run "$SCRIPT"
[ "$status" -eq 1 ]
[ "$output" = "::error::.tool-versions must define both elixir and erlang" ]
}
73 changes: 73 additions & 0 deletions actions/setup-elixir/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# SPDX-FileCopyrightText: SUSE LLC
# SPDX-License-Identifier: Apache-2.0

---
name: Set up Elixir and restore dependencies
description: >-
Install Erlang/OTP and Elixir, then restore the Elixir dependency cache.
With build-deps, also build the dependencies on a cache miss. The jobs that
build the dependencies and the jobs that use them share this cache key
format. MIX_ENV must be set in the job environment.

inputs:
otp-version:
description: Erlang/OTP version. It is also part of the cache key.
required: true
elixir-version:
description: Elixir version. It is also part of the cache key.
required: true
cache-key-suffix:
description: Extra cache key segment, added after the Elixir version. Empty adds nothing.
required: false
default: ""
setup-beam:
description: Set to "false" to restore the cache without installing Erlang/OTP and Elixir.
required: false
default: "true"
build-deps:
description: >-
Set to "true" to fetch and compile the dependencies, and to build the
Dialyzer PLT when MIX_ENV is not prod, on a cache miss. The cache saves
the result at the end of the job.
required: false
default: "false"

outputs:
cache-hit:
description: '"true" when the cache key matched exactly.'
value: ${{ steps.cache.outputs.cache-hit }}

runs:
using: composite
steps:
- name: Check MIX_ENV
shell: bash
run: '"${{ github.action_path }}/check-mix-env.sh"'
- name: Set up Erlang/OTP and Elixir
if: inputs.setup-beam == 'true'
uses: erlef/setup-beam@54075bcc5e249e4758d363f27d099f55d843f124 # v1.24.1
with:
otp-version: ${{ inputs.otp-version }}
elixir-version: ${{ inputs.elixir-version }}
- name: Restore Elixir dependencies
id: cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
deps
_build/${{ env.MIX_ENV }}
priv/plts
key: erlang-${{ inputs.otp-version }}-elixir-${{ inputs.elixir-version }}${{ inputs.cache-key-suffix != '' && format('-{0}', inputs.cache-key-suffix) || '' }}-${{ hashFiles('mix.lock') }}-${{ env.MIX_ENV }}
- name: Install dependencies
if: inputs.build-deps == 'true' && steps.cache.outputs.cache-hit != 'true'
shell: bash
run: |
mkdir -p priv/plts
mix local.rebar --force
mix local.hex --force
mix deps.get
mix deps.compile --warnings-as-errors
- name: Build Dialyzer PLT
if: inputs.build-deps == 'true' && steps.cache.outputs.cache-hit != 'true' && env.MIX_ENV != 'prod'
shell: bash
run: mix dialyzer --plt
11 changes: 11 additions & 0 deletions actions/setup-elixir/check-mix-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

# SPDX-FileCopyrightText: SUSE LLC
# SPDX-License-Identifier: Apache-2.0

set -euo pipefail

if [[ -z "${MIX_ENV:-}" ]]; then
echo "::error::MIX_ENV must be set in the job environment"
exit 1
fi
32 changes: 32 additions & 0 deletions actions/setup-elixir/tests/check-mix-env.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bats

# SPDX-FileCopyrightText: SUSE LLC
# SPDX-License-Identifier: Apache-2.0

setup() {
SCRIPT="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)/check-mix-env.sh"
unset MIX_ENV
}

@test "script is executable" {
[ -x "$SCRIPT" ]
}

@test "MIX_ENV set: succeeds" {
export MIX_ENV=test
run "$SCRIPT"
[ "$status" -eq 0 ]
[ -z "$output" ]
}

@test "MIX_ENV unset: fails" {
run "$SCRIPT"
[ "$status" -eq 1 ]
[ "$output" = "::error::MIX_ENV must be set in the job environment" ]
}

@test "MIX_ENV empty: fails" {
export MIX_ENV=""
run "$SCRIPT"
[ "$status" -eq 1 ]
}
Loading
Loading