Add BetweenIntervalTriggerEvent and handle intermediate triggers (#395) #2085
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: build-project | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: main | |
| release: | |
| types: [published] | |
| env: | |
| REGISTRY_GITHUB: ghcr.io | |
| jobs: | |
| variables: | |
| outputs: | |
| ref_name: ${{ steps.var.outputs.ref_name}} | |
| image_name: ${{ steps.var.outputs.image_name }} | |
| ghcr_image: ${{ steps.var.outputs.ghcr_image }} | |
| version: ${{ steps.var.outputs.version }} | |
| runs-on: "ubuntu-latest" | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Setting global variables | |
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 | |
| id: var | |
| with: | |
| script: | | |
| const refName = '${{ github.ref_name || github.event.release.tag_name }}'; | |
| core.setOutput('ref_name', refName.toLowerCase().replaceAll(/[/.]/g, '-').trim('-')); | |
| core.setOutput('image_name', '${{ github.repository }}'.toLowerCase()); | |
| core.setOutput('ghcr_image', '${{ env.REGISTRY_GITHUB }}/${{ github.repository }}'.toLowerCase()); | |
| const version = refName.replace(/^v/, ''); | |
| core.setOutput('version', version); | |
| build-check: | |
| runs-on: ubuntu-latest | |
| needs: [variables] | |
| env: | |
| REF_NAME: ${{ needs.variables.outputs.ref_name }} | |
| permissions: | |
| id-token: write | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python 3.13 | |
| uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 | |
| with: | |
| python-version: "3.13" | |
| - name: Cache Python packages | |
| uses: actions/cache@2c8a9bd7457de244a408f35966fab2fb45fda9c8 | |
| with: | |
| path: | | |
| ~/.cache/pip | |
| !~/.cache/pip/log | |
| key: ${{ runner.os }}-python-3.13-pip-${{ hashFiles('**/requirements.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-python-3.13-pip- | |
| ${{ runner.os }}-python-3.13- | |
| ${{ runner.os }}-python- | |
| ${{ runner.os }}-pip- | |
| - name: Install build package | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build | |
| - name: Install package with dev dependencies | |
| run: pip install -e ".[dev,forecast]" | |
| - name: Get changed Python files | |
| id: changed-py-files | |
| run: | | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| FILES=$(git diff --name-only --diff-filter=ACMRT "origin/${{ github.base_ref }}...HEAD" -- '*.py' | tr '\n' ' ') | |
| elif [ "${{ github.event_name }}" = "push" ] && \ | |
| [ "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]; then | |
| FILES=$(git diff --name-only --diff-filter=ACMRT "${{ github.event.before }}" "${{ github.sha }}" -- '*.py' | tr '\n' ' ') | |
| fi | |
| echo "files=$(echo "$FILES" | xargs)" >> $GITHUB_OUTPUT | |
| - name: Lint with ruff | |
| run: | | |
| FILES="${{ steps.changed-py-files.outputs.files }}" | |
| ruff check ${FILES:-.} | |
| - name: Type check with pyright | |
| run: | | |
| FILES="${{ steps.changed-py-files.outputs.files }}" | |
| if [ -z "$FILES" ]; then | |
| pyright | |
| else | |
| pyright $FILES | |
| fi | |
| - name: Run tests with coverage | |
| run: python -m pytest --cov=solaredge2mqtt --cov-report=xml:coverage.xml --tb=short | |
| - name: Build package | |
| run: python -m build | |
| - name: Save python artifacts | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a | |
| with: | |
| name: python-artifacts-3.13-${{ env.REF_NAME }} | |
| path: | | |
| dist | |
| - name: Publish package to pypi | |
| if: ${{ github.event_name == 'release' }} | |
| uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b | |
| with: | |
| packages-dir: dist/ | |
| - name: Publish assets to github | |
| if: ${{ github.event_name == 'release' }} | |
| uses: svenstaro/upload-release-action@29e53e917877a24fad85510ded594ab3c9ca12de | |
| with: | |
| repo_token: ${{ github.token }} | |
| file: dist/* | |
| tag: ${{ github.event.release.tag_name }} | |
| overwrite: true | |
| file_glob: true | |
| build-compat: | |
| runs-on: ubuntu-latest | |
| needs: [variables, build-check] | |
| env: | |
| REF_NAME: ${{ needs.variables.outputs.ref_name }} | |
| permissions: | |
| contents: read | |
| strategy: | |
| matrix: | |
| python-version: | |
| - "3.11" | |
| - "3.12" | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Cache Python packages | |
| uses: actions/cache@2c8a9bd7457de244a408f35966fab2fb45fda9c8 | |
| with: | |
| path: | | |
| ~/.cache/pip | |
| !~/.cache/pip/log | |
| key: ${{ runner.os }}-python-${{ matrix.python-version }}-pip-${{ hashFiles('**/requirements.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-python-${{ matrix.python-version }}-pip- | |
| ${{ runner.os }}-python-${{ matrix.python-version }}- | |
| ${{ runner.os }}-python- | |
| ${{ runner.os }}-pip- | |
| - name: Install package with dev dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -e ".[dev,forecast]" | |
| - name: Run tests | |
| run: python -m pytest --tb=short | |
| build-docker: | |
| runs-on: ubuntu-latest | |
| needs: [variables, build-check] | |
| env: | |
| REF_NAME: ${{ needs.variables.outputs.ref_name }} | |
| IMAGE_NAME: ${{ needs.variables.outputs.image_name }} | |
| GHCR_IMAGE: ${{ needs.variables.outputs.ghcr_image }} | |
| VERSION: ${{ needs.variables.outputs.version }} | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| matrix: | |
| arch: [amd64, arm64, arm/v7] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install setuptools-scm and tomli | |
| run: pip install setuptools-scm[toml]>=8 tomli | |
| - name: Generate static version.json | |
| run: python freeze_version.py | |
| - name: Generate requirements hashFiles | |
| run: python generate_requirements.py | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a | |
| with: | |
| platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
| - name: Set up Docker Buildx | |
| id: buildx | |
| uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 | |
| - name: Log in to the Docker github container registry | |
| if: ${{github.event_name == 'release' || (github.event_name == 'push' && contains(fromJSON(vars.PACKAGE_BRANCHES), github.ref_name))}} | |
| uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee | |
| with: | |
| registry: ${{ env.REGISTRY_GITHUB }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Log in to the Docker container registry | |
| if: ${{github.event_name == 'release'}} | |
| uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Map platform to tag suffix | |
| id: archmap | |
| run: | | |
| case "${{ matrix.arch }}" in | |
| amd64) echo "ARCH_TAG=amd64" >> $GITHUB_ENV ;; | |
| arm64) echo "ARCH_TAG=arm64" >> $GITHUB_ENV ;; | |
| arm/v7) echo "ARCH_TAG=armv7" >> $GITHUB_ENV ;; | |
| esac | |
| - name: Extract Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 | |
| with: | |
| images: | | |
| ${{ env.GHCR_IMAGE }} | |
| ${{ github.event_name == 'release' && env.IMAGE_NAME || '' }} | |
| tags: | | |
| type=raw,value=latest-${{ env.ARCH_TAG }},enable=${{ github.event_name == 'release' }} | |
| type=raw,value=${{ env.VERSION }}-${{ env.ARCH_TAG }},enable=${{ github.event_name == 'release' }} | |
| type=raw,value=${{ env.REF_NAME }}-${{ env.ARCH_TAG }},enable=${{ github.event_name != 'release' }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf | |
| with: | |
| builder: ${{ steps.buildx.outputs.name }} | |
| context: . | |
| platforms: linux/${{ matrix.arch }} | |
| push: ${{github.event_name == 'release' || (github.event_name == 'push' && contains(fromJSON(vars.PACKAGE_BRANCHES), github.ref_name))}} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| annotations: ${{ steps.meta.outputs.annotations }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha,scope=${{ github.repository }}-${{ env.REF_NAME }}-${{ matrix.arch }} | |
| cache-to: type=gha,mode=max,scope=${{ github.repository }}-${{ env.REF_NAME }}-${{ matrix.arch }} | |
| merge-manifest: | |
| runs-on: ubuntu-latest | |
| needs: [variables, build-docker] | |
| env: | |
| REF_NAME: ${{ needs.variables.outputs.ref_name }} | |
| IMAGE_NAME: ${{ needs.variables.outputs.image_name }} | |
| GHCR_IMAGE: ${{ needs.variables.outputs.ghcr_image }} | |
| VERSION: ${{ needs.variables.outputs.version }} | |
| if: ${{github.event_name == 'release' || (github.event_name == 'push' && contains(fromJSON(vars.PACKAGE_BRANCHES), github.ref_name))}} | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 | |
| - name: Log in to the Docker github container registry | |
| uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee | |
| with: | |
| registry: ${{ env.REGISTRY_GITHUB }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Log in to the Docker container registry | |
| if: ${{github.event_name == 'release'}} | |
| uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Extract Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 | |
| with: | |
| images: | | |
| ${{ env.GHCR_IMAGE }} | |
| ${{ github.event_name == 'release' && env.IMAGE_NAME || '' }} | |
| tags: | | |
| type=raw,value=latest,enable=${{ github.event_name == 'release' }} | |
| type=raw,value=${{ env.VERSION }},enable=${{ github.event_name == 'release' }} | |
| type=raw,value=${{ env.REF_NAME }},enable=${{ github.event_name != 'release' }} | |
| - name: Create and push multi-arch manifest | |
| run: | | |
| set -eux | |
| if [ "${{ github.event_name }}" == "release" ]; then | |
| # Create latest tag | |
| docker buildx imagetools create \ | |
| -t ${{ env.GHCR_IMAGE }}:latest \ | |
| ${{ env.GHCR_IMAGE }}:latest-amd64 \ | |
| ${{ env.GHCR_IMAGE }}:latest-arm64 \ | |
| ${{ env.GHCR_IMAGE }}:latest-armv7 | |
| docker buildx imagetools create \ | |
| -t ${{ env.IMAGE_NAME }}:latest \ | |
| ${{ env.IMAGE_NAME }}:latest-amd64 \ | |
| ${{ env.IMAGE_NAME }}:latest-arm64 \ | |
| ${{ env.IMAGE_NAME }}:latest-armv7 | |
| # Create version tag | |
| docker buildx imagetools create \ | |
| -t ${{ env.GHCR_IMAGE }}:${{ env.VERSION }} \ | |
| ${{ env.GHCR_IMAGE }}:${{ env.VERSION }}-amd64 \ | |
| ${{ env.GHCR_IMAGE }}:${{ env.VERSION }}-arm64 \ | |
| ${{ env.GHCR_IMAGE }}:${{ env.VERSION }}-armv7 | |
| docker buildx imagetools create \ | |
| -t ${{ env.IMAGE_NAME }}:${{ env.VERSION }} \ | |
| ${{ env.IMAGE_NAME }}:${{ env.VERSION }}-amd64 \ | |
| ${{ env.IMAGE_NAME }}:${{ env.VERSION }}-arm64 \ | |
| ${{ env.IMAGE_NAME }}:${{ env.VERSION }}-armv7 | |
| else | |
| docker buildx imagetools create \ | |
| -t ${{ env.GHCR_IMAGE }}:${{ env.REF_NAME }} \ | |
| ${{ env.GHCR_IMAGE }}:${{ env.REF_NAME }}-amd64 \ | |
| ${{ env.GHCR_IMAGE }}:${{ env.REF_NAME }}-arm64 \ | |
| ${{ env.GHCR_IMAGE }}:${{ env.REF_NAME }}-armv7 | |
| fi |