Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
258 changes: 126 additions & 132 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,142 +3,136 @@ name: Test and Release
# Run this job on all pushes and pull requests
# as well as tags with a semantic version
on:
push:
branches:
- master
- automated/*
tags:
# normal versions
- "v[0-9]+.[0-9]+.[0-9]+"
# pre-releases
- "v[0-9]+.[0-9]+.[0-9]+-**"
pull_request: {}
push:
branches:
- master
- automated/*
tags:
# normal versions
- "v[0-9]+.[0-9]+.[0-9]+"
# pre-releases
- "v[0-9]+.[0-9]+.[0-9]+-**"
pull_request: {}

# Cancel previous PR/branch runs when a new commit is pushed
concurrency:
group: ${{ github.ref }}-tests
cancel-in-progress: true
group: ${{ github.ref }}-tests
cancel-in-progress: true

permissions:
id-token: write # Required for OIDC
contents: write
pull-requests: write
id-token: write # Required for OIDC
contents: write
pull-requests: write

jobs:
# Runs unit tests on all supported node versions and OSes
unit-tests:
if: contains(github.event.head_commit.message, '[skip ci]') == false

runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [20.x, 22.x, 24.x]
os: [ubuntu-latest]

steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Verify formatting
run: npm run format

- name: Lint source code
run: npm run lint

- name: Compile TypeScript code
run: npm run build

- name: Run component tests
run: npm t
env:
REQUEST_TIMEOUT: 20000
TESTING: true

- name: Test migration from ioBroker.example adapters
run: bash .github/test_migration.sh
env:
TESTING: true

- name: Start the CLI on a production environment
run: |
npm ci --omit=dev
TEST_STARTUP=true node ./bin/create-adapter.js
# TODO: Test the console output

# ===================

# Deploys the final package to NPM and Github Releases
deploy:
# Trigger this step only when a commit is tagged with a version number
if: |
contains(github.event.head_commit.message, '[skip ci]') == false &&
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/v')

needs: [unit-tests]

runs-on: ubuntu-latest
strategy:
matrix:
node-version: [22.x]

steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Extract the version and commit body from the tag
id: extract_release
# The body may be multiline, therefore we need to escape some characters
run: |
VERSION="${{ github.ref }}"
VERSION=${VERSION##*/v}
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
EOF=$(od -An -N6 -x /dev/urandom | tr -d ' ')
BODY=$(git show -s --format=%b)
echo "BODY<<$EOF" >> $GITHUB_OUTPUT
echo "$BODY" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT

- name: Install dependencies
run: npm ci

# This is unnecessary, since npm publish will run prepublishOnly, which will run build
# - name: Create a clean build
# run: npm run build

- name: Publish package to npm
run: |
npm install -g npm@latest
npm publish

- name: Create Github Release
uses: softprops/action-gh-release@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
name: Release v${{ steps.extract_release.outputs.VERSION }}
draft: false
# Prerelease versions create prereleases on Github
prerelease: ${{ contains(steps.extract_release.outputs.VERSION, '-') }}
body: ${{ steps.extract_release.outputs.BODY }}

- name: Update ioBroker.template repo
run: bash .github/update_templates.sh
env:
GITHUB_TOKEN: ${{ secrets.ALCALZONE_GITHUB_TOKEN }}
# Runs unit tests on all supported node versions and OSes
unit-tests:
if: contains(github.event.head_commit.message, '[skip ci]') == false

runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [20.x, 22.x, 24.x]
os: [ubuntu-latest]

steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: "npm"

- name: Install dependencies
run: npm ci

- name: Verify formatting
run: npm run format

- name: Lint source code
run: npm run lint

- name: Compile TypeScript code
run: npm run build

- name: Run component tests
run: npm t
env:
REQUEST_TIMEOUT: 20000
TESTING: true

- name: Test migration from ioBroker.example adapters
run: bash .github/test_migration.sh
env:
TESTING: true

- name: Start the CLI on a production environment
run: |
npm ci --omit=dev
TEST_STARTUP=true node ./bin/create-adapter.js
# TODO: Test the console output

# ===================

# Deploys the final package to NPM and Github Releases
deploy:
# Trigger this step only when a commit is tagged with a version number
if: |
contains(github.event.head_commit.message, '[skip ci]') == false &&
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/v')

needs: [unit-tests]

runs-on: ubuntu-latest
strategy:
matrix:
node-version: [22.x]

steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: "npm"

- name: Extract the version and commit body from the tag
id: extract_release
# The body may be multiline, therefore we need to escape some characters
run: |
VERSION="${{ github.ref }}"
VERSION=${VERSION##*/v}
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
EOF=$(od -An -N6 -x /dev/urandom | tr -d ' ')
BODY=$(git show -s --format=%b)
echo "BODY<<$EOF" >> $GITHUB_OUTPUT
echo "$BODY" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT

- name: Install dependencies
run: npm ci

- name: Publish package to npm
run: npm publish # npm publish will run prepublishOnly, which will run build

- name: Create Github Release
uses: softprops/action-gh-release@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
name: Release v${{ steps.extract_release.outputs.VERSION }}
draft: false
# Prerelease versions create prereleases on Github
prerelease: ${{ contains(steps.extract_release.outputs.VERSION, '-') }}
body: ${{ steps.extract_release.outputs.BODY }}

- name: Update ioBroker.template repo
run: bash .github/update_templates.sh
env:
GITHUB_TOKEN: ${{ secrets.ALCALZONE_GITHUB_TOKEN }}
Loading