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

evolvedbinary / lwdita / 68773b77-654c-4ff1-a10c-5163f967ad58

04 Sep 2024 09:14AM UTC coverage: 90.182% (-1.0%) from 91.185%
68773b77-654c-4ff1-a10c-5163f967ad58

Pull #262

circleci

marmoure
[bugfix] rename processCode to existCode
Pull Request #262: [feature] assure that each external command exists with success code

594 of 692 branches covered (85.84%)

Branch coverage included in aggregate %.

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

1 existing line in 1 file now uncovered.

1537 of 1671 relevant lines covered (91.98%)

58.02 hits per line

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

14.61
/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
UNCOV
60
          this.context.stdout.write("1. Checking project status...\n");
×
61
          this.context.stdout.write("1.1. Checking for git 'main' branch...\n");
×
62
          //   await execute('git', ['branch', '--show-current'], executeOptions);
63
          this.context.stdout.write("1.2. Checking for unstaged changes...\n");
×
64
          //   await execute('git', ['status', '--porcelain', '--untracked-files=no'], executeOptions);
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
69
          this.context.stdout.write("2. Performing pre-release testing...\n");
×
70
          await this.cli.run(['build']);
×
71
          await this.cli.run(['lint']);
×
72
          await this.cli.run(['test']);
×
73
          // this.context.stdout.write("2.1. Performing lint...\n");
74
          // await this.cli.run(['clean'])
75
          // await this.cli.run(['lint'])
76
          // this.context.stdout.write("2.2. Performing build...\n");
77
          // await this.cli.run(['clean'])
78
          // await this.cli.run(['build'])
79
          // this.context.stdout.write("2.3. Running tests...\n");
80
          // await this.cli.run(['clean'])
81
          // await this.cli.run(['test'])
82

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

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

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

101
          // process exist code for the last command
NEW
102
          let exitCode = 0;
×
103

104
          // Step 4 - git commit the version update.
105
          this.context.stdout.write(`4. git Committing the version update...\n`);
×
NEW
106
          exitCode = await execute('git', ['commit', `--message=[release] Release version: ${this.version}`].concat(packageFiles), executeOptions);
×
NEW
107
          if (exitCode !== 0) {
×
NEW
108
            this.context.stdout.write(`Error: git commit failed with code: ${exitCode}\n`);
×
NEW
109
            return;
×
110
          } else {
NEW
111
            this.context.stdout.write(`git commit OK!\n`);
×
112
          } 
113

114
          // Step 5 - git tag and sign the release tag.
115
          this.context.stdout.write(`5. git Committing the version update...\n`);
×
NEW
116
          exitCode = await execute('git', ['tag', `--message=[release] Release version: ${this.version}`, '--sign', `v${this.version}`], executeOptions);
×
NEW
117
          if (exitCode !== 0) {
×
NEW
118
            this.context.stdout.write(`Error: git tag failed with code: ${exitCode}\n`);
×
NEW
119
            return;
×
120
          } else {
NEW
121
            this.context.stdout.write(`git tag OK!\n`);
×
122
          }
123
          
124
          // Step 6 - git push the updates.
125
          this.context.stdout.write(`6. git push the version update...\n`);
×
126
          this.context.stdout.write(`6.1. git pushing the branch...\n`);
×
NEW
127
          exitCode = await execute('git', ['push'], executeOptions);
×
NEW
128
          if (exitCode !== 0) {
×
NEW
129
            this.context.stdout.write(`Error: git push failed with code: ${exitCode}\n`)
×
NEW
130
            return;
×
131
          } else {
NEW
132
            this.context.stdout.write(`git push OK!\n`);
×
133
          }
134

NEW
135
          this.context.stdout.write(`6.2. git pushing the tag...\n`);
×
NEW
136
          exitCode = await execute('git', ['push', '--tags'], executeOptions);
×
NEW
137
          if (exitCode !== 0) {
×
NEW
138
            this.context.stdout.write(`Error: git push tags failed with code: ${exitCode}\n`);
×
NEW
139
            return;
×
140
          } else {
NEW
141
            this.context.stdout.write(`git push tags OK!\n`);
×
142
          }
143
          
144
          // Step 7 - Publish the packages to npm.js.
145
          this.context.stdout.write(`7. Running \`yarn npn publish\` to publish packages to npm.js...\n`);
×
146
          await this.cli.run(['npm', 'login']);
×
147
          for (let i = 0; i < project.workspaces.length; i++) {
×
148
            let projectWorkspace = project.workspaces[i];
×
149

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

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

160
              // Remove the copy of the LICENSE file from the workspace
161
              await rm(`${projectWorkspace.cwd}/LICENSE`);
×
162
            }
163
          }
164

165
          this.context.stdout.write(`Released version: ${this.version} OK!\n`);
×
166
        }
167

168
        async catch(error) {
NEW
169
          throw error;
×
170
        }
171
      }
172
  
173
      return {
2✔
174
        commands: [
175
          ReleaseCommand,
176
        ],
177
      };
178
    },
179
  };
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