mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-06-23 05:31:47 +00:00
1a1c09449c
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
241 lines
10 KiB
YAML
241 lines
10 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- '[0-9]+.[0-9]+.[0-9]+'
|
|
branches:
|
|
- dev
|
|
- master
|
|
pull_request:
|
|
|
|
permissions:
|
|
contents: write
|
|
pull-requests: write
|
|
id-token: write
|
|
|
|
jobs:
|
|
ci:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
id-token: write # for npm publish
|
|
actions: read # for Nerivec/action-ci-bench
|
|
pull-requests: write # for Nerivec/action-ci-bench
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
if: (github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/tags/')) && github.event_name == 'push'
|
|
with:
|
|
# Required for `release: merge dev -> master and promote dev`
|
|
token: ${{ secrets.GH_TOKEN }}
|
|
|
|
- uses: actions/checkout@v6
|
|
if: ((github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/tags/')) && github.event_name == 'push') == false
|
|
|
|
- uses: pnpm/action-setup@v6
|
|
|
|
- uses: actions/setup-node@v6
|
|
with:
|
|
node-version: 24
|
|
registry-url: https://registry.npmjs.org/
|
|
cache: pnpm
|
|
|
|
- name: Install dependencies
|
|
run: pnpm i --frozen-lockfile
|
|
|
|
- name: Check
|
|
run: pnpm run check
|
|
|
|
- name: Build
|
|
run: pnpm run build
|
|
|
|
- name: Test
|
|
run: pnpm run test:coverage
|
|
|
|
- name: Bench
|
|
if: github.ref == 'refs/heads/dev' || (github.event_name == 'pull_request' && !startsWith(github.head_ref, 'release-please-'))
|
|
uses: Nerivec/action-ci-bench@main
|
|
with:
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
compare-against: dev
|
|
base-cmd: npx vitest bench --run --config ./test/vitest.config.mts --outputJson bench.json
|
|
compare-cmd: npx vitest bench --run --config ./test/vitest.config.mts --compare bench.json
|
|
base-result: bench.json
|
|
|
|
- name: Log in to the Docker container registry
|
|
if: (github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/tags/')) && github.event_name == 'push'
|
|
uses: docker/login-action@v4
|
|
with:
|
|
username: koenkk
|
|
password: ${{ secrets.DOCKER_KEY }}
|
|
|
|
- name: Log in to the GitHub container registry
|
|
if: (github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/tags/')) && github.event_name == 'push'
|
|
uses: docker/login-action@v4
|
|
with:
|
|
registry: ghcr.io
|
|
username: koenkk
|
|
password: ${{ secrets.GH_TOKEN }}
|
|
|
|
- name: Docker setup - QEMU
|
|
if: (github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/tags/')) && github.event_name == 'push'
|
|
uses: docker/setup-qemu-action@v4
|
|
with:
|
|
platforms: all
|
|
|
|
- name: Docker setup - Buildx
|
|
if: (github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/tags/')) && github.event_name == 'push'
|
|
id: buildx
|
|
uses: docker/setup-buildx-action@v4
|
|
with:
|
|
version: latest
|
|
|
|
- name: dev - Docker build and push
|
|
if: github.ref == 'refs/heads/dev' && github.event_name == 'push'
|
|
uses: docker/build-push-action@v7
|
|
with:
|
|
context: .
|
|
file: docker/Dockerfile
|
|
platforms: linux/arm64/v8,linux/amd64,linux/arm/v6,linux/arm/v7,linux/riscv64,linux/386
|
|
tags: koenkk/zigbee2mqtt:latest-dev,ghcr.io/koenkk/zigbee2mqtt:latest-dev
|
|
push: true
|
|
build-args: |
|
|
COMMIT=${{ github.sha }}
|
|
VERSION=dev
|
|
DATE=${{ github.event.repository.updated_at }}
|
|
|
|
- name: dev - Publish types
|
|
if: github.ref == 'refs/heads/dev' && github.event_name == 'push'
|
|
run: |
|
|
pnpm run build:types
|
|
temp_dir=$(mktemp -d)
|
|
cp -R package.json LICENSE dist $temp_dir
|
|
git fetch --unshallow
|
|
git checkout dev-types
|
|
rm -rf *
|
|
cp -R $temp_dir/* .
|
|
# remove unnecessary dependencies
|
|
KEEP_DEPS='["zigbee-herdsman","zigbee-herdsman-converters"]'
|
|
tmp_pkg=$(mktemp)
|
|
jq --indent 4 --argjson keep "$KEEP_DEPS" 'def filterDeps: (. // {}) | with_entries(select(.key as $k | $keep | index($k))); .dependencies |= filterDeps | .devDependencies |= filterDeps | .optionalDependencies |= filterDeps' package.json > "$tmp_pkg"
|
|
mv "$tmp_pkg" package.json
|
|
git add -A
|
|
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
git config --local user.name "github-actions[bot]"
|
|
git commit -m "$GITHUB_SHA" || echo 'Nothing to commit'
|
|
git push --force --set-upstream origin dev-types
|
|
|
|
- name: release - Docker meta
|
|
if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push'
|
|
uses: docker/metadata-action@v6
|
|
id: meta
|
|
with:
|
|
images: |
|
|
koenkk/zigbee2mqtt
|
|
ghcr.io/koenkk/zigbee2mqtt
|
|
tags: |
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=semver,pattern={{major}}
|
|
|
|
- name: release - Docker build and push
|
|
if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push'
|
|
uses: docker/build-push-action@v7
|
|
with:
|
|
context: .
|
|
file: docker/Dockerfile
|
|
platforms: linux/arm64/v8,linux/amd64,linux/arm/v6,linux/arm/v7,linux/riscv64,linux/386
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
push: true
|
|
build-args: |
|
|
COMMIT=${{ github.sha }}
|
|
VERSION=${{ github.ref_name }}
|
|
DATE=${{ github.event.repository.updated_at }}
|
|
|
|
- name: 'release: Publish to npm'
|
|
if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push'
|
|
run: pnpm publish --no-git-checks
|
|
env:
|
|
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN }}
|
|
NPM_CONFIG_PROVENANCE: true
|
|
|
|
- name: 'dev: Trigger zigbee2mqtt/hassio-zigbee2mqtt build'
|
|
if: github.ref == 'refs/heads/dev' && github.event_name == 'push'
|
|
run: |
|
|
curl \
|
|
-X POST \
|
|
-H "Authorization: token ${{ secrets.GH_TOKEN }}" \
|
|
-H "Accept: application/vnd.github.v3+json" \
|
|
https://api.github.com/repos/zigbee2mqtt/hassio-zigbee2mqtt/actions/workflows/ci.yml/dispatches \
|
|
-d '{"ref":"master","inputs":{}}'
|
|
|
|
- name: 'release: Trigger zigbee2mqtt/hassio-zigbee2mqtt build'
|
|
if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push'
|
|
run: |
|
|
TAG=${GITHUB_REF#refs/*/}
|
|
echo "Triggering with tag '$TAG'"
|
|
curl \
|
|
-X POST \
|
|
-H "Authorization: token ${{ secrets.GH_TOKEN }}" \
|
|
-H "Accept: application/vnd.github.everest-preview+json" \
|
|
-H "Content-Type: application/json" \
|
|
https://api.github.com/repos/zigbee2mqtt/hassio-zigbee2mqtt/dispatches \
|
|
--data "{\"event_type\": \"release\", \"client_payload\": { \"version\": \"$TAG-1\"}}"
|
|
|
|
- name: 'release: Trigger zigbee2mqtt-chart image update'
|
|
if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push'
|
|
run: |
|
|
TAG=${GITHUB_REF#refs/*/}
|
|
echo "Triggering with tag '$TAG'"
|
|
curl -L \
|
|
-X POST \
|
|
-H "Accept: application/vnd.github+json" \
|
|
-H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" \
|
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
|
https://api.github.com/repos/Koenkk/zigbee2mqtt-chart/actions/workflows/on_zigbee2mqtt_release.yaml/dispatches \
|
|
--data "{\"ref\": \"main\", \"inputs\": { \"zigbee2mqtt_version\": \"$TAG\"}}"
|
|
|
|
- name: 'release: merge dev -> master and promote dev'
|
|
if: startsWith(github.ref, 'refs/tags/') && github.event_name == 'push'
|
|
run: |
|
|
TAG=${GITHUB_REF#refs/*/}
|
|
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
git config --local user.name "github-actions[bot]"
|
|
git fetch --unshallow
|
|
git fetch origin
|
|
git checkout master
|
|
git merge --ff-only origin/dev
|
|
git push origin master
|
|
git checkout dev
|
|
jq --indent 4 ".version = \"$TAG-dev\"" package.json > package.json.tmp
|
|
mv package.json.tmp package.json
|
|
git add -A
|
|
git commit -m "chore: promote to dev"
|
|
git push origin dev
|
|
|
|
tests:
|
|
strategy:
|
|
matrix:
|
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
node: [20, 22, 24]
|
|
runs-on: ${{ matrix.os }}
|
|
continue-on-error: true
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
|
|
- uses: pnpm/action-setup@v6
|
|
|
|
- uses: actions/setup-node@v6
|
|
with:
|
|
node-version: ${{ matrix.node }}
|
|
cache: pnpm
|
|
|
|
- name: Install dependencies
|
|
# --ignore-scripts prevents build on Windows (only for unix-dgram, so doesn't matter, others have pre-builds)
|
|
run: pnpm i --frozen-lockfile ${{ matrix.os == 'windows-latest' && '--ignore-scripts' || '' }}
|
|
|
|
- name: Build
|
|
run: pnpm run build
|
|
|
|
- name: Test
|
|
run: pnpm run test:coverage
|