semantic-release keeps committing dist and docs to repo despite .gitignore

130 Views Asked by At

Im using semantic-release to build and publish an NPM package. The build process creates a dist\ and docs\ directory which is properly set to be ignored in the .gitignore. Once the build stage is done, I then use the upload-artifact github action to pass them to the release stage. On the release stage I just retrieve the artifact and run npx semantic-release to publish the package.

This all works great, the package is correctly published and it has all the files I expect. However, semantic-release commits the dist\ and docs\ into the repo despite them being in the .gitignore. Im sure its just a configuration step Im missing. Any thoughts?

semantic-release config (in package.json):

"release": {
    "branches": [
        {
            "name": "main"
        },
        {
            "name": "develop",
            "channel": "beta",
            "prerelease": "beta"
        }
    ],
    "plugins": [
        "@semantic-release/commit-analyzer",
        "@semantic-release/release-notes-generator",
        [
            "@semantic-release/changelog",
            {
                "changelogFile": "CHANGELOG.md"
            }
        ],
        "@semantic-release/npm",
        "@semantic-release/github",
        [
            "@semantic-release/git",
            {
                "assets": [
                    "CHANGELOG.md",
                    "dist/**",
                    "docs/**"
                ],
                "message": "chore(release): set `package.json` to ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
            }
        ]
    ]
},

Heres a screenshot of the semantic-release-bot committing dist\ and docs\ back to the repo (along with changelog, which is expected)

commit

Relevant part of .gitignore

## docs
/docs/

# build
/_site/
/dist/
/out-tsc/
1

There are 1 best solutions below

0
Anton Komarov On

Update ur file (i mean its .releaserc.js) to

"release": {
    "branches": [
        {
            "name": "main"
        },
        {
            "name": "develop",
            "channel": "beta",
            "prerelease": "beta"
        }
    ],
    "plugins": [
        "@semantic-release/commit-analyzer",
        "@semantic-release/release-notes-generator",
        [
            "@semantic-release/changelog",
            {
                "changelogFile": "CHANGELOG.md"
            }
        ],
        "@semantic-release/npm",
        "@semantic-release/github",
        [
            "@semantic-release/git",
            {
                assets: ['CHANGELOG.md', 'package.json', 'package-lock.json'],
                "message": "chore(release): set `package.json` to ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
            }
        ]
    ]
},

(update "@semantic-release/git".assets) when u put "dist/**", "docs/**" to "@semantic-release/git".assets semantic release add them to commit

u can see example of deploy semantic release with typescript here

https://github.com/JS-AK/example-automatic-deploy-ts-app-to-npm-with-scope