Skip to content

Commit

Permalink
Merge pull request #22990 from storybookjs/next-debug
Browse files Browse the repository at this point in the history
Release: Fix minor scripts and workflows
  • Loading branch information
JReinhold authored Jun 8, 2023
2 parents 4678e0c + 1cf6332 commit 2d5e11a
Show file tree
Hide file tree
Showing 29 changed files with 163 additions and 690 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/prepare-patch-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ run-name: Prepare patch PR, triggered by ${{ github.triggering_actor }}
on:
push:
branches:
- next-v2
- next
workflow_dispatch:

env:
Expand Down Expand Up @@ -38,7 +38,11 @@ jobs:
with:
path: |
~/.yarn/berry/cache
key: yarn-v1-${{ hashFiles('scripts/yarn.lock') }}
key: yarn-v1-${{ hashFiles('scripts/yarn.lock') }}-${{ hashFiles('code/yarn.lock') }}
restore-keys: |
yarn-v1-${{ hashFiles('scripts/yarn.lock') }}-${{ hashFiles('code/yarn.lock') }}
yarn-v1-${{ hashFiles('scripts/yarn.lock') }}
yarn-v1
- name: Install Script Dependencies
run: |
Expand Down Expand Up @@ -81,6 +85,10 @@ jobs:
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
yarn release:pick-patches
- name: Install code dependencies
working-directory: .
run: yarn task --task=install --start-from=install

- name: Bump version
id: bump-version
if: steps.unreleased-changes.outputs.has-changes-to-release == 'true'
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/prepare-prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ jobs:
with:
path: |
~/.yarn/berry/cache
key: yarn-v1-${{ hashFiles('scripts/yarn.lock') }}
key: yarn-v1-${{ hashFiles('scripts/yarn.lock') }}-${{ hashFiles('code/yarn.lock') }}
restore-keys: |
yarn-v1-${{ hashFiles('scripts/yarn.lock') }}-${{ hashFiles('code/yarn.lock') }}
yarn-v1-${{ hashFiles('scripts/yarn.lock') }}
yarn-v1
- name: Install Script Dependencies
run: |
Expand Down Expand Up @@ -100,6 +104,10 @@ jobs:
gh run cancel ${{ github.run_id }}
gh run watch ${{ github.run_id }}
- name: Install code dependencies
working-directory: .
run: yarn task --task=install --start-from=install

- name: Bump version
id: bump-version
run: |
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ jobs:
with:
path: |
~/.yarn/berry/cache
key: yarn-v1-${{ hashFiles('scripts/yarn.lock') }}
key: yarn-v1-${{ hashFiles('scripts/yarn.lock') }}-${{ hashFiles('code/yarn.lock') }}
restore-keys: |
yarn-v1-${{ hashFiles('scripts/yarn.lock') }}-${{ hashFiles('code/yarn.lock') }}
yarn-v1-${{ hashFiles('scripts/yarn.lock') }}
yarn-v1
- name: Install script dependencies
run: |
Expand Down
550 changes: 0 additions & 550 deletions .yarn/plugins/@yarnpkg/plugin-version.cjs

This file was deleted.

8 changes: 3 additions & 5 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ installStatePath: ./.yarn/root-install-state.gz

nodeLinker: node-modules

npmPublishAccess: public

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
spec: '@yarnpkg/plugin-version'
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: '@yarnpkg/plugin-workspace-tools'
spec: "@yarnpkg/plugin-workspace-tools"

yarnPath: .yarn/releases/yarn-3.5.1.cjs

npmPublishAccess: 'public'
9 changes: 6 additions & 3 deletions scripts/__mocks__/simple-git.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* eslint-disable no-underscore-dangle */
const mod = jest.createMockFromModule('simple-git');

mod.__getRemotes = jest.fn().mockReturnValue([{name: 'origin', refs: {fetch: 'origin', push: 'origin'}}]);
mod.__getRemotes = jest
.fn()
.mockReturnValue([{ name: 'origin', refs: { fetch: 'origin', push: 'origin' } }]);
mod.__fetch = jest.fn();
mod.__revparse = jest.fn().mockResolvedValue('mockedGitCommitHash');

Expand All @@ -9,7 +12,7 @@ mod.simpleGit = () => {
getRemotes: mod.__getRemotes,
fetch: mod.__fetch,
revparse: mod.__revparse,
}
}
};
};

module.exports = mod;
5 changes: 4 additions & 1 deletion scripts/__mocks__/uuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ const { v5 } = jest.requireActual('uuid');

let seed = 0;

export const v4 = () => v5((seed++).toString(), '6c7fda6d-f92f-4bd2-9d4d-da26a59196a6');
export const v4 = () => {
seed += 1;
return v5(seed.toString(), '6c7fda6d-f92f-4bd2-9d4d-da26a59196a6');
};
2 changes: 2 additions & 0 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/experimental-utils": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"ansi-regex": "^5.0.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^9.1.2",
"boxen": "^5.1.2",
Expand Down Expand Up @@ -133,6 +134,7 @@
"jest-os-detection": "^1.3.1",
"jest-serializer-html": "^7.1.0",
"jest-watch-typeahead": "^2.2.1",
"json5": "^2.2.3",
"junit-xml": "^1.2.0",
"lint-staged": "^10.5.4",
"lodash": "^4.17.21",
Expand Down
34 changes: 20 additions & 14 deletions scripts/release/__tests__/is-pr-frozen.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import path from "path";
import { run as isPrFrozen } from "../is-pr-frozen";
/* eslint-disable no-underscore-dangle */
/* eslint-disable global-require */
import path from 'path';
import { run as isPrFrozen } from '../is-pr-frozen';

// eslint-disable-next-line jest/no-mocks-import
jest.mock('fs-extra', () => require('../../../code/__mocks__/fs-extra'));
jest.mock('../utils/get-github-info');

Expand All @@ -16,40 +19,43 @@ fsExtra.__setMockFiles({
});

describe('isPrFrozen', () => {

beforeEach(() => {
jest.clearAllMocks();
});

it('should return true when PR is frozen', async () => {
getPullInfoFromCommit.mockResolvedValue({
labels: ['freeze']
labels: ['freeze'],
});
await expect(isPrFrozen({patch: false})).resolves.toBe(true);
await expect(isPrFrozen({ patch: false })).resolves.toBe(true);
});

it('should return false when PR is not frozen', async () => {
getPullInfoFromCommit.mockResolvedValue({
labels: []
labels: [],
});
await expect(isPrFrozen({patch: false})).resolves.toBe(false);
await expect(isPrFrozen({ patch: false })).resolves.toBe(false);
});

it('should look for patch PRs when patch is true', async () => {
getPullInfoFromCommit.mockResolvedValue({
labels: []
labels: [],
});
await isPrFrozen({patch: true});
await isPrFrozen({ patch: true });

expect(simpleGit.__fetch).toHaveBeenCalledWith('origin', 'version-from-patch-1.0.0', {'--depth': 1});
expect(simpleGit.__fetch).toHaveBeenCalledWith('origin', 'version-from-patch-1.0.0', {
'--depth': 1,
});
});

it('should look for prerelease PRs when patch is false', async () => {
getPullInfoFromCommit.mockResolvedValue({
labels: []
labels: [],
});
await isPrFrozen({patch: false});
await isPrFrozen({ patch: false });

expect(simpleGit.__fetch).toHaveBeenCalledWith('origin', 'version-from-prerelease-1.0.0', {'--depth': 1});
expect(simpleGit.__fetch).toHaveBeenCalledWith('origin', 'version-from-prerelease-1.0.0', {
'--depth': 1,
});
});
});
6 changes: 3 additions & 3 deletions scripts/release/__tests__/label-patches.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const gitLogMock: LogResult = {
hash: 'some-hash',
date: '2023-06-07T09:45:11+02:00',
message: 'Something else',
refs: 'HEAD -> main-v2',
refs: 'HEAD -> main',
body: '',
author_name: 'Jeppe Reinhold',
author_email: '[email protected]',
Expand All @@ -39,7 +39,7 @@ const gitLogMock: LogResult = {
hash: 'b75879c4d3d72f7830e9c5fca9f75a303ddb194d',
date: '2023-06-07T09:45:11+02:00',
message: 'Merge pull request #55 from storybookjs/fixes',
refs: 'HEAD -> main-v2',
refs: 'HEAD -> main',
body:
'Legal: Fix license\n' +
'(cherry picked from commit 930b47f011f750c44a1782267d698ccdd3c04da3)\n',
Expand Down Expand Up @@ -101,7 +101,7 @@ test('it should label the PR associated with cheery picks in the current branch'
",
{
"input": {
"clientMutationId": "111db3d5-7ad7-5d3b-a8a9-efa7e7e9de57",
"clientMutationId": "7efda802-d7d1-5d76-97d6-cc16a9f3e357",
"labelIds": [
"pick-id",
],
Expand Down
32 changes: 18 additions & 14 deletions scripts/release/generate-pr-description.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable no-continue */
/* eslint-disable @typescript-eslint/naming-convention */
/* eslint-disable no-underscore-dangle */
/* eslint-disable no-console */
import chalk from 'chalk';
import program from 'commander';
Expand Down Expand Up @@ -56,7 +53,12 @@ const LABELS_BY_IMPORTANCE = {
unknown: '❔ Missing Label',
} as const;

const CHANGE_TITLES_TO_IGNORE = [/^bump version on.*/i, /^merge branch.*/i];
const CHANGE_TITLES_TO_IGNORE = [
/^bump version.*/i,
/^merge branch.*/i,
/\[skip ci\]/i,
/\[ci skip\]/i,
];

export const mapToChangelist = ({
changes,
Expand Down Expand Up @@ -116,13 +118,13 @@ export const mapCherryPicksToTodo = ({
}): string => {
const list = commits
.map((commit) => {
const change = changes.find((change) => change.commit === commit.substring(0, 7));
if (!change) {
const foundChange = changes.find((change) => change.commit === commit.substring(0, 7));
if (!foundChange) {
throw new Error(
`Cherry pick commit "${commit}" not found in changes, this should not happen?!`
);
}
return `- [ ] ${change.links.pull}: \`git cherry-pick -m1 -x ${commit}\``;
return `- [ ] ${foundChange.links.pull}: \`git cherry-pick -m1 -x ${commit}\``;
})
.join('\n');

Expand Down Expand Up @@ -174,7 +176,7 @@ export const generateReleaseDescription = ({
${changeList}
${manualCherryPicks ? manualCherryPicks : ''}
${manualCherryPicks || ''}
If you've made any changes doing the above QA (change PR titles, revert PRs), manually trigger a re-generation of this PR with [this workflow](https://github.com/storybookjs/monorepo-release-tooling-prototype/actions/workflows/prepare-prerelease.yml) and wait for it to finish. It will wipe your progress in this to do, which is expected.
Expand Down Expand Up @@ -207,7 +209,7 @@ export const generateNonReleaseDescription = (
${changeList}
${manualCherryPicks ? manualCherryPicks : ''}
${manualCherryPicks || ''}
If you've made any changes (change PR titles, revert PRs), manually trigger a re-generation of this PR with [this workflow](https://github.com/storybookjs/monorepo-release-tooling-prototype/actions/workflows/prepare-prerelease.yml) and wait for it to finish.
Expand Down Expand Up @@ -266,11 +268,13 @@ export const run = async (rawOptions: unknown) => {
})
: generateNonReleaseDescription(
mapToChangelist({ changes, isRelease: false }),
hasCherryPicks ? mapCherryPicksToTodo({
commits: manualCherryPicks,
changes,
verbose,
}) : undefined
hasCherryPicks
? mapCherryPicksToTodo({
commits: manualCherryPicks,
changes,
verbose,
})
: undefined
);

if (process.env.GITHUB_ACTIONS === 'true') {
Expand Down
3 changes: 0 additions & 3 deletions scripts/release/get-current-version.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable no-continue */
/* eslint-disable @typescript-eslint/naming-convention */
/* eslint-disable no-underscore-dangle */
/* eslint-disable no-console */
import chalk from 'chalk';
import { setOutput } from '@actions/core';
Expand Down
3 changes: 0 additions & 3 deletions scripts/release/is-pr-frozen.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable no-continue */
/* eslint-disable @typescript-eslint/naming-convention */
/* eslint-disable no-underscore-dangle */
/* eslint-disable no-console */
import chalk from 'chalk';
import program from 'commander';
Expand Down
3 changes: 0 additions & 3 deletions scripts/release/is-prerelease.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable no-continue */
/* eslint-disable @typescript-eslint/naming-convention */
/* eslint-disable no-underscore-dangle */
/* eslint-disable no-console */
import chalk from 'chalk';
import program from 'commander';
Expand Down
3 changes: 0 additions & 3 deletions scripts/release/is-version-published.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable no-continue */
/* eslint-disable @typescript-eslint/naming-convention */
/* eslint-disable no-underscore-dangle */
/* eslint-disable no-console */
import chalk from 'chalk';
import program from 'commander';
Expand Down
3 changes: 1 addition & 2 deletions scripts/release/label-patches.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-await-in-loop */
import program from 'commander';
import { v4 as uuidv4 } from 'uuid';
import ora from 'ora';
Expand Down Expand Up @@ -33,7 +32,7 @@ export const run = async (_: unknown) => {
spinner.succeed(`Found latest tag: ${latestTag}`);

const spinner2 = ora(`Looking at cherry pick commits since ${latestTag}`).start();
const commitsSinceLatest = await git.log({ from: latestTag });
const commitsSinceLatest = await git.log({ from: latestTag, '--first-parent': null });
console.log(commitsSinceLatest);
const cherryPicked = commitsSinceLatest.all.flatMap((it) => {
const result = it.body.match(/\(cherry picked from commit (\b[0-9a-f]{7,40}\b)\)/);
Expand Down
10 changes: 6 additions & 4 deletions scripts/release/pick-patches.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
/* eslint-disable no-await-in-loop */
import program from 'commander';
import chalk from 'chalk';
Expand Down Expand Up @@ -112,14 +113,15 @@ export const run = async (_: unknown) => {

const failedCherryPicks: string[] = [];

// eslint-disable-next-line no-restricted-syntax
for (const pr of patchPRs) {
const spinner = ora(`Cherry picking #${pr.number}`).start();
const prSpinner = ora(`Cherry picking #${pr.number}`).start();

try {
await git.raw(['cherry-pick', '-m', '1', '-x', pr.mergeCommit]);
spinner.succeed(`Picked: ${formatPR(pr)}`);
prSpinner.succeed(`Picked: ${formatPR(pr)}`);
} catch (pickError) {
spinner.fail(`Failed to automatically pick: ${formatPR(pr)}`);
prSpinner.fail(`Failed to automatically pick: ${formatPR(pr)}`);
logger.error(pickError.message);
const abort = ora(`Aborting cherry pick for merge commit: ${pr.mergeCommit}`).start();
try {
Expand All @@ -130,7 +132,7 @@ export const run = async (_: unknown) => {
logger.error(pickError.message);
}
failedCherryPicks.push(pr.mergeCommit);
spinner.info(
prSpinner.info(
`This PR can be picked manually with: ${chalk.grey(
`git cherry-pick -m1 -x ${pr.mergeCommit}`
)}`
Expand Down
3 changes: 0 additions & 3 deletions scripts/release/publish.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable no-continue */
/* eslint-disable @typescript-eslint/naming-convention */
/* eslint-disable no-underscore-dangle */
/* eslint-disable no-console */
import chalk from 'chalk';
import path from 'path';
Expand Down
Loading

0 comments on commit 2d5e11a

Please sign in to comment.