Skip to content

Commit

Permalink
Allow yaml for config and build in info action (#46)
Browse files Browse the repository at this point in the history
* Allow yaml for config and build in info action

* syntax

* simplify

* fix

* typo
  • Loading branch information
ludeeus authored Sep 25, 2021
1 parent 2227acf commit 30d00b3
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 7 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/helpers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,32 @@ jobs:

- name: Verify installation
run: which vcn

info:
runs-on: ubuntu-latest
name: info
strategy:
fail-fast: False
matrix:
file:
- "build"
- "config"
type:
- "json"
- "yaml"

steps:
- name: Check out the repository
uses: actions/checkout@v2

- name: Test
uses: ./helpers/info
id: info
with:
path: "test_files/${{ matrix.file }}_${{ matrix.type }}"

- name: Validate result
run: |
if [[ '${{ steps.info.outputs.architectures }}' != '["aarch64","armv7","armhf","amd64","i386"]' ]]; then
exit 1
fi
23 changes: 16 additions & 7 deletions helpers/info/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,20 @@ runs:
- shell: bash
id: architectures
run: |
if [[ -f "${{ inputs.path }}/build.json" ]]; then
archs=$(jq -r '.build_from | keys | [ .[] | tostring ] | @json' "${{ inputs.path }}/build.json")
elif [[ -f "${{ inputs.path }}/config.json" ]]; then
archs=$(jq -r '.arch | [ .[] | tostring ] | @json' "${{ inputs.path }}/config.json")
else
archs=[]
fi
archs=[]
mkdir -p "${{ github.action_path }}/bin"
wget -q -O "${{ github.action_path }}/bin/yq" https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
chmod a+x "${{ github.action_path }}/bin/yq"
echo "${{ github.action_path }}/bin" >> "$GITHUB_PATH"
for file_type in json yml yaml; do
if [[ -f "${{ inputs.path }}/build.${file_type}" ]]; then
archs=$(yq e -N -M '.build_from | keys' -o=json -I=0 "${{ inputs.path }}/build.${file_type}")
break
elif [[ -f "${{ inputs.path }}/config.${file_type}" ]]; then
archs=$(yq e -N -M '.arch' -o=json -I=0 "${{ inputs.path }}/config.${file_type}")
break
fi
done
echo "::set-output name=architectures::$archs"
9 changes: 9 additions & 0 deletions test_files/build_json/build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"build_from": {
"aarch64": "ghcr.io/home-assistant/aarch64-base:3.13",
"armv7": "ghcr.io/home-assistant/armv7-base:3.13",
"armhf": "ghcr.io/home-assistant/armhf-base:3.13",
"amd64": "ghcr.io/home-assistant/amd64-base:3.13",
"i386": "ghcr.io/home-assistant/i386-base:3.13"
}
}
7 changes: 7 additions & 0 deletions test_files/build_yaml/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
build_from:
aarch64: ghcr.io/home-assistant/aarch64-base:3.13
armv7: ghcr.io/home-assistant/armv7-base:3.13
armhf: ghcr.io/home-assistant/armhf-base:3.13
amd64: ghcr.io/home-assistant/amd64-base:3.13
i386: ghcr.io/home-assistant/i386-base:3.13
3 changes: 3 additions & 0 deletions test_files/config_json/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"arch": ["aarch64","armv7","armhf","amd64","i386"]
}
7 changes: 7 additions & 0 deletions test_files/config_yaml/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
arch:
- aarch64
- armv7
- armhf
- amd64
- i386

0 comments on commit 30d00b3

Please sign in to comment.