From 1923e0312b248f761324a55b9a07f9a92bd5c626 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Sun, 12 Jul 2020 14:38:29 +1200 Subject: [PATCH] Add github actions (#1125) --- .github/workflows/pull.yaml | 59 ++++++++ .github/workflows/release-dev.yaml | 124 +++++++++++++++++ .github/workflows/release-version.yaml | 180 +++++++++++++++++++++++++ script/setup | 4 +- 4 files changed, 365 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/pull.yaml create mode 100644 .github/workflows/release-dev.yaml create mode 100644 .github/workflows/release-version.yaml diff --git a/.github/workflows/pull.yaml b/.github/workflows/pull.yaml new file mode 100644 index 0000000000..6b66192150 --- /dev/null +++ b/.github/workflows/pull.yaml @@ -0,0 +1,59 @@ +name: PR testing + +on: [pull_request] + +jobs: + lint-custom: + runs-on: ubuntu-latest + container: jesserockz/esphome-lint + name: Lint Custom + steps: + - uses: actions/checkout@v2 + - run: script/setup + - run: script/ci-custom.py + lint-python: + runs-on: ubuntu-latest + container: jesserockz/esphome-lint + name: Lint Python + steps: + - uses: actions/checkout@v2 + - run: script/setup + - run: script/lint-python + lint-tidy: + runs-on: ubuntu-latest + container: jesserockz/esphome-lint + name: Lint Tidy + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - run: script/setup + - run: pio init --ide atom + - run: script/clang-tidy --all-headers --fix + - run: script/ci-suggest-changes + lint-format: + runs-on: ubuntu-latest + container: jesserockz/esphome-lint + name: Lint Format + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - run: script/setup + - run: script/clang-format -i + - run: script/ci-suggest-changes + + test: + runs-on: ubuntu-latest + container: jesserockz/esphome-lint + strategy: + matrix: + test: + - test1 + - test2 + - test3 + - test4 + steps: + - uses: actions/checkout@v2 + - run: script/setup + - run: esphome tests/${{ matrix.test }}.yaml compile diff --git a/.github/workflows/release-dev.yaml b/.github/workflows/release-dev.yaml new file mode 100644 index 0000000000..7f71d79610 --- /dev/null +++ b/.github/workflows/release-dev.yaml @@ -0,0 +1,124 @@ +name: Release dev + +on: + push: + branches: + - dev + +jobs: + lint-custom: + runs-on: ubuntu-latest + container: jesserockz/esphome-lint + name: Lint Custom + steps: + - uses: actions/checkout@v2 + - run: script/setup + - run: script/ci-custom.py + lint-python: + runs-on: ubuntu-latest + container: jesserockz/esphome-lint + name: Lint Python + steps: + - uses: actions/checkout@v2 + - run: script/setup + - run: script/lint-python + lint-tidy: + runs-on: ubuntu-latest + container: jesserockz/esphome-lint + name: Lint Tidy + steps: + - uses: actions/checkout@v2 + - run: script/setup + - run: pio init --ide atom + - run: script/clang-tidy --all-headers --fix + - run: script/ci-suggest-changes + lint-format: + runs-on: ubuntu-latest + container: jesserockz/esphome-lint + name: Lint Format + steps: + - uses: actions/checkout@v2 + - run: script/setup + - run: script/clang-format -i + - run: script/ci-suggest-changes + + test: + runs-on: ubuntu-latest + container: jesserockz/esphome-lint + strategy: + matrix: + test: + - test1 + - test2 + - test3 + - test4 + steps: + - uses: actions/checkout@v2 + - run: script/setup + - run: esphome tests/${{ matrix.test }}.yaml compile + + deploy-docker: + runs-on: ubuntu-latest + needs: [lint-custom, lint-python, lint-tidy, lint-format, test] + strategy: + matrix: + arch: [aarch64, amd64, armv7, i386] + build-type: [hassio, docker] + steps: + - uses: actions/checkout@v2 + - run: docker info + - run: docker login -u "${DOCKER_USER}" -p "${DOCKER_PASSWORD}" + env: + DOCKER_USER: ${{ secrets.DOCKER_USER }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + - run: docker run --rm --privileged multiarch/qemu-user-static:5.0.0-2 --reset -p yes + - env: + BASE_VERSION: 2.1.1 + run: | + if [[ "${{ matrix.build-type }}" == "hassio" ]]; then + BUILD_FROM=esphome/esphome-hassio-base-${{ matrix.arch }}:${BASE_VERSION} + BUILD_TO=${{ github.repository }}-hassio-${{ matrix.arch }} + DOCKERFILE=docker/Dockerfile.hassio + else + BUILD_FROM=esphome/esphome-base-${{ matrix.arch }}:${BASE_VERSION} + BUILD_TO=${{ github.repository }}-${{ matrix.arch }} + DOCKERFILE=docker/Dockerfile + fi + + TAG=${{ github.sha }} + TAG=${TAG:0:7} + + echo "Building tag: ${TAG}" + + docker build \ + --build-arg BUILD_FROM=${BUILD_FROM} \ + --build-arg BUILD_VERSION=${TAG} \ + --tag ${BUILD_TO}:dev \ + --file ${DOCKERFILE} \ + . + + echo "Pushing to ${BUILD_TO}:dev" + docker push ${BUILD_TO}:dev + + deploy-docker-manifest-version: + runs-on: ubuntu-latest + needs: [deploy-docker] + steps: + - run: mkdir -p ~/.docker + - run: | + echo "{\"experimental\": \"enabled\"}" > ~/.docker/config.json + - run: docker login -u "${DOCKER_USER}" -p "${DOCKER_PASSWORD}" + env: + DOCKER_USER: ${{ secrets.DOCKER_USER }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + - run: | + REPO=${{ github.repository }} + + docker manifest create ${REPO}:dev \ + ${REPO}-aarch64:dev \ + ${REPO}-amd64:dev \ + ${REPO}-armv7:dev \ + ${REPO}-i386:dev + + echo "Pushing to ${REPO}:dev" + docker manifest push ${REPO}:dev diff --git a/.github/workflows/release-version.yaml b/.github/workflows/release-version.yaml new file mode 100644 index 0000000000..cb72aae761 --- /dev/null +++ b/.github/workflows/release-version.yaml @@ -0,0 +1,180 @@ +name: Release a version + +on: + push: + tags: + - "*" + +jobs: + lint-custom: + runs-on: ubuntu-latest + container: jesserockz/esphome-lint + name: Lint Custom + steps: + - uses: actions/checkout@v2 + - run: script/setup + - run: script/ci-custom.py + lint-python: + runs-on: ubuntu-latest + container: jesserockz/esphome-lint + name: Lint Python + steps: + - uses: actions/checkout@v2 + - run: script/setup + - run: script/lint-python + lint-tidy: + runs-on: ubuntu-latest + container: jesserockz/esphome-lint + name: Lint Tidy + steps: + - uses: actions/checkout@v2 + - run: script/setup + - run: pio init --ide atom + - run: script/clang-tidy --all-headers --fix + - run: script/ci-suggest-changes + lint-format: + runs-on: ubuntu-latest + container: jesserockz/esphome-lint + name: Lint Format + steps: + - uses: actions/checkout@v2 + - run: script/setup + - run: script/clang-format -i + - run: script/ci-suggest-changes + + test: + runs-on: ubuntu-latest + container: jesserockz/esphome-lint + strategy: + matrix: + test: + - test1 + - test2 + - test3 + - test4 + steps: + - uses: actions/checkout@v2 + - run: script/setup + - run: esphome tests/${{ matrix.test }}.yaml compile + + deploy-pypi: + runs-on: ubuntu-latest + container: jesserockz/esphome-lint + needs: [lint-custom, lint-python, lint-tidy, lint-format, test] + steps: + - run: pip install twine wheel + - run: python setup.py sdist bdist_wheel + - run: twine upload dist/* + env: + TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }} + TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} + + deploy-docker: + runs-on: ubuntu-latest + needs: [lint-custom, lint-python, lint-tidy, lint-format, test] + strategy: + matrix: + arch: [aarch64, amd64, armv7, i386] + build-type: [hassio, docker] + steps: + - uses: actions/checkout@v2 + - run: docker info + - run: docker login -u "${DOCKER_USER}" -p "${DOCKER_PASSWORD}" + env: + DOCKER_USER: ${{ secrets.DOCKER_USER }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + - run: docker run --rm --privileged multiarch/qemu-user-static:5.0.0-2 --reset -p yes + - env: + BASE_VERSION: 2.1.1 + run: | + if [[ "${{ matrix.build-type }}" == "hassio" ]]; then + BUILD_FROM=esphome/esphome-hassio-base-${{ matrix.arch }}:${BASE_VERSION} + BUILD_TO=${{ github.repository }}-hassio-${{ matrix.arch }} + DOCKERFILE=docker/Dockerfile.hassio + else + BUILD_FROM=esphome/esphome-base-${{ matrix.arch }}:${BASE_VERSION} + BUILD_TO=${{ github.repository }}-${{ matrix.arch }} + DOCKERFILE=docker/Dockerfile + fi + + TAG=${{ github.ref }} + TAG=${TAG#refs/tags/v} + + echo "Building tag: ${TAG}" + + docker build \ + --build-arg BUILD_FROM=${BUILD_FROM} \ + --build-arg BUILD_VERSION=${TAG} \ + --tag ${BUILD_TO}:${TAG} \ + --file ${DOCKERFILE} \ + . + + echo "Pushing to ${BUILD_TO}:${TAG}" + docker push ${BUILD_TO}:${TAG} + + beta_tag="^v\d+\.\d+\.\d+b\d+$" + if [[ "${TAG}" ~= "${beta_tag}" ]]; then + echo "Pushing to ${BUILD_TO}:beta" + docker tag ${BUILD_TO}:${TAG} ${BUILD_TO}:beta + docker push ${BUILD_TO}:beta + else + echo "Pushing to ${BUILD_TO}:latest" + docker tag ${BUILD_TO}:${TAG} ${BUILD_TO}:latest + docker push ${BUILD_TO}:latest + fi + + deploy-docker-manifest-version: + runs-on: ubuntu-latest + steps: + - run: mkdir -p ~/.docker + - run: | + echo "{\"experimental\": \"enabled\"}" > ~/.docker/config.json + - run: docker login -u "${DOCKER_USER}" -p "${DOCKER_PASSWORD}" + env: + DOCKER_USER: ${{ secrets.DOCKER_USER }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + - run: | + REPO=${{ github.repository }} + + TAG=${{ github.ref }} + TAG=${TAG#refs/tags/v} + + docker manifest create ${REPO}:${TAG} \ + ${REPO}-aarch64:${TAG} \ + ${REPO}-amd64:${TAG} \ + ${REPO}-armv7:${TAG} \ + ${REPO}-i386:${TAG} + + echo "Pushing to ${REPO}:${TAG}" + docker push ${REPO}:${TAG} + + deploy-docker-manifest: + runs-on: ubuntu-latest + steps: + - run: mkdir -p ~/.docker + - run: | + echo "{\"experimental\": \"enabled\"}" > ~/.docker/config.json + - run: docker login -u "${DOCKER_USER}" -p "${DOCKER_PASSWORD}" + env: + DOCKER_USER: ${{ secrets.DOCKER_USER }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + - run: | + REPO=${{ github.repository }} + + TAG=${{ github.ref }} + TAG=${TAG#refs/tags/v} + + beta_tag="^v\d+\.\d+\.\d+b\d+$" + if [[ "${TAG}" ~= "${beta_tag}" ]]; then + TAG=beta + else + TAG=latest + fi + docker manifest create ${REPO}:${TAG} \ + ${REPO}-aarch64:${TAG} \ + ${REPO}-amd64:${TAG} \ + ${REPO}-armv7:${TAG} \ + ${REPO}-i386:${TAG} + + echo "Pushing to ${REPO}:${TAG}" + docker push ${REPO}:${TAG} diff --git a/script/setup b/script/setup index b6cff39f0c..810fb2a2bf 100755 --- a/script/setup +++ b/script/setup @@ -4,5 +4,5 @@ set -e cd "$(dirname "$0")/.." -pip install -r requirements_test.txt -pip install -e . +pip3 install -r requirements_test.txt +pip3 install -e .