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

evolvedbinary / lwdita / 10f6bf8b-7d86-4391-bcf2-0f64adb1c499

04 Jun 2024 11:25AM UTC coverage: 87.355% (-0.3%) from 87.62%
10f6bf8b-7d86-4391-bcf2-0f64adb1c499

push

circleci

adamretter
[feature] Add a 'yarn build' pre-release check to the release plugin

499 of 604 branches covered (82.62%)

Branch coverage included in aggregate %.

0 of 7 new or added lines in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

1228 of 1373 relevant lines covered (89.44%)

20.92 hits per line

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

18.84
/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 {copyFile, rm} = require('fs/promises');
2✔
9
      const t = require(`typanion`);
2✔
10

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

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

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

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

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

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

81
          // Cleanup after Step 2 - Pre-release testing
NEW
82
          await this.cli.run(['clean'])
×
83

84
          // Step 3 - Increment the versions of all packages (including the project root)
85
          let packageFiles = [];
×
86
          this.context.stdout.write(`3. Running \`yarn version\` to bump versions of all workspaces to ${this.version}...\n`);
×
87
          for (let i = 0; i < project.workspaces.length; i++) {
×
88
            let projectWorkspace = project.workspaces[i];
×
89

90
            if (projectWorkspace.cwd == project.cwd) {
×
91
              await this.cli.run(['version', this.version]);
×
92
            } else {
93
              let projectWorkspaceName = `@${projectWorkspace.manifest.name.scope}/${projectWorkspace.manifest.name.name}`;
×
94
              await this.cli.run(['workspace', projectWorkspaceName, 'version', this.version]);
×
95
            }
96
            packageFiles.push(`${projectWorkspace.cwd}/package.json`);
×
97
          }
98

99
          // Step 4 - git commit the version update.
100
          this.context.stdout.write(`4. git Committing the version update...\n`);
×
101
          await execute('git', ['commit', `--message=[release] Release version: ${this.version}`].concat(packageFiles), executeOptions);
×
102
        
103
          // Step 5 - git tag and sign the release tag.
104
          this.context.stdout.write(`5. git Committing the version update...\n`);
×
105
          await execute('git', ['tag', `--message=[release] Release version: ${this.version}`, '--sign', `v${this.version}`], executeOptions);
×
106
        
107
          // Step 6 - git push the updates.
108
          this.context.stdout.write(`6. git push the version update...\n`);
×
109
          this.context.stdout.write(`6.1. git pushing the branch...\n`);
×
110
          await execute('git', ['push'], executeOptions);
×
111
          this.context.stdout.write(`6.2. git pushing the tag...\n`);
×
112
          await execute('git', ['push', '--tags'], executeOptions);
×
113

114
          // Step 7 - Publish the packages to npm.js.
115
          this.context.stdout.write(`7. Running \`yarn npn publish\` to publish packages to npm.js...\n`);
×
116
          await this.cli.run(['npm', 'login']);
×
117
          for (let i = 0; i < project.workspaces.length; i++) {
×
118
            let projectWorkspace = project.workspaces[i];
×
119

120
            if (projectWorkspace.cwd == project.cwd) {
×
121
              this.context.stdout.write("NOTE: Skipping publish of project root workspace!\n")
×
122
            } else {
123
              // Make a copy of the LICENSE file to the workspace so that it is published as part of the package
124
              await copyFile(`${project.cwd}/LICENSE`, `${projectWorkspace.cwd}/LICENSE`);
×
125

126
              // Publish the workspace package
127
              let projectWorkspaceName = `@${projectWorkspace.manifest.name.scope}/${projectWorkspace.manifest.name.name}`;
×
128
              await this.cli.run(['workspace', projectWorkspaceName, 'npm', 'publish', '--access', 'public']);
×
129

130
              // Remove the copy of the LICENSE file from the workspace
131
              await rm(`${projectWorkspace.cwd}/LICENSE`);
×
132
            }
133
          }
134

135
          this.context.stdout.write(`Released version: ${this.version} OK!\n`);
×
136
        }
137
      }
138
  
139
      return {
2✔
140
        commands: [
141
          ReleaseCommand,
142
        ],
143
      };
144
    },
145
  };
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