• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

evolvedbinary / lwdita / 3cad5200-3c1b-4bce-b7e8-c60fa5be664f

04 Jun 2024 10:50AM UTC coverage: 87.614% (-2.2%) from 89.811%
3cad5200-3c1b-4bce-b7e8-c60fa5be664f

push

circleci

web-flow
Merge pull request #174 from evolvedbinary/release/prep

Add Release Plugin and Instructions for Performing a Release

499 of 604 branches covered (82.62%)

Branch coverage included in aggregate %.

18 of 62 new or added lines in 3 files covered. (29.03%)

1227 of 1366 relevant lines covered (89.82%)

21.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

19.35
/plugin-release.js
1
module.exports = {
1✔
2
    name: `plugin-addition`,
3
    factory: require => {
4
      const {BaseCommand, WorkspaceRequiredError} = require(`@yarnpkg/cli`);
2✔
5
      const {Configuration, Project} = require('@yarnpkg/core');
2✔
6
      const {execute} = require('@yarnpkg/shell');
2✔
7
      const {Command, Option} = require(`clipanion`);
2✔
8
      const t = require(`typanion`);
2✔
9

10
      const semver2Regex = "(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:\\-([1-9A-Za-z-][0-9A-Za-z-]*(?:\\.[1-9A-Za-z-][0-9A-Za-z-]*)*))?(?:\\+([1-9A-Za-z-][0-9A-Za-z-]*(?:\\.[1-9A-Za-z-][0-9A-Za-z-]*)*))?";
2✔
11
      const yarnAutoVersionsRegex = "(major|minor|patch)";
2✔
12
  
13
      class ReleaseCommand extends BaseCommand {
14
        static paths = [[`release`]];
2✔
15
  
16
        // Show descriptive usage for a --help argument passed to this command
17
        static usage = Command.Usage({
2✔
18
          description: `Publish a new release`,
19
          details: `
20
            This command will create a new release for the project, which involves the following steps:
21
            1. Check project status - Requires no unstaged changes, and no un-pushed commits.
22
            2. Pre-release testing - Executes the \`lint\` and \`test\` scripts.
23
            3. Update the version numbers of all packages.
24
            4. git commit the version update.
25
            5. git tag and sign the release tag.
26
            6. git push the updates - Version commit and tag.
27
            7. Publish the packages to npm.js.
28
          `,
29
          examples: [
30
            [
31
                `Release the next major version`,
32
                `yarn release major`,
33
            ],
34
            [
35
                `Release the next version as 2.1.0`,
36
                `yarn release 2.1.0`,
37
            ]
38
        ],
39
        });
40
  
41
        version = Option.String({
1✔
42
            validator: t.matchesRegExp(new RegExp("^" + yarnAutoVersionsRegex + "|(?:" + semver2Regex + ")$"))
43
        });
44
        // b = Option.String({validator: t.isNumber()});
45
  
46
        async execute() {
NEW
47
          const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
×
NEW
48
          const {project, workspace} = await Project.find(configuration, this.context.cwd);
×
49

NEW
50
          if (!workspace) {
×
NEW
51
            throw new WorkspaceRequiredError(project.cwd, this.context.cwd);
×
52
          }
53

NEW
54
          this.context.stdout.write(`Preparing to release version: ${this.version}...\n`);
×
55

NEW
56
          let executeOptions = {"cwd": project.cwd};
×
57

58
          // Step 1. Check project status - requires no unstaged changes, and no un-pushed commits 
59
          // TODO(AR) figure out how to capture stdout from the git commands below and check the content
NEW
60
          this.context.stdout.write("1. Checking project status...\n");
×
NEW
61
          this.context.stdout.write("1.1. Checking for git 'main' branch...\n");
×
62
          //   await execute('git', ['branch', '--show-current'], executeOptions);
NEW
63
          this.context.stdout.write("1.2. Checking for unstaged changes...\n");
×
64
          //   await execute('git', ['status', '--porcelain', '--untracked-files=no'], executeOptions);
NEW
65
          this.context.stdout.write("1.3. Checking for un-pushed commits...\n");
×
66
          //   await execute('git', ['log', 'origin/main..HEAD'], [], executeOptions);
67

68
          // Step 2. Pre-release testing - Executes the `lint` and `test` scripts
NEW
69
          this.context.stdout.write("2. Performing pre-release testing...\n");
×
NEW
70
          this.context.stdout.write("2.1. Performing lint...\n");
×
NEW
71
          await this.cli.run(['lint'])
×
NEW
72
          this.context.stdout.write("2.2. Running tests...\n");
×
NEW
73
          await this.cli.run(['test'])
×
74

75
          // Step 3 - Increment the versions of all packages (including the project root)
NEW
76
          let packageFiles = [];
×
NEW
77
          this.context.stdout.write(`3. Running \`yarn version\` to bump versions of all workspaces to ${this.version}...\n`);
×
NEW
78
          for (let i = 0; i < project.workspaces.length; i++) {
×
NEW
79
            let projectWorkspace = project.workspaces[i];
×
80

NEW
81
            if (projectWorkspace.cwd == project.cwd) {
×
NEW
82
              await this.cli.run(['version', this.version]);
×
83
            } else {
NEW
84
              let projectWorkspaceName = `@${projectWorkspace.manifest.name.scope}/${projectWorkspace.manifest.name.name}`;
×
NEW
85
              await this.cli.run(['workspace', projectWorkspaceName, 'version', this.version]);
×
86
            }
NEW
87
            packageFiles.push(`${projectWorkspace.cwd}/package.json`);
×
88
          }
89

90
          // Step 4 - git commit the version update.
NEW
91
          this.context.stdout.write(`4. git Committing the version update...\n`);
×
NEW
92
          await execute('git', ['commit', `--message=[release] Release version: ${this.version}`].concat(packageFiles), executeOptions);
×
93
        
94
          // Step 5 - git tag and sign the release tag.
NEW
95
          this.context.stdout.write(`5. git Committing the version update...\n`);
×
NEW
96
          await execute('git', ['tag', `--message=[release] Release version: ${this.version}`, '--sign', `v${this.version}`], executeOptions);
×
97
        
98
          // Step 6. git push the updates.
NEW
99
          this.context.stdout.write(`6. git push the version update...\n`);
×
NEW
100
          this.context.stdout.write(`6.1. git pushing the branch...\n`);
×
NEW
101
          await execute('git', ['push'], executeOptions);
×
NEW
102
          this.context.stdout.write(`6.2. git pushing the tag...\n`);
×
NEW
103
          await execute('git', ['push', '--tags'], executeOptions);
×
104

105
          // Step 7. Publish the packages to npm.js.
NEW
106
          this.context.stdout.write(`7. Running \`yarn npn publish\` to publish packages to npm.js...\n`);
×
NEW
107
          await this.cli.run(['npm', 'login']);
×
NEW
108
          for (let i = 0; i < project.workspaces.length; i++) {
×
NEW
109
            let projectWorkspace = project.workspaces[i];
×
110

NEW
111
            if (projectWorkspace.cwd == project.cwd) {
×
NEW
112
              this.context.stdout.write("NOTE: Skipping publish of project root workspace!")
×
113
            } else {
114
              // Make a copy of the LICENSE file to the workspace so that it is published as part of the package
NEW
115
              await execute('cp' [`${project.cwd}/LICENSE`, projectWorkspace.cwd]);
×
116

NEW
117
              let projectWorkspaceName = `@${projectWorkspace.manifest.name.scope}/${projectWorkspace.manifest.name.name}`;
×
NEW
118
              await this.cli.run(['workspace', projectWorkspaceName, 'npm', 'publish', '--access', 'public']);
×
119

120
              // Remove the copy of the LICENSE file from the workspace
NEW
121
              await execute('rm' [`${projectWorkspace.cwd}/LICENSE`]);
×
122
            }
123
          }
124

NEW
125
          this.context.stdout.write(`Released version: ${this.version} OK!\n`);
×
126
        }
127
      }
128
  
129
      return {
2✔
130
        commands: [
131
          ReleaseCommand,
132
        ],
133
      };
134
    },
135
  };
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc