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

evolvedbinary / lwdita / 3f7678b7-3878-4b28-a2c4-8913572a432f

04 Jun 2024 11:06AM UTC coverage: 87.62% (+0.006%) from 87.614%
3f7678b7-3878-4b28-a2c4-8913572a432f

push

circleci

adamretter
[bugfix] Fix an issue with copying the LICENSE file in the release plugin

499 of 604 branches covered (82.62%)

Branch coverage included in aggregate %.

1 of 4 new or added lines in 1 file covered. (25.0%)

1228 of 1367 relevant lines covered (89.83%)

21.01 hits per line

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

20.63
/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");
×
72
          await this.cli.run(['lint'])
×
73
          this.context.stdout.write("2.2. Running tests...\n");
×
74
          await this.cli.run(['test'])
×
75

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

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

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

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

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

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

122
              // Remove the copy of the LICENSE file from the workspace
NEW
123
              await rm(`${projectWorkspace.cwd}/LICENSE`);
×
124
            }
125
          }
126

127
          this.context.stdout.write(`Released version: ${this.version} OK!\n`);
×
128
        }
129
      }
130
  
131
      return {
2✔
132
        commands: [
133
          ReleaseCommand,
134
        ],
135
      };
136
    },
137
  };
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