Skip to content

Commit

Permalink
Add support for the YAML file format (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck authored Nov 1, 2021
1 parent 72cdbff commit 173a795
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
exit 1;
fi
if [[ "${{ steps.information.outputs.config }}" != "test/config.json" ]]; then
if [[ "${{ steps.information.outputs.config }}" != "test/config.yaml" ]]; then
echo "::error ::'config' does not have the expected value"
exit 1;
fi
Expand Down
52 changes: 39 additions & 13 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,55 +66,77 @@ runs:
if [[ -n "${{ inputs.path }}" ]]; then
path="${{ inputs.path }}"
path="${path%/}"
config="${path}/config.json"
if [[ ! -f "${config}" ]]; then
for config_ext in json yaml yml; do
if [[ -f "${path}/config.${config_ext}" ]]; then
config="${path}/config.${config_ext}"
fi
done
if [[ -z "${config+x}" ]]; then
echo "::error ::Could not find add-on configuration file in ${path}"
exit 1
fi
else
if ! find ./ -mindepth 2 -maxdepth 2 -name "config.json" | grep --silent .; then
if ! find \
./ -mindepth 2 -maxdepth 2 \
-regex ".*\config\.\(json\|yaml\|yml\)$" \
| head -1 | grep --silent .;
then
echo "::error ::Could not find add-on configuration file"
exit 1
fi
config=$(find ./ -mindepth 2 -maxdepth 2 -name "config.json" -printf '%P\n')
config=$(
find ./ -mindepth 2 -maxdepth 2 \
-regex ".*\config\.\(json\|yaml\|yml\)$" -printf '%P\n' \
| head -1
)
fi
echo "::set-output name=config::${config}"
target=$(dirname "${config}")
echo "::set-output name=target::${target}"
if [[ ! -f "${target}/build.json" ]]; then
for config_ext in json yaml yml; do
if [[ -f "${target}/build.${config_ext}" ]]; then
build="${target}/build.${config_ext}"
fi
done
if [[ -z "${build+x}" ]]; then
echo "::error ::Could not find add-on build file"
exit 1
fi
echo "::set-output name=build::${target}/build.json"
echo "::set-output name=build::${build}"
- name: ℹ️ Extract basic add-on information
shell: bash
id: basic
run: |
slug=$(jq --raw-output '.slug' "${{ steps.find.outputs.config }}")
slug=$(yq --no-colors eval '.slug' "${{ steps.find.outputs.config }}")
echo "::set-output name=slug::${slug}"
name=$(jq --raw-output '.name' "${{ steps.find.outputs.config }}")
name=$(yq --no-colors eval '.name' "${{ steps.find.outputs.config }}")
echo "::set-output name=name::${name}"
description=$(jq --raw-output '.description' "${{ steps.find.outputs.config }}")
description=$(yq --no-colors eval '.description' "${{ steps.find.outputs.config }}")
echo "::set-output name=description::${description}"
image=$(jq --raw-output '.image // empty' "${{ steps.find.outputs.config }}")
image=$(yq --no-colors eval '.image // ""' "${{ steps.find.outputs.config }}")
echo "::set-output name=image::${image}"
version=$(jq --raw-output '.version' "${{ steps.find.outputs.config }}")
version=$(yq --no-colors eval '.version' "${{ steps.find.outputs.config }}")
echo "::set-output name=version::${version}"
- name: ℹ️ Extract add-on architecture information
shell: bash
id: architectures
run: |
architectures=$(jq --raw-output --compact-output '.arch | sort' "${{ steps.find.outputs.config }}")
architectures=$(
yq --no-colors --output-format json eval '.arch' "${{ steps.find.outputs.config }}" \
| jq --raw-output --compact-output '. | sort'
)
echo "::set-output name=architectures::${architectures}"
for architecture in \
Expand All @@ -124,6 +146,10 @@ runs:
armv7 \
i386;
do
available=$(jq --raw-output "(.arch | index(\"${architecture}\") // false) != false" "${{ steps.find.outputs.config }}")
available=$(
yq --no-colors eval \
".arch[] | select(. == \"${architecture}\") | . or false" \
"${{ steps.find.outputs.config }}"
)
echo "::set-output name=${architecture}::${available}"
done
8 changes: 0 additions & 8 deletions test/config.json

This file was deleted.

12 changes: 12 additions & 0 deletions test/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: Test Add-on
version: dev
slug: test
description: This is a test add-on
url: https://github.com/frenck/action-addon-information
arch:
- aarch64
- amd64
- armhf
- armv7
- i386

0 comments on commit 173a795

Please sign in to comment.