|
| 1 | +--- |
| 2 | +name: CI |
| 3 | + |
| 4 | +# yamllint disable-line rule:truthy |
| 5 | +on: |
| 6 | + push: |
| 7 | + pull_request: |
| 8 | + types: |
| 9 | + - opened |
| 10 | + - reopened |
| 11 | + - synchronize |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +jobs: |
| 15 | + information: |
| 16 | + name: Gather add-on information |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + architectures: ${{ steps.information.outputs.architectures }} |
| 20 | + build: ${{ steps.information.outputs.build }} |
| 21 | + description: ${{ steps.information.outputs.description }} |
| 22 | + name: ${{ steps.information.outputs.name }} |
| 23 | + slug: ${{ steps.information.outputs.slug }} |
| 24 | + target: ${{ steps.information.outputs.target }} |
| 25 | + steps: |
| 26 | + - name: ⤵️ Check out code from GitHub |
| 27 | + uses: actions/checkout@v2.3.4 |
| 28 | + - name: 🚀 Run add-on information action |
| 29 | + id: information |
| 30 | + uses: frenck/action-addon-information@v1.0.0 |
| 31 | + |
| 32 | + lint-addon: |
| 33 | + name: Lint Add-on |
| 34 | + needs: |
| 35 | + - information |
| 36 | + runs-on: ubuntu-latest |
| 37 | + steps: |
| 38 | + - name: ⤵️ Check out code from GitHub |
| 39 | + uses: actions/checkout@v2.3.4 |
| 40 | + - name: 🚀 Run Add-on Lint |
| 41 | + uses: frenck/action-addon-linter@v1.3.1 |
| 42 | + with: |
| 43 | + community: true |
| 44 | + path: "./${{ needs.information.outputs.target }}" |
| 45 | + |
| 46 | + lint-hadolint: |
| 47 | + name: Hadolint |
| 48 | + needs: |
| 49 | + - information |
| 50 | + runs-on: ubuntu-latest |
| 51 | + steps: |
| 52 | + - name: ⤵️ Check out code from GitHub |
| 53 | + uses: actions/checkout@v2.3.4 |
| 54 | + - name: 🚀 Run Hadolint |
| 55 | + uses: brpaz/hadolint-action@v1.3.1 |
| 56 | + with: |
| 57 | + dockerfile: "./${{ needs.information.outputs.target }}/Dockerfile" |
| 58 | + |
| 59 | + lint-json: |
| 60 | + name: JSON Lint |
| 61 | + runs-on: ubuntu-latest |
| 62 | + steps: |
| 63 | + - name: ⤵️ Check out code from GitHub |
| 64 | + uses: actions/checkout@v2.3.4 |
| 65 | + - name: 🚀 Run JQ |
| 66 | + run: | |
| 67 | + shopt -s globstar |
| 68 | + cat **/*.json | jq '.' |
| 69 | +
|
| 70 | + lint-markdown: |
| 71 | + name: MarkdownLint |
| 72 | + runs-on: ubuntu-latest |
| 73 | + steps: |
| 74 | + - name: ⤵️ Check out code from GitHub |
| 75 | + uses: actions/checkout@v2.3.4 |
| 76 | + - name: 🚀 Run mdl |
| 77 | + uses: actionshub/markdownlint@2.0.0 |
| 78 | + |
| 79 | + lint-shellcheck: |
| 80 | + name: Shellcheck |
| 81 | + runs-on: ubuntu-latest |
| 82 | + steps: |
| 83 | + - name: ⤵️ Check out code from GitHub |
| 84 | + uses: actions/checkout@v2.3.4 |
| 85 | + - name: 🚀 Run Shellcheck |
| 86 | + uses: ludeeus/action-shellcheck@1.0.0 |
| 87 | + env: |
| 88 | + SHELLCHECK_OPTS: -s bash |
| 89 | + |
| 90 | + lint-yamllint: |
| 91 | + name: YAMLLint |
| 92 | + runs-on: ubuntu-latest |
| 93 | + steps: |
| 94 | + - name: ⤵️ Check out code from GitHub |
| 95 | + uses: actions/checkout@v2.3.4 |
| 96 | + - name: 🚀 Run YAMLLint |
| 97 | + uses: frenck/action-yamllint@v1.0.2 |
| 98 | + |
| 99 | + lint-prettier: |
| 100 | + name: Prettier |
| 101 | + runs-on: ubuntu-latest |
| 102 | + steps: |
| 103 | + - name: ⤵️ Check out code from GitHub |
| 104 | + uses: actions/checkout@v2.3.4 |
| 105 | + - name: 🚀 Run Prettier |
| 106 | + uses: creyD/prettier_action@v3.3 |
| 107 | + with: |
| 108 | + prettier_options: --write **/*.{json,js,md,yaml} |
| 109 | + env: |
| 110 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 111 | + |
| 112 | + build: |
| 113 | + name: Build ${{ matrix.architecture }} |
| 114 | + needs: |
| 115 | + - information |
| 116 | + - lint-addon |
| 117 | + - lint-hadolint |
| 118 | + - lint-json |
| 119 | + - lint-markdown |
| 120 | + - lint-prettier |
| 121 | + - lint-shellcheck |
| 122 | + - lint-yamllint |
| 123 | + runs-on: ubuntu-latest |
| 124 | + strategy: |
| 125 | + matrix: |
| 126 | + architecture: ${{ fromJson(needs.information.outputs.architectures) }} |
| 127 | + steps: |
| 128 | + - name: ⤵️ Check out code from GitHub |
| 129 | + uses: actions/checkout@v2.3.4 |
| 130 | + - name: 🏗 Set up build cache |
| 131 | + id: cache |
| 132 | + uses: actions/cache@v2.1.3 |
| 133 | + with: |
| 134 | + path: /tmp/.docker-cache |
| 135 | + key: docker-${{ github.ref }}-${{ matrix.architecture }}-${{ github.sha }} |
| 136 | + restore-keys: | |
| 137 | + docker-${{ github.ref }}-${{ matrix.architecture }} |
| 138 | + - name: 🏗 Set up QEMU |
| 139 | + uses: docker/setup-qemu-action@v1.0.1 |
| 140 | + - name: 🏗 Set up Docker Buildx |
| 141 | + uses: docker/setup-buildx-action@v1.1.1 |
| 142 | + - name: ℹ️ Compose build flags |
| 143 | + id: flags |
| 144 | + run: | |
| 145 | + echo "::set-output name=date::$(date +"%Y-%m-%dT%H:%M:%SZ")" |
| 146 | + from=$(jq --raw-output ".build_from.${{ matrix.architecture }}" "${{ needs.information.outputs.build }}") |
| 147 | + echo "::set-output name=from::${from}" |
| 148 | +
|
| 149 | + if [[ "${{ matrix.architecture}}" = "amd64" ]]; then |
| 150 | + echo "::set-output name=platform::linux/amd64" |
| 151 | + elif [[ "${{ matrix.architecture }}" = "i386" ]]; then |
| 152 | + echo "::set-output name=platform::linux/386" |
| 153 | + elif [[ "${{ matrix.architecture }}" = "armhf" ]]; then |
| 154 | + echo "::set-output name=platform::linux/arm/v6" |
| 155 | + elif [[ "${{ matrix.architecture }}" = "armv7" ]]; then |
| 156 | + echo "::set-output name=platform::linux/arm/v7" |
| 157 | + elif [[ "${{ matrix.architecture }}" = "aarch64" ]]; then |
| 158 | + echo "::set-output name=platform::linux/arm64/v8" |
| 159 | + else |
| 160 | + echo "::error ::Could not determine platform for architecture ${{ matrix.architecture }}" |
| 161 | + exit 1 |
| 162 | + fi |
| 163 | + - name: 🚀 Build |
| 164 | + uses: docker/build-push-action@v2.2.2 |
| 165 | + with: |
| 166 | + push: false |
| 167 | + context: ${{ needs.information.outputs.target }} |
| 168 | + file: ${{ needs.information.outputs.target }}/Dockerfile |
| 169 | + cache-from: | |
| 170 | + type=local,src=/tmp/.docker-cache |
| 171 | + ghcr.io/hassio-addons/${{ needs.information.outputs.slug }}/${{ matrix.architecture }}:edge |
| 172 | + cache-to: type=local,mode=max,dest=/tmp/.docker-cache |
| 173 | + platforms: ${{ steps.flags.outputs.platform }} |
| 174 | + build-args: | |
| 175 | + BUILD_ARCH=${{ matrix.architecture }} |
| 176 | + BUILD_DATE=${{ steps.flags.outputs.date }} |
| 177 | + BUILD_DESCRIPTION=${{ needs.information.outputs.description }} |
| 178 | + BUILD_FROM=${{ steps.flags.outputs.from }} |
| 179 | + BUILD_NAME=${{ needs.information.outputs.name }} |
| 180 | + BUILD_REF=${{ github.sha }} |
| 181 | + BUILD_REPOSITORY=${{ github.repository }} |
| 182 | + BUILD_VERSION=edge |
0 commit comments