Skip to content

Commit

Permalink
Merge pull request #29545 from RocketChat/release-6.2.6
Browse files Browse the repository at this point in the history
Release 6.2.6
  • Loading branch information
sampaiodiego committed Jun 15, 2023
2 parents b921d86 + 8ade880 commit dfc9f86
Show file tree
Hide file tree
Showing 27 changed files with 1,310 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/silly-stingrays-play.md
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

fix: Frontend crash if IndexedDB is not available, i.e. in Firefox private mode
5 changes: 5 additions & 0 deletions .changeset/tiny-cups-pump.md
@@ -0,0 +1,5 @@
---
'@rocket.chat/release-action': major
---

New action to publish package releases
71 changes: 71 additions & 0 deletions .github/workflows/new-release.yml
@@ -0,0 +1,71 @@
name: Start new release

on:
workflow_dispatch:
inputs:
name:
type: choice
description: Release type
default: next
required: true
options:
- next
- patch
- publish
base-ref:
description: Base version
default: master
required: false

env:
HUSKY: 0

jobs:
new-release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup NodeJS
uses: ./.github/actions/setup-node
with:
node-version: 14.21.3
cache-modules: true
install: true

- uses: dtinth/setup-github-actions-caching-for-turbo@v1

- name: Build
run: yarn build

- name: Start next release
if: ${{ github.event.inputs.name == 'next' }}
uses: ./packages/release-action
with:
action: bump
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Start patch release
if: ${{ github.event.inputs.name == 'patch' }}
uses: ./packages/release-action
with:
action: patch
base-ref: ${{ github.event.inputs.base-ref }}
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish release
if: ${{ github.event.inputs.name == 'publish' }}
uses: ./packages/release-action
with:
action: publish
base-ref: ${{ github.event.inputs.base-ref }}
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39 changes: 39 additions & 0 deletions .github/workflows/publish-release.yml
@@ -0,0 +1,39 @@
name: Publish Final Release

on:
push:
branches:
- master

concurrency: ${{ github.workflow }}-${{ github.ref }}

env:
HUSKY: 0

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup NodeJS
uses: ./.github/actions/setup-node
with:
node-version: 14.21.3
cache-modules: true
install: true

- uses: dtinth/setup-github-actions-caching-for-turbo@v1

- name: Build
run: yarn build

- name: Publish final release
uses: ./packages/release-action
with:
action: publish-final
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Up @@ -92,7 +92,7 @@ export class CachedCollection<T extends object, U = T> extends Emitter<{ changed
}

private async loadFromCache() {
const data = await localforage.getItem<{ version: number; token: unknown; records: unknown[]; updatedAt: Date }>(this.name);
const data = await localforage.getItem<{ version: number; token: unknown; records: unknown[]; updatedAt: Date | string }>(this.name);

if (!data) {
return false;
Expand All @@ -106,6 +106,11 @@ export class CachedCollection<T extends object, U = T> extends Emitter<{ changed
return false;
}

// updatedAt may be a Date or a string depending on the used localForage backend
if (!(data.updatedAt instanceof Date)) {
data.updatedAt = new Date(data.updatedAt);
}

if (Date.now() - data.updatedAt.getTime() >= 1000 * CachedCollection.MAX_CACHE_TIME) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "rocket.chat",
"version": "6.2.5",
"version": "6.2.6",
"description": "Rocket.Chat Monorepo",
"main": "index.js",
"private": true,
Expand Down
1 change: 1 addition & 0 deletions packages/base64/package.json
@@ -1,5 +1,6 @@
{
"name": "@rocket.chat/base64",
"private": true,
"description": "Base64 encoding and decoding; Fork of Meteor's Base64 package",
"version": "1.0.12",
"main": "./dist/base64.js",
Expand Down
1 change: 1 addition & 0 deletions packages/fuselage-ui-kit/package.json
@@ -1,5 +1,6 @@
{
"name": "@rocket.chat/fuselage-ui-kit",
"private": true,
"version": "0.31.16",
"description": "UiKit elements for Rocket.Chat Apps built under Fuselage design system",
"homepage": "https://rocketchat.github.io/Rocket.Chat.Fuselage/",
Expand Down
1 change: 1 addition & 0 deletions packages/random/package.json
@@ -1,5 +1,6 @@
{
"name": "@rocket.chat/random",
"private": true,
"description": "Random number generator and utilities; Fork of Meteor's Random package",
"version": "1.2.1",
"main": "./dist/main.server.js",
Expand Down
4 changes: 4 additions & 0 deletions packages/release-action/.eslintrc.json
@@ -0,0 +1,4 @@
{
"extends": ["@rocket.chat/eslint-config"],
"ignorePatterns": ["**/dist"]
}
1 change: 1 addition & 0 deletions packages/release-action/.gitignore
@@ -0,0 +1 @@
dist/
1 change: 1 addition & 0 deletions packages/release-action/CHANGELOG.md
@@ -0,0 +1 @@
# @rocket.chat/release-action
1 change: 1 addition & 0 deletions packages/release-action/README.md
@@ -0,0 +1 @@
# release-action
18 changes: 18 additions & 0 deletions packages/release-action/action.yml
@@ -0,0 +1,18 @@
name: Changeset release
description: Action to cut and publish releases using changesets

inputs:
action:
description: "The main action to perform: publish, publish-final, bump or patch"
required: true
base-ref:
description: "Base ref to use for the release"
required: false

runs:
using: "node16"
main: "dist/index.js"

branding:
icon: "package"
color: "blue"
30 changes: 30 additions & 0 deletions packages/release-action/package.json
@@ -0,0 +1,30 @@
{
"name": "@rocket.chat/release-action",
"version": "0.0.1",
"private": true,
"scripts": {
"build": "tsc",
"lint": "eslint src",
"lint:fix": "eslint --fix src"
},
"main": "dist/index.js",
"packageManager": "yarn@3.5.1",
"devDependencies": {
"@types/eslint": "^8",
"@types/node": "^16",
"typescript": "^5.1.3"
},
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1",
"@actions/github": "^5.1.1",
"@octokit/plugin-throttling": "^6.0.0",
"@rocket.chat/eslint-config": "workspace:^",
"eslint": "^8.42.0",
"mdast-util-to-string": "2",
"remark-parse": "9",
"remark-stringify": "9",
"semver": "^7.5.1",
"unified": "9"
}
}
97 changes: 97 additions & 0 deletions packages/release-action/src/bumpNextVersion.ts
@@ -0,0 +1,97 @@
import fs from 'fs';
import path from 'path';

import { exec } from '@actions/exec';
import * as core from '@actions/core';
import * as github from '@actions/github';

import { setupOctokit } from './setupOctokit';
import { createNpmFile } from './createNpmFile';
import { getChangelogEntry, updateVersionPackageJson } from './utils';
import { fixWorkspaceVersionsBeforePublish } from './fixWorkspaceVersionsBeforePublish';

export async function bumpNextVersion({
githubToken,
mainPackagePath,
cwd = process.cwd(),
}: {
githubToken: string;
mainPackagePath: string;
cwd?: string;
}) {
const octokit = setupOctokit(githubToken);

// TODO do this only if publishing to npm
await createNpmFile();

// TODO need to check if there is any change to 'main package', if not, there is no need to enter rc
// and instead a normal release of the other packages should be done

// start release candidate
await exec('yarn', ['changeset', 'pre', 'enter', 'rc']);

// bump version of all packages to rc
await exec('yarn', ['changeset', 'version']);

// get version from main package
const mainPackageJsonPath = path.join(mainPackagePath, 'package.json');
// eslint-disable-next-line import/no-dynamic-require, @typescript-eslint/no-var-requires
const { version: newVersion } = require(mainPackageJsonPath);

const mainPackageChangelog = path.join(mainPackagePath, 'CHANGELOG.md');

const changelogContents = fs.readFileSync(mainPackageChangelog, 'utf8');
const changelogEntry = getChangelogEntry(changelogContents, newVersion);
if (!changelogEntry) {
// we can find a changelog but not the entry for this version
// if this is true, something has probably gone wrong
throw new Error('Could not find changelog entry for version newVersion');
}

const prBody = changelogEntry.content;

const finalVersion = newVersion.split('-')[0];

const newBranch = `release-${finalVersion}`;

// update root package.json
core.info('bump main package.json version');
updateVersionPackageJson(cwd, newVersion);

// TODO check if branch exists
await exec('git', ['checkout', '-b', newBranch]);

await exec('git', ['add', '.']);
await exec('git', ['commit', '-m', newVersion]);

core.info('fix dependencies in workspace packages');
await fixWorkspaceVersionsBeforePublish();

await exec('yarn', ['changeset', 'publish']);

await exec('git', ['push', '--force', '--follow-tags', 'origin', `HEAD:refs/heads/${newBranch}`]);

if (newVersion.includes('rc.0')) {
const finalPrTitle = `Release ${finalVersion}`;

core.info('creating pull request');
await octokit.rest.pulls.create({
base: 'master',
head: newBranch,
title: finalPrTitle,
body: prBody,
...github.context.repo,
});
} else {
core.info('no pull request created: release is not the first candidate');
}

core.info('create release');
await octokit.rest.repos.createRelease({
name: newVersion,
tag_name: newVersion,
body: prBody,
prerelease: newVersion.includes('-'),
...github.context.repo,
});
}
26 changes: 26 additions & 0 deletions packages/release-action/src/createNpmFile.ts
@@ -0,0 +1,26 @@
import fs from 'fs';
import fsPromise from 'fs/promises';

import * as core from '@actions/core';

export async function createNpmFile() {
const userNpmrcPath = `${process.env.HOME}/.npmrc`;

if (fs.existsSync(userNpmrcPath)) {
core.info('Found existing user .npmrc file');
const userNpmrcContent = await fsPromise.readFile(userNpmrcPath, 'utf8');
const authLine = userNpmrcContent.split('\n').find((line) => {
// check based on https://github.com/npm/cli/blob/8f8f71e4dd5ee66b3b17888faad5a7bf6c657eed/test/lib/adduser.js#L103-L105
return /^\s*\/\/registry\.npmjs\.org\/:[_-]authToken=/i.test(line);
});
if (authLine) {
core.info('Found existing auth token for the npm registry in the user .npmrc file');
} else {
core.info("Didn't find existing auth token for the npm registry in the user .npmrc file, creating one");
fs.appendFileSync(userNpmrcPath, `\n//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`);
}
} else {
core.info('No user .npmrc file found, creating one');
fs.writeFileSync(userNpmrcPath, `//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`);
}
}

0 comments on commit dfc9f86

Please sign in to comment.