semantic-release / semantic-release/git

Discrepancy between actual committed files and logged committed files

Open
#508 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
339
Forks
75
Avg merge
5h 15m
Merged PRs (30d)
6

Description

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 <semantic-release-bot@martynus.net>
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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the release using the shown .releaserc and prepare-publish.js, then compare the @semantic-release/git plugin log with git show --name-only. Trace how the configured assets and files staged by the preparation script are collected and reported. Done means the log lists CHANGELOG.md, package.json, manifest.json, and the generated dist zip.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, javascript, node.js
Domain
release
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.