Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: David Bauer <[email protected]>
  • Loading branch information
blocktrron committed Nov 15, 2023
0 parents commit 3302d15
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 3302d15

Please sign in to comment.