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

semantic-release with support for Github/npm #340

Open
manuel3108 opened this issue May 5, 2024 · 1 comment
Open

semantic-release with support for Github/npm #340

manuel3108 opened this issue May 5, 2024 · 1 comment

Comments

@manuel3108
Copy link
Member

manuel3108 commented May 5, 2024

Website

https://semantic-release.gitbook.io/semantic-release

Documentation

https://semantic-release.gitbook.io/semantic-release

Integration summary

  1. Install the following dependencies: semantic-releae, @semantic-release/commit-analyzer, @semantic-release/npm, @semantic-release/github, husky and lint-staged (see notes below)
  2. modify package.json and the following section:
        "release": {
                "plugins": [
                        "@semantic-release/commit-analyzer",
                        "@semantic-release/release-notes-generator",
                        "@semantic-release/github"
                ],
                "branches": [
                        "main",
                        "next"
                ]
        },
        "lint-staged": {
                "**/*.{js,jsx,ts,tsx,html,css,json}": [
                        "pnpm run format"
                ]
        }
}
  1. Also add the following scripts to package.json:
                "lint": "prettier --check . && eslint .", 
                "lint-staged": "lint-staged",
                "format": "prettier --write .",
                // setup husky
                "prepare": "husky",
                // ensure everyone has commit hooks set up
                "postinstall": "pnpm run prepare",
                // actual semantic-release script 
                "release": "semantic-release"
  1. Add the following to `.husky/pre-commit'
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# dlx downloads "lint-staged" every time, resulting in long commit delays
# when internet connection is slow
# Solution: Install as dev dependency and run as target from package.json instead
pnpm run lint-staged
  1. Add the following to Github actions (further configuration for repository permissions is required)
      - name: Release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          # Publishing to NPM is not necessary for websites
          # NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: pnpm run release

Further details

Explanation

This request is augmenting the Github pages composer.

As a note ahead, the formatting and linting might be a seperate composer. It is just how I did it.

Setting up a Continuous Integration, Delivery and Deployment pipeline can take several hours per repository.

Using Conventional Commits and semantic-release can help to fully automated the process, including

  • automated semantic versioning
  • tagging in Git
  • publishing a release to npm or Github pages
  • Release notes on Github

The composer should take over additional tasks to ensure a consistent and productive development experience:

  • check format of commit messages using husky
  • Lint and fix any changed files using lint-staged for consistent formatting using prettier (shipped with sveltekit)

Options

Ask for

  • github and npm plug-ins of semantic-releae
  • ask for lint-staged, and husky

Configure Github Actions

The Github Actions are already configured to build and deploy the project to Github Pages.

Therefor you need to set two permissions in the settings of your repository:

  • In your browser, open the repository settings
  • Go to the Actions section
  • In the Workflow permissions, select Read and write permissions
  • Check Allow GitHub Actions to create and approve pull requests
@manuel3108
Copy link
Member Author

Initially brought up by @tburny in svelte-compose/svelte-compose#22

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

No branches or pull requests

1 participant