Skip to content

Publish nightly configuration updates #1427

Publish nightly configuration updates

Publish nightly configuration updates #1427

name: Publish nightly configuration updates
on:
schedule:
- cron: 0 2 * * * # Every day at 02:00
workflow_dispatch: # Manually on demand
jobs:
publish-config:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18] # This should be LTS
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch the history, or this action won't work
- name: Enable Corepack
shell: bash
run: corepack enable
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- name: Detect changes (git)
run: |
# ===============================
# Detect changes using git
# ===============================
LAST_TAG=$(git describe --abbrev=0)
echo "Checking for changes since last tag $LAST_TAG"
# Figure out what changed in the package directories
CHANGES=$(git diff "$LAST_TAG" --name-only | grep -E "^packages\/" || true)
# Check if there were any config file changes
CONFIG_CHANGES=$(echo "$CHANGES" | grep -E "^packages\/config\/config\/(.*\/)?.+\.json" || true)
if [ -z "$CONFIG_CHANGES" ] ; then
echo "🔸 No config file changes since latest version, aborting..."
exit 0
fi
# Check if there were changes except config files and .gitignore
NON_CONFIG_CHANGES=$(echo "$CHANGES" | grep -E -v "^packages\/config\/config\/(.*\/)?.+\.json" | grep -v ".gitignore" || true)
if [ -n "$NON_CONFIG_CHANGES" ] ; then
echo "❌ Found non-config changes, aborting..."
exit 0
else
echo "✔ Changes are limited to config files"
fi
# ===============================
# Install dependencies
# ===============================
yarn install --immutable
yarn bootstrap
# ===============================
# Double-check changes with yarn
# ===============================
# Verify that only @zwave-js/config and zwave-js are changed
CHANGED_PACKAGES=$(SINCE=$LAST_TAG yarn ls-changed)
if [[ $(echo -e "@zwave-js/config\nzwave-js") != "$CHANGED_PACKAGES" ]]; then
echo "❌ Yarn detected unexpected package changes, aborting..."
echo "These packages are changed:"
echo "$CHANGED_PACKAGES"
exit 0
fi
# ===============================
# Perform last checks
# ===============================
# Create a clean build
yarn build
# Lint config files and Z-Wave specifics
yarn run lint:zwave
# ===============================
# Bump the version and publish
# ===============================
cd packages/config
# Figure out next version
cat > ./script.js << 'EOF'
const semver = require("semver");
let v = require("@zwave-js/config/package.json").version;
const now = new Date();
const today = new Date(now.getTime() - now.getTimezoneOffset()*60000);
const dateStr = today.toISOString().split("T")[0].replace(/-/g, "");
// Figure out the version increase with the least priority
// 1.0.0 < 1.0.1-20210101 < 1.0.1-alpha.0 < 1.0.1-alpha.0.20200101 < 1.0.1-alpha.1
if (semver.parse(v).prerelease.length) {
// This is a prerelease, append the config identifier
v += "." + dateStr;
} else {
// This is not a prerelease, patch-bump and then append the config (pre)identifier
v = semver.inc(v, "patch") + "-" + dateStr;
}
console.log(v);
EOF
VERSION=$(node script.js)
echo "Next version is $VERSION"
cd ../..
yarn config set npmAuthToken "${{ secrets.NPM_TOKEN }}"
yarn npm whoami
yarn workspace "@zwave-js/config" version "$VERSION" --deferred
yarn version apply --all
yarn workspace "@zwave-js/config" -vi npm publish --tag nightly