Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ci): auto-release nightly versions of @zwave-js/config #1271

Merged
merged 1 commit into from
Jan 1, 2021
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .actrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-P ubuntu-latest=nektos/act-environments-ubuntu:18.04
95 changes: 95 additions & 0 deletions .github/workflows/nightly-config-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Publish nightly configuration updates

on:
schedule:
- cron: 0 2 * * * # Every day at 02:00

jobs:
publish-config:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x]

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

- name: Detect changes (git)
run: |
LAST_TAG=$(git describe --abbrev=0)
echo "Checking for changes since last tag $LAST_TAG"

# Check if there were any config file changes
if [[ $(git diff "$LAST_TAG" --name-only | grep -E "packages\/config\/config\/(.*\/)?.+\.json") != 0 ]]; then
echo "🔸 No config file changes since latest version, aborting..."
exit 0
fi

# Check if there were changes except config files and .gitignore
if [[ $(git diff "$LAST_TAG" --name-only | grep -E -v "packages\/config\/config\/(.*\/)?.+\.json" | grep -v ".gitignore") = 0 ]]; then
echo "❌ Found non-config changes, aborting..."
exit 0
else
echo "✔ Changes are limited to config files"
fi

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Install yarn
run: npm i -g yarn

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Double-check changes with lerna
run: |
# Verify that only @zwave-js/config and zwave-js are changed
LERNA_CHANGED=$(npx lerna changed)
if [[ $(echo -e "@zwave-js/config\nzwave-js") != "$LERNA_CHANGED" ]]; then
echo "❌ Lerna detected unexpected package changes, aborting..."
echo "These packages are changed:"
echo "$LERNA_CHANGED"
exit 0
fi

- name: Create a clean build
run: npx lerna run build --scope=@zwave-js/config

- name: Lint config files
run: npx lerna run lint:config

- name: Bump the version and publish
run: |
cd packages/config
npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
npm whoami

# Figure out next version
cat > ./script.js << 'EOF'
const semver = require("semver");
let v = require("../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"
npm version "$VERSION" --ignore-scripts --no-git-tag-version
npm publish