Skip to content

Commit

Permalink
update workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Feb 23, 2023
1 parent 1c6a93f commit 3a415f0
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 10 deletions.
52 changes: 52 additions & 0 deletions .github/scripts/bump-versions.mjs
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);
6 changes: 6 additions & 0 deletions .github/scripts/package.json
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"
}
}
11 changes: 6 additions & 5 deletions .github/workflows/check-documentation-urls.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
name: Check Documentation URLs

on:
push:
tags:
- n8n@*
release:
types: [published]
schedule:
- cron: '0 0 * * *'
workflow_dispatch:

jobs:
build:
check-docs-urls:
runs-on: ubuntu-latest

timeout-minutes: 5
Expand All @@ -23,7 +24,7 @@ jobs:
cache: 'pnpm'

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

- name: Build nodes-base
run: pnpm --filter n8n-workflow --filter=n8n-core --filter=n8n-nodes-base build
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/check-pr-title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- opened
- edited
- synchronize
branches:
- '**'
- '!release/*'

jobs:
check-pr-title:
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/docker-images.yml
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:
Expand Down
70 changes: 70 additions & 0 deletions .github/workflows/release-create-pr.yml
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
57 changes: 57 additions & 0 deletions .github/workflows/release-publish.yml
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}}
5 changes: 3 additions & 2 deletions .github/workflows/test-workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

- uses: pnpm/action-setup@v2.2.4
with:
version: 7.18.1
version: 7.27.0

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
Expand Down Expand Up @@ -73,10 +73,11 @@ jobs:
shell: bash

- name: Run tests
run: n8n/packages/cli/bin/n8n executeBatch --shallow --ids=test-workflows/safeList.txt --shortOutput --concurrency=16 --compare=test-workflows/snapshots
run: n8n/packages/cli/bin/n8n executeBatch --shallow --skipList=test-workflows/skipList.txt --shortOutput --concurrency=16 --compare=test-workflows/snapshots
shell: bash
env:
N8N_ENCRYPTION_KEY: ${{secrets.ENCRYPTION_KEY}}
SKIP_STATISTICS_EVENTS: true
# -
# name: Export credentials
# if: always()
Expand Down

0 comments on commit 3a415f0

Please # to comment.