forked from n8n-io/n8n
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
199 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import semver from 'semver'; | ||
import { writeFile, readFile } from 'fs/promises'; | ||
import { resolve } from 'path'; | ||
import child_process from 'child_process'; | ||
import { promisify } from 'util'; | ||
import assert from 'assert'; | ||
|
||
const exec = promisify(child_process.exec); | ||
|
||
const rootDir = process.cwd(); | ||
const releaseType = process.env.RELEASE_TYPE; | ||
assert.match(releaseType, /^(patch|minor|major)$/, 'Invalid RELEASE_TYPE'); | ||
|
||
// TODO: if releaseType is `auto` determine release type based on the changelog | ||
|
||
const lastTag = (await exec('git describe --tags --match "n8n@*" --abbrev=0')).stdout.trim(); | ||
const packages = JSON.parse((await exec('pnpm ls -r --only-projects --json')).stdout); | ||
|
||
const packageMap = {}; | ||
for (let { name, path, version, private: isPrivate, dependencies } of packages) { | ||
if (isPrivate && path !== rootDir) continue; | ||
if (path === rootDir) name = 'monorepo-root'; | ||
|
||
const isDirty = await exec(`git diff --quiet HEAD ${lastTag} -- ${path}`) | ||
.then(() => false) | ||
.catch((error) => true); | ||
|
||
packageMap[name] = { path, isDirty, version }; | ||
} | ||
|
||
assert.ok(packageMap['n8n'].isDirty, 'No changes found since the last release'); | ||
|
||
// Keep the monorepo version up to date with the released version | ||
packageMap['monorepo-root'].version = packageMap['n8n'].version; | ||
|
||
for (const packageName in packageMap) { | ||
const { path, version, isDirty } = packageMap[packageName]; | ||
const packageFile = resolve(path, 'package.json'); | ||
const packageJson = JSON.parse(await readFile(packageFile, 'utf-8')); | ||
|
||
packageJson.version = packageMap[packageName].nextVersion = | ||
isDirty || | ||
Object.keys(packageJson.dependencies).some( | ||
(dependencyName) => packageMap[dependencyName]?.isDirty, | ||
) | ||
? semver.inc(version, releaseType) | ||
: version; | ||
|
||
await writeFile(packageFile, JSON.stringify(packageJson, null, 2) + '\n'); | ||
} | ||
|
||
console.log(packageMap['n8n'].nextVersion); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"dependencies": { | ||
"semver": "^7.3.8", | ||
"conventional-changelog-cli": "^2.2.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ on: | |
- opened | ||
- edited | ||
- synchronize | ||
branches: | ||
- '**' | ||
- '!release/*' | ||
|
||
jobs: | ||
check-pr-title: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
name: Docker Image CI | ||
|
||
on: | ||
push: | ||
tags: | ||
- n8n@* | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
build: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: 'Release: Create Pull Request' | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
base-branch: | ||
description: 'The branch, tag, or commit to create this release PR from.' | ||
required: true | ||
default: 'master' | ||
|
||
release-type: | ||
description: 'A SemVer release type.' | ||
required: true | ||
type: choice | ||
default: 'minor' | ||
options: | ||
- patch | ||
- minor | ||
|
||
jobs: | ||
create-release-pr: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
timeout-minutes: 5 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ github.event.inputs.base-branch }} | ||
|
||
- name: Push the base branch | ||
run: | | ||
git checkout -b "release/${{ github.event.inputs.release-type }}" | ||
git push -f origin "release/${{ github.event.inputs.release-type }}" | ||
- uses: pnpm/action-setup@v2.2.4 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16.x | ||
- run: npm install --prefix=.github/scripts --no-package-lock | ||
|
||
- name: Bump package versions | ||
run: | | ||
echo "NEXT_RELEASE=$(node .github/scripts/bump-versions.mjs)" >> $GITHUB_ENV | ||
pnpm i --lockfile-only | ||
env: | ||
RELEASE_TYPE: ${{ github.event.inputs.release-type }} | ||
|
||
- name: Generate Changelog | ||
run: npx conventional-changelog-cli -p angular -i CHANGELOG.md -s -t n8n@ | ||
|
||
- name: Push the release branch, and Create the PR | ||
uses: peter-evans/create-pull-request@v4 | ||
with: | ||
base: 'release/${{ github.event.inputs.release-type }}' | ||
branch: 'release/${{ env.NEXT_RELEASE }}' | ||
commit-message: ':rocket: Release ${{ env.NEXT_RELEASE }}' | ||
delete-branch: true | ||
labels: 'release' | ||
title: ':rocket: Release ${{ env.NEXT_RELEASE }}' | ||
# 'TODO: add generated changelog to the body. create a script to generate custom changelog' | ||
body: '' | ||
|
||
# TODO: post PR link to slack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: 'Release: Publish' | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
branches: | ||
- 'release/patch' | ||
- 'release/minor' | ||
|
||
jobs: | ||
publish-release: | ||
if: github.event.pull_request.merged == true | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: write | ||
|
||
timeout-minutes: 10 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- uses: pnpm/action-setup@v2.2.4 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16.x | ||
cache: 'pnpm' | ||
- run: pnpm install --frozen-lockfile | ||
|
||
- name: Build | ||
run: pnpm build | ||
|
||
- name: Publish to NPM | ||
run: | | ||
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | ||
pnpm publish -r --publish-branch ${{github.event.pull_request.base.ref}} --access public | ||
echo "RELEASE=$(node -e 'console.log(require("./package.json").version)')" >> $GITHUB_ENV | ||
- name: Create Release | ||
uses: ncipollo/release-action@v1 | ||
with: | ||
commit: ${{github.event.pull_request.base.ref}} | ||
tag: 'n8n@${{env.RELEASE}}' | ||
|
||
- name: Merge Release into 'master' | ||
run: | | ||
git fetch origin | ||
git checkout --track origin/master | ||
git config user.name "Jan Oberhauser" | ||
git config user.email jan.oberhauser@gmail.com | ||
git merge --ff n8n@${{env.RELEASE}} | ||
git push origin master | ||
git push origin :${{github.event.pull_request.base.ref}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters