From 3a415f053b589fa09362b171d9612d385321ba59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Thu, 23 Feb 2023 13:50:58 +0100 Subject: [PATCH] update workflows --- .github/scripts/bump-versions.mjs | 52 ++++++++++++++ .github/scripts/package.json | 6 ++ .../workflows/check-documentation-urls.yml | 11 +-- .github/workflows/check-pr-title.yml | 3 + .github/workflows/docker-images.yml | 5 +- .github/workflows/release-create-pr.yml | 70 +++++++++++++++++++ .github/workflows/release-publish.yml | 57 +++++++++++++++ .github/workflows/test-workflows.yml | 5 +- 8 files changed, 199 insertions(+), 10 deletions(-) create mode 100644 .github/scripts/bump-versions.mjs create mode 100644 .github/scripts/package.json create mode 100644 .github/workflows/release-create-pr.yml create mode 100644 .github/workflows/release-publish.yml diff --git a/.github/scripts/bump-versions.mjs b/.github/scripts/bump-versions.mjs new file mode 100644 index 0000000000000..da45c92a8035d --- /dev/null +++ b/.github/scripts/bump-versions.mjs @@ -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); diff --git a/.github/scripts/package.json b/.github/scripts/package.json new file mode 100644 index 0000000000000..60f945f3f507b --- /dev/null +++ b/.github/scripts/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "semver": "^7.3.8", + "conventional-changelog-cli": "^2.2.2" + } +} diff --git a/.github/workflows/check-documentation-urls.yml b/.github/workflows/check-documentation-urls.yml index f32fc6f1654ac..6e352d2016afc 100644 --- a/.github/workflows/check-documentation-urls.yml +++ b/.github/workflows/check-documentation-urls.yml @@ -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 @@ -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 diff --git a/.github/workflows/check-pr-title.yml b/.github/workflows/check-pr-title.yml index 85011b7045d3c..f515d900e9147 100644 --- a/.github/workflows/check-pr-title.yml +++ b/.github/workflows/check-pr-title.yml @@ -6,6 +6,9 @@ on: - opened - edited - synchronize + branches: + - '**' + - '!release/*' jobs: check-pr-title: diff --git a/.github/workflows/docker-images.yml b/.github/workflows/docker-images.yml index 5d79fba12e80c..ad40b97d98a6c 100644 --- a/.github/workflows/docker-images.yml +++ b/.github/workflows/docker-images.yml @@ -1,9 +1,8 @@ name: Docker Image CI on: - push: - tags: - - n8n@* + release: + types: [published] jobs: build: diff --git a/.github/workflows/release-create-pr.yml b/.github/workflows/release-create-pr.yml new file mode 100644 index 0000000000000..cb0f359f4579a --- /dev/null +++ b/.github/workflows/release-create-pr.yml @@ -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 diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml new file mode 100644 index 0000000000000..b8b03ab8e1997 --- /dev/null +++ b/.github/workflows/release-publish.yml @@ -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}} diff --git a/.github/workflows/test-workflows.yml b/.github/workflows/test-workflows.yml index d8392ef3c7c67..2a26fcf9c2444 100644 --- a/.github/workflows/test-workflows.yml +++ b/.github/workflows/test-workflows.yml @@ -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 @@ -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()