Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

semantic-release with support for Github/npm #22

Closed
tburny opened this issue Apr 21, 2024 · 2 comments
Closed

semantic-release with support for Github/npm #22

tburny opened this issue Apr 21, 2024 · 2 comments
Labels
C: new-composer Let's create a new composer

Comments

@tburny
Copy link

tburny commented Apr 21, 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 manuel3108 added enhancement New feature or request C: new-composer Let's create a new composer and removed enhancement New feature or request labels Apr 27, 2024
@manuel3108
Copy link
Member

Relates #18

I don't know how, but I managed to miss that you created two issues. Sorry for that!

Eslint and prettier are currently part of the official create-svelte experience, so I'm not going to focus on this point, although create-svelte is only for the initial setup.

Up to this point I have not thought about integrating editor / deployment tooling, but I think this totally makes sense. As of now, I'm doing an end-to-end testing with all existing composers, which obviously will not work here. So I'm going to need to think about how we can test that stuff (Maybe I can include those thoughts in #7).

@manuel3108
Copy link
Member

Project is now using the svelte-add name again. Issue moved: svelte-add/svelte-add#340

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C: new-composer Let's create a new composer
Projects
None yet
Development

No branches or pull requests

2 participants