Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discrepancy between actual committed files and logged committed files #508

Open
sorokinvj opened this issue Mar 17, 2024 · 3 comments
Open

Comments

@sorokinvj
Copy link

sorokinvj commented Mar 17, 2024

When running semantic-release with the @semantic-release/git plugin, the log output from semantic-release only shows that two files (CHANGELOG.md and package.json) are being committed. However, the git show command shows that additional files (manifest.json and a zip file in the dist directory) are also being committed (which is the goal author tries to achieve)

Steps to reproduce:

  1. Run semantic-release with the @semantic-release/git plugin.
  2. Check the log output from semantic-release.
  3. Run the git show command.

Expected behavior:

The log output from semantic-release should accurately reflect all the files that are being committed.

Actual behavior:

The log output from semantic-release only shows that two files are being committed, even though more files are actually being committed.

Plugin logs Actually committed
CHANGELOG.md, package.json CHANGELOG.md, package.json, dist/jobLander-0.5.10.zip, manifest.json

Additional context:

.releaserc

{
  "branches": [
    "main"
  ],
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "@semantic-release/changelog",
    [
      "semantic-release-chrome",
      {
        "extensionId": "hafhjepjihcimcljkdphpinannbdmnhf",
        "asset": "./dist/jobLander-${nextRelease.version}.zip",
        "skipPrepare": true,
        "target": "draft"
      }
    ],
    [
      "@semantic-release/git",
      {
        "assets": [
          "package.json",
          "CHANGELOG.md",
          "dist/jobLander-${nextRelease.version}.zip",
          "manifest.json"
        ],
        "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
      }
    ]
  ],
  "prepare": [
    "@semantic-release/changelog",
    {
      "path": "@semantic-release/exec",
      "cmd": "node ./scripts/prepare-publish.js ${nextRelease.version}"
    },
    "@semantic-release/git"
  ]
}

prepare-publish.js

#!/usr/bin/env node
// file: scripts/prepare-publish.js
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable no-console */
const fs = require('fs');
const { execSync } = require('child_process');
const path = require('path');
const rootDir = path.join(__dirname, '..');

// Get the new version from the command line arguments
const newVersion = process.argv[2];
if (!newVersion) {
  console.error('Please provide a version number as a command line argument.');
  process.exit(1);
}
console.log(`Preparing release ${newVersion}...`);

try {
  // Read and update the package.json file
  const packageJsonPath = path.join(rootDir, 'package.json');
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
  packageJson.version = newVersion;
  fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
  console.log('Updated version in package.json to', newVersion);
} catch (error) {
  console.error('An error occurred while updating package.json:', error);
  process.exit(1);
}

try {
  // Read and update the manifest.json file
  const manifestJsonPath = path.join(rootDir, 'manifest.json');
  const manifestJson = JSON.parse(fs.readFileSync(manifestJsonPath, 'utf8'));
  manifestJson.version = newVersion;
  fs.writeFileSync(manifestJsonPath, JSON.stringify(manifestJson, null, 2));
  console.log('Updated version in manifest.json to', newVersion);
  execSync('git add manifest.json'); // THIS IS IMPORTANT
  console.log('Added manifest.json to Git');
} catch (error) {
  console.error('An error occurred while updating manifest.json:', error);
  process.exit(1);
}

try {
  // Build the app
  execSync('yarn build');
  console.log('Build completed');
} catch (error) {
  console.error('An error occurred during the build:', error);
  process.exit(1);
}

try {
  // Zip the dist folder
  execSync(`zip -r ./dist/jobLander-${newVersion}.zip ./extension`);
  console.log('Zipped the /extension folder');
  execSync(`git add ./dist/jobLander-${newVersion}.zip`);  // THIS IS IMPORTANT
  console.log(`Added ./dist/jobLander-${newVersion}.zip to Git`);
} catch (error) {
  console.error('An error occurred while zipping the dist folder:', error);
  process.exit(1);
}

console.log('Preparation is finished, continue with publishing...');
git show --name-only
commit 661dcfc4424c8b7deafd58148be0d5464265a136 (HEAD -> main, tag: v0.5.10, origin/main, origin/HEAD)
Author: semantic-release-bot <[email protected]>
Date:   Sun Mar 17 22:47:23 2024 +0000

    chore(release): 0.5.10 [skip ci]
    
    ## [0.5.10](https://github.com/sorokinvj/JobLander-extension/compare/v0.5.9...v0.5.10) (2024-03-17)
    
    ### Bug Fixes
    
    * correct path in releaserc ([128ddec](https://github.com/sorokinvj/JobLander-extension/commit/128ddecb7210c78cccee00a8669482da74ee2b0c))

CHANGELOG.md
dist/jobLander-0.5.10.zip
manifest.json
package.json
@travi
Copy link
Member

travi commented Mar 18, 2024

Why do you have a prepareblock in addition to plugins in your config? Does the behavior change if you remove that?

@sorokinvj
Copy link
Author

sorokinvj commented Mar 23, 2024

Why do you have a prepareblock in addition to plugins in your config? Does the behavior change if you remove that?

Because its the only way to run my script before git plugin, which I need to commit files back to the repo @travi

Ah, and because chrome plugin makes zip file from the build dir at prepare stage, so I am overriding the whole prepare to prevent this.

@travi
Copy link
Member

travi commented Mar 23, 2024

Configure your plugins within the plugins list. Configured plugins execute their lifecycle hooks in the order the plugins are declared in the plugins list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants