diff --git a/.github/workflows/helpers.yml b/.github/workflows/helpers.yml index 18f7f13..cd62bda 100644 --- a/.github/workflows/helpers.yml +++ b/.github/workflows/helpers.yml @@ -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 \ No newline at end of file diff --git a/helpers/info/action.yml b/helpers/info/action.yml index c0f9efd..83c1cc0 100644 --- a/helpers/info/action.yml +++ b/helpers/info/action.yml @@ -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" diff --git a/test_files/build_json/build.json b/test_files/build_json/build.json new file mode 100644 index 0000000..c75bfd3 --- /dev/null +++ b/test_files/build_json/build.json @@ -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" + } + } \ No newline at end of file diff --git a/test_files/build_yaml/build.yaml b/test_files/build_yaml/build.yaml new file mode 100644 index 0000000..a288d92 --- /dev/null +++ b/test_files/build_yaml/build.yaml @@ -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 diff --git a/test_files/config_json/config.json b/test_files/config_json/config.json new file mode 100644 index 0000000..fc400a5 --- /dev/null +++ b/test_files/config_json/config.json @@ -0,0 +1,3 @@ +{ + "arch": ["aarch64","armv7","armhf","amd64","i386"] +} \ No newline at end of file diff --git a/test_files/config_yaml/config.yaml b/test_files/config_yaml/config.yaml new file mode 100644 index 0000000..40af1e9 --- /dev/null +++ b/test_files/config_yaml/config.yaml @@ -0,0 +1,7 @@ +--- +arch: + - aarch64 + - armv7 + - armhf + - amd64 + - i386 \ No newline at end of file