ci: Improve release automation (#29752)

pull/29758/head
Diego Sampaio 3 years ago committed by GitHub
parent 2ae66ab53a
commit 0f2f37d4db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .changeset/config.json
  2. 5
      .changeset/nine-yaks-draw.md
  3. 51
      .github/workflows/changesets.yml
  4. 3
      .github/workflows/publish-release.yml
  5. 1
      package.json
  6. 12
      packages/release-action/src/bumpNextVersion.ts
  7. 4
      packages/release-action/src/fixWorkspaceVersionsBeforePublish.ts
  8. 38
      packages/release-action/src/gitUtils.ts
  9. 17
      packages/release-action/src/publishRelease.ts
  10. 2
      packages/release-action/src/startPatchRelease.ts
  11. 33
      yarn.lock

@ -1,6 +1,6 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json",
"changelog": ["@changesets/changelog-github", { "repo": "RocketChat/Rocket.Chat" }],
"changelog": "@changesets/changelog-git",
"commit": false,
"fixed": [
["@rocket.chat/meteor", "@rocket.chat/core-typings", "@rocket.chat/rest-typings"]

@ -0,0 +1,5 @@
---
'@rocket.chat/release-action': minor
---
Use `release-automation` branch to perform the release

@ -1,51 +0,0 @@
name: Changesets
on:
push:
branches:
- develop
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
release-versions:
name: Variables Setup
runs-on: ubuntu-latest
outputs:
node-version: ${{ steps.var.outputs.node-version }}
steps:
- uses: Bhacaz/checkout-files@v2
with:
files: package.json
branch: ${{ github.ref }}
- id: var
run: |
NODE_VERSION=$(node -p "require('./package.json').engines.node")
echo "NODE_VERSION: ${NODE_VERSION}"
echo "node-version=${NODE_VERSION}" >> $GITHUB_OUTPUT
release:
name: Release
needs: [release-versions]
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Setup NodeJS
uses: ./.github/actions/setup-node
with:
node-version: ${{ needs.release-versions.outputs.node-version }}
cache-modules: true
install: true
- uses: dtinth/setup-github-actions-caching-for-turbo@v1
- name: Create Release Pull Request
uses: changesets/action@v1
with:
title: 'chore: Bump packages'
env:
HUSKY: 0
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

@ -3,7 +3,7 @@ name: Publish Final Release
on:
push:
branches:
- master
- release-automation
concurrency: ${{ github.workflow }}-${{ github.ref }}
@ -18,6 +18,7 @@ jobs:
- name: Checkout Repo
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.CI_PAT }}
- name: Setup NodeJS

@ -17,7 +17,6 @@
"fuselage": "./fuselage.sh"
},
"devDependencies": {
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.1",
"@types/chart.js": "^2.9.37",
"@types/js-yaml": "^4.0.5",

@ -9,6 +9,7 @@ import { setupOctokit } from './setupOctokit';
import { createNpmFile } from './createNpmFile';
import { getChangelogEntry, bumpFileVersions, readPackageJson } from './utils';
import { fixWorkspaceVersionsBeforePublish } from './fixWorkspaceVersionsBeforePublish';
import { commitChanges, createBranch, createTag, pushNewBranch } from './gitUtils';
export async function bumpNextVersion({
githubToken,
@ -59,26 +60,25 @@ export async function bumpNextVersion({
await bumpFileVersions(cwd, currentVersion, newVersion);
// TODO check if branch exists
await exec('git', ['checkout', '-b', newBranch]);
await createBranch(newBranch);
await exec('git', ['add', '.']);
await exec('git', ['commit', '-m', newVersion]);
await commitChanges(`Release ${newVersion}`);
core.info('fix dependencies in workspace packages');
await fixWorkspaceVersionsBeforePublish();
await exec('yarn', ['changeset', 'publish', '--no-git-tag']);
await exec('git', ['tag', newVersion]);
await createTag(newVersion);
await exec('git', ['push', '--force', '--follow-tags', 'origin', `HEAD:refs/heads/${newBranch}`]);
await pushNewBranch(newBranch);
if (newVersion.includes('rc.0')) {
const finalPrTitle = `Release ${finalVersion}`;
core.info('creating pull request');
await octokit.rest.pulls.create({
base: 'master',
base: 'release-automation',
head: newBranch,
title: finalPrTitle,
body: prBody,

@ -41,10 +41,6 @@ export async function fixWorkspaceVersionsBeforePublish() {
for (const dependency of dependencies) {
const dependencyVersion = packageJson[dependencyType][dependency];
if (dependencyVersion.startsWith('workspace:')) {
if (!dependencyVersion.startsWith('workspace:^')) {
throw new Error(`Unsupported workspace version range: ${dependencyVersion}`);
}
const realVersion = workspaceVersions.get(dependency);
if (!realVersion) {
throw new Error(`Could not find version for workspace ${dependency}`);

@ -1,6 +1,42 @@
import { exec } from '@actions/exec';
import { exec, getExecOutput } from '@actions/exec';
export async function setupGitUser() {
await exec('git', ['config', 'user.name', '"rocketchat-github-ci"']);
await exec('git', ['config', 'user.email', '"buildmaster@rocket.chat"']);
}
export async function createBranch(newBranch: string) {
await exec('git', ['checkout', '-b', newBranch]);
}
export async function checkoutBranch(branchName: string) {
await exec('git', ['checkout', branchName]);
}
export async function mergeBranch(branchName: string) {
await exec('git', ['merge', '--no-edit', branchName]);
}
export async function commitChanges(commitMessage: string) {
await exec('git', ['add', '.']);
await exec('git', ['commit', '-m', commitMessage]);
}
export async function createTag(version: string) {
// create an annotated tag so git push --follow-tags will push the tag
await exec('git', ['tag', version, '-m', version]);
}
export async function getCurrentBranch() {
const { stdout: branchName } = await getExecOutput('git', ['rev-parse', '--abbrev-ref', 'HEAD']);
return branchName.trim();
}
export async function pushChanges() {
await exec('git', ['push', '--follow-tags']);
}
export async function pushNewBranch(newBranch: string) {
await exec('git', ['push', '--force', '--follow-tags', 'origin', `HEAD:refs/heads/${newBranch}`]);
}

@ -9,6 +9,7 @@ import { createNpmFile } from './createNpmFile';
import { setupOctokit } from './setupOctokit';
import { bumpFileVersions, getChangelogEntry, readPackageJson } from './utils';
import { fixWorkspaceVersionsBeforePublish } from './fixWorkspaceVersionsBeforePublish';
import { checkoutBranch, commitChanges, createTag, getCurrentBranch, mergeBranch, pushChanges } from './gitUtils';
export async function publishRelease({
githubToken,
@ -29,7 +30,7 @@ export async function publishRelease({
await createNpmFile();
if (baseRef) {
await exec('git', ['checkout', baseRef]);
await checkoutBranch(baseRef);
}
const { version: currentVersion } = await readPackageJson(cwd);
@ -73,17 +74,23 @@ export async function publishRelease({
core.info('update version in all files to new');
await bumpFileVersions(cwd, currentVersion, newVersion);
await exec('git', ['add', '.']);
await exec('git', ['commit', '-m', `Release ${newVersion}`]);
await commitChanges(`Release ${newVersion}`);
// get current branch name
const branchName = await getCurrentBranch();
// merge release changes to master
await checkoutBranch('master');
await mergeBranch(branchName);
core.info('fix dependencies in workspace packages');
await fixWorkspaceVersionsBeforePublish();
await exec('yarn', ['changeset', 'publish', '--no-git-tag']);
await exec('git', ['tag', newVersion]);
await createTag(newVersion);
await exec('git', ['push', '--follow-tags']);
await pushChanges();
core.info('create release');
await octokit.rest.repos.createRelease({

@ -48,7 +48,7 @@ export async function startPatchRelease({
core.info('creating pull request');
await octokit.rest.pulls.create({
base: 'master',
base: 'release-automation',
head: newBranch,
title: finalPrTitle,
body: '',

@ -4165,17 +4165,6 @@ __metadata:
languageName: node
linkType: hard
"@changesets/changelog-github@npm:^0.4.8":
version: 0.4.8
resolution: "@changesets/changelog-github@npm:0.4.8"
dependencies:
"@changesets/get-github-info": ^0.5.2
"@changesets/types": ^5.2.1
dotenv: ^8.1.0
checksum: 8a357cc08757e0eeca267ee05141f68bef936582abef8b78a5d30d99f5a86e41b7d3debba70992b73b2f57b0fc6201ec1cc3c65116930167ee3197b427b865c5
languageName: node
linkType: hard
"@changesets/cli@npm:^2.26.1":
version: 2.26.1
resolution: "@changesets/cli@npm:2.26.1"
@ -4256,16 +4245,6 @@ __metadata:
languageName: node
linkType: hard
"@changesets/get-github-info@npm:^0.5.2":
version: 0.5.2
resolution: "@changesets/get-github-info@npm:0.5.2"
dependencies:
dataloader: ^1.4.0
node-fetch: ^2.5.0
checksum: 067e07eeaecdbedbd1c715513c4aa6206a941bd1d3af292d067792808c6fa6644caad2b35fba614a44892559c031c234df8028f8d2abd4cb2682d48080ef5df3
languageName: node
linkType: hard
"@changesets/get-release-plan@npm:^3.0.16":
version: 3.0.16
resolution: "@changesets/get-release-plan@npm:3.0.16"
@ -20149,13 +20128,6 @@ __metadata:
languageName: node
linkType: hard
"dataloader@npm:^1.4.0":
version: 1.4.0
resolution: "dataloader@npm:1.4.0"
checksum: e2c93d43afde68980efc0cd9ff48e9851116e27a9687f863e02b56d46f7e7868cc762cd6dcbaf4197e1ca850a03651510c165c2ae24b8e9843fd894002ad0e20
languageName: node
linkType: hard
"date-fns@npm:^2.15.0, date-fns@npm:^2.28.0":
version: 2.28.0
resolution: "date-fns@npm:2.28.0"
@ -21058,7 +21030,7 @@ __metadata:
languageName: node
linkType: hard
"dotenv@npm:^8.0.0, dotenv@npm:^8.1.0":
"dotenv@npm:^8.0.0":
version: 8.6.0
resolution: "dotenv@npm:8.6.0"
checksum: 38e902c80b0666ab59e9310a3d24ed237029a7ce34d976796349765ac96b8d769f6df19090f1f471b77a25ca391971efde8a1ea63bb83111bd8bec8e5cc9b2cd
@ -30812,7 +30784,7 @@ __metadata:
languageName: node
linkType: hard
"node-fetch@npm:^2.5.0, node-fetch@npm:^2.6.11":
"node-fetch@npm:^2.6.11":
version: 2.6.11
resolution: "node-fetch@npm:2.6.11"
dependencies:
@ -35958,7 +35930,6 @@ __metadata:
version: 0.0.0-use.local
resolution: "rocket.chat@workspace:."
dependencies:
"@changesets/changelog-github": ^0.4.8
"@changesets/cli": ^2.26.1
"@types/chart.js": ^2.9.37
"@types/js-yaml": ^4.0.5

Loading…
Cancel
Save