Skip to content

Publish nightly dev releases #15

Publish nightly dev releases

Publish nightly dev releases #15

# This workflow automatically generates nightly release PRs if there were changes to the code
name: Publish nightly dev releases
on:
schedule:
- cron: 0 2 * * * # Every day at 02:00
workflow_dispatch: # Manually on demand
jobs:
publish-config:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch the history, or this action won't work
- name: Detect changes (git)
id: changes
run: |
# ===============================
# Detect changes using git
# ===============================
LAST_TAG=$(git describe --abbrev=0 --tags)
echo "Checking for changes since last tag $LAST_TAG"
# Figure out if anything changed in the package directories
CHANGES=$(git diff "$LAST_TAG" --name-only | grep -E "^packages\/" || true)
if [ -z "$CHANGES" ] ; then
echo "🔸 No package changes since latest version, aborting..."
echo "result=unchanged" >> $GITHUB_OUTPUT
else
echo "result=ok" >> $GITHUB_OUTPUT
fi
- name: Prepare testing environment
if: steps.changes.outputs.result == 'ok'
uses: ./.github/actions/prepare-env
- name: Prepare Webbrowser testing environment
if: steps.changes.outputs.result == 'ok'
uses: ./.github/actions/prepare-webtests
- name: Execute tests
if: steps.changes.outputs.result == 'ok'
run: npm run test
- name: Prepare chip tests
if: steps.changes.outputs.result == 'ok'
uses: ./.github/actions/prepare-chip-testing
- name: chip-tool-test execution
if: steps.changes.outputs.result == 'ok'
id: test-execution
shell: bash
run: |
cd chip-testing
npm run test-chip
- name: Determine the version bump
if: steps.changes.outputs.result == 'ok'
id: version
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const semver = require("semver");
const now = new Date();
const today = new Date(now.getTime() - now.getTimezoneOffset()*60000);
const dateStr = today.toISOString().split("T")[0].replace(/-/g, "");
const sha = require("child_process").execSync("git rev-parse --short HEAD").toString("utf8").trim();
const prevVersion = require(`${process.env.GITHUB_WORKSPACE}/lerna.json`).version;
const parsed = semver.parse(prevVersion);
const prereleaseIdentifier = parsed.prerelease[0] || "alpha";
for (let i = 1; i < parsed.prerelease.length; i++) {
const part = parsed.prerelease[i];
if (typeof part === "number") {
continue;
}
// Parse stuff like `8-20210909-001a711c` back to `8`
const numeric = parseInt(part);
if (!Number.isNaN(numeric)) {
parsed.prerelease[i] = numeric;
}
}
// Figure out the next version
return `${semver.inc(parsed, "prerelease", prereleaseIdentifier)}-${dateStr}-${sha}`;
- name: Bump version locally
if: steps.changes.outputs.result == 'ok'
env:
VERSION: ${{ steps.version.outputs.result }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "Github Action"
git add .
git commit -m "v${VERSION}" && npx lerna version ${VERSION} --no-push --exact --ignore-scripts --no-commit-hooks --yes --amend --force-publish || npx lerna version ${VERSION} --exact --no-push --ignore-scripts --no-commit-hooks --yes --force-publish
- name: Create Pull Request
if: steps.changes.outputs.result == 'ok'
id: cpr
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.PR_TOKEN }}
commit-message: "[NIGHTLY DEV RELEASE] ${{ steps.version.outputs.result }}"
committer: Automator77 <[email protected]>
author: Automator77 <[email protected]>
signoff: false
branch: nightly-release
delete-branch: true
title: "[NIGHTLY DEV RELEASE] ${{ steps.version.outputs.result }}"
body: |
Update version by nightly dev release
labels: |
automated pr
assignees: Automator77
draft: false