From 3302d1590f9e4c4d6a68913a762c0e444fccc700 Mon Sep 17 00:00:00 2001 From: David Bauer Date: Wed, 15 Nov 2023 19:29:13 +0100 Subject: [PATCH] initial commit Signed-off-by: David Bauer --- .github/workflows/lint.yml | 32 ++++++++++++++++++++++++++++++++ README.md | 33 +++++++++++++++++++++++++++++++++ action.yml | 35 +++++++++++++++++++++++++++++++++++ entrypoint.sh | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 .github/workflows/lint.yml create mode 100644 README.md create mode 100644 action.yml create mode 100755 entrypoint.sh diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..787c08c --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,32 @@ +--- +name: "Lint" + +# yamllint disable-line rule:truthy +on: [push, pull_request] + +jobs: + lint-yaml: + name: "YAML" + runs-on: ubuntu-22.04 + env: + YAML_FILES: | + .github/workflows/lint.yml + action.yml + steps: + - uses: actions/checkout@v4 + - name: Install Dependencies + run: sudo apt-get update && sudo apt-get install -y yamllint shellcheck + - name: Validate YAML Files + run: yamllint $YAML_FILES + + shellcheck: + name: "Shell Scripts" + runs-on: ubuntu-22.04 + env: + SHELL_FILES: entrypoint.sh + steps: + - uses: actions/checkout@v4 + - name: Install Dependencies + run: sudo apt-get update && sudo apt-get install -y shellcheck + - name: Validate Shell Scripts + run: shellcheck $SHELL_FILES diff --git a/README.md b/README.md new file mode 100644 index 0000000..418e534 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# action-target-list + +This Action allows to obtain a list of targets available for a +given Gluon release. + +The target-list is returned as a JSON, so it can be used with +a matrix-strategy for building multiple concurrent targets +in a CI. + + +## Inputs + +### gluon-path +Path to a checked-out Gluon repository. + +### allowlist +Space-separated list of targets which are allowed in the output list. + +Any target not present in this list won't occur in the output list. + +### denylist +Space-separated list of targets which are not allowed in the output list. + +Any target present in this list won't occur in the output list. + +### broken +Whether or not to include targets marked as `BROKEN` in the output list. + + +## Outputs + +### targets +JSON list containing all valid targets diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..c67b353 --- /dev/null +++ b/action.yml @@ -0,0 +1,35 @@ +--- +name: 'Get list of available targets for Gluon release' +description: 'Returns targets available in a specified Gluon release' +inputs: + gluon-path: + description: 'Path to Gluon repository' + required: true + allowlist: + description: 'Space-separated list of targets to be returned if available' + required: false + denylist: + description: | + 'Space-separated list of targets to be excluded from the result' + required: false + broken: + description: 'Determines if BROKEN targets should be returned (Default: 0)' + default: 0 +outputs: + targets: + description: 'JSON list containing all valid targets' + value: ${{ steps.save-step.outputs.targets }} +runs: + using: 'composite' + steps: + - run: > + bash ${{ github.action_path }}/entrypoint.sh + ${{ inputs.gluon-path }} > /tmp/targets.json + shell: bash + env: + ALLOWLIST: ${{ inputs.allowlist }} + DENYLIST: ${{ inputs.denylist }} + BROKEN: ${{ inputs.broken }} + - run: echo "targets=$(cat /tmp/targets.json)" >> "$GITHUB_OUTPUT" + shell: bash + id: save-step diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..7fde83d --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +set -euxo pipefail + +GLUON_PATH="$1" + +ALLOWLIST="${ALLOWLIST:-}" +DENYLIST="${DENYLIST:-}" +BROKEN="${BROKEN:0}" + +# Get List of available Targets +AVAILABLE_TARGETS_NEWLINE="$(make --no-print-directory -C "$GLUON_PATH" list-targets "BROKEN=${BROKEN}" "GLUON_SITEDIR=docs/site-example")" + +# Format Allow- and Denylist +TARGET_ALLOWLIST_NEWLINE="$(echo "$ALLOWLIST" | tr ' ' '\n')" +TARGET_DENYLIST_NEWLINE="$(echo "$DENYLIST" | tr ' ' '\n')" + +# Return all available targets if no allowlist is set +OUTPUT_TARGETS="${AVAILABLE_TARGETS_NEWLINE}" + +if [ -n "$ALLOWLIST" ]; then + # Only return words present in both lists + OUTPUT_TARGETS="$(echo -e "$AVAILABLE_TARGETS_NEWLINE\n$TARGET_ALLOWLIST_NEWLINE" | sort | uniq -d)" +fi + +if [ -n "$DENYLIST" ]; then + # Remove words present in denylist + OUTPUT_TARGETS="$(echo -e "$OUTPUT_TARGETS\n$TARGET_DENYLIST_NEWLINE" | sort | uniq -u)" +fi + +# Convert to JSON +OUTPUT_JSON="$(echo "$OUTPUT_TARGETS" | jq --raw-input . | jq --slurp . | jq -c .)" + +echo "$OUTPUT_JSON"