Skip to content

Commit

Permalink
chore: actions to publish stable and alpha
Browse files Browse the repository at this point in the history
Conventional commits
Commitlint
  • Loading branch information
sergiocarracedo committed Feb 25, 2025
1 parent 564f3a8 commit 52df9fc
Show file tree
Hide file tree
Showing 11 changed files with 769 additions and 81 deletions.
24 changes: 24 additions & 0 deletions .github/actions/setup-node-pnpm/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 'Setup Node and pnpm'
description: 'Setup Node.js and pnpm, install dependencies and build'
inputs:
node-version:
description: 'Node.js version'
required: false
default: '20.x'

runs:
using: "composite"
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
registry-url: 'https://registry.npmjs.org'

- name: Install pnpm
run: npm install -g pnpm
shell: bash

- name: Install dependencies
run: pnpm install
shell: bash
81 changes: 81 additions & 0 deletions .github/workflows/build-and-publish-alpha.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Build and publish [ALPHA]

on:
issue_comment:
types: [ created ]
pull_request:
types: [ opened, synchronize ]

jobs:
##################
# Alpha versions #
##################
publish-alpha:
if: |
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
contains(github.event.comment.body, 'build')) ||
github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
packages: write

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- uses: ./.github/actions/setup-node-pnpm

- name: Build
run: pnpm build

# For PRs: Publish alpha version
- name: Version and publish alpha
run: |
# Get lastest version from package.json
CURRENT_VERSION=$(node -p "require('./package.json').version")
PR_NUMBER=${{ github.event.pull_request.number }}
COMMIT-SHA="${{ github.sha }}"
# Create alpha version
ALPHA_VERSION="${CURRENT_VERSION}-alpha.pr${PR_NUMBER}.CI-${COMMIT_SHA}"
# Update package.json version
pnpm version $ALPHA_VERSION --no-git-tag-version
# Publish alpha version to registry
pnpm publish --tag alpha
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Remove old alpha versions
run: |
# Get the alpha versions and their publish dates
ALPHA_INFO=$(npm view $PACKAGE_NAME time --json | jq 'to_entries | map(select(.key | contains("-alpha"))) | map({version: .key, date: .value})')
CURRENT_DATE=$(date +%s)
REMOVE_DAYS=5
# 5 days in seconds
REMOVE_DAYS_IN_SECONDS=$((REMOVE_DAYS * 24 * 60 * 60))
# Process each alpha version
echo "$ALPHA_INFO" | jq -c '.[]' | while read -r VERSION_DATA; do
VERSION=$(echo "$VERSION_DATA" | jq -r '.version')
PUBLISH_DATE=$(echo "$VERSION_DATA" | jq -r '.date')
PUBLISH_DATE_SECONDS=$(date -d "$PUBLISH_DATE" +%s)
DIFF_SECONDS=$((CURRENT_DATE - PUBLISH_DATE_SECONDS))
if [ $DIFF_SECONDS -gt $REMOVE_DAYS_IN_SECONDS ]; then
echo "Removing ($VERSION) published more than $FIVE_DAYS days ago"
npm unpublish "${PACKAGE_NAME}@${VERSION}" --force || true
fi
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
44 changes: 44 additions & 0 deletions .github/workflows/build-and-publish-stable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build and publish [STABLE]

on:
push:
branches:
- main

jobs:
release-please:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- uses: google-github-actions/release-please-action@v4
id: release
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: node

publish-npm:
needs: release-please
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
if: ${{ needs.release-please.outputs.release_created }}

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.repository.default_branch }}

- uses: ./.github/actions/setup-node-pnpm

- name: Build
run: pnpm build

- name: Publish to registry
run: pnpm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

1 change: 1 addition & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx --no -- commitlint --edit "$1"
Empty file added .husky/pre-commit
Empty file.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@factorialco:registry=https://npm.pkg.github.com
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default { extends: ['@commitlint/config-conventional'] };
54 changes: 54 additions & 0 deletions docs/development/release-and-versioning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Versioning

This project is following the [Semantic Versioning](https://semver.org/) specification with automatic version bumping
based in [convention commits](https://www.conventionalcommits.org/en/v1.0.0/).

## Release process

### Stable versions

When a PR is merged into the `main` branch, the CI will automatically will check the commit messages, bump the version
in consequence and publish a new version of the package to the github package registry.

### Experimental (alpha) versions

When a PR is created any commit into the PR will trigger the build and publish process, but the version will be marked
as
`alpha` and the version will be `x.y.z-alpha.<pr-number>-<commit-sha>`. Where the `pr-number` is the number of the PR
and the commit sha is the sha of the commit that triggered the build.

Those versions are not meant to be used in production, but to be tested and reviewed by the team.

Those version are ephemeral and will be deleted after the PR is closed of after some time (TBD).

## Conventional Commits

The Conventional Commits specification is a lightweight convention on top of commit messages. This convention
dovetails with SemVer, by describing the features, fixes, and breaking changes made in commit messages.

The commit message should be structured as follows:

```
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
```

The commit contains the following structural elements, to communicate intent to the consumers of your library:

- **fix**: a commit of the type fix patches a bug in your codebase (this correlates with PATCH in Semantic Versioning).
- **feat**: a commit of the type feat introduces a new feature to the codebase (this correlates with MINOR in Semantic
Versioning).
- **BREAKING CHANGE**: a commit that has a footer BREAKING CHANGE:, or appends a ! after the type/scope, introduces a
breaking API change (correlating with MAJOR in Semantic Versioning). A BREAKING CHANGE can be part of commits of any
type.
- types other than fix: and feat: are allowed, for example build:, chore:, ci:, docs:, style:, refactor:, perf:, test:,
and others. will not trigger a new version.

[Read more about Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#examples)




6 changes: 4 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
`factorial-one` is a set of component, hooks, utilities used as foundations for the factorial's app

- [Getting started](./getting-started.md)
- [Local Development](development/development.md)
- [Using factorial-one without build it](development/using-factorial-one-source.md)
- Development
- [Local Development](development/development.md)
- [Using factorial-one without build it](development/using-factorial-one-source.md)
- [Release and Versioning](development/release-and-versioning)
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
"tsc": "tsc --noEmit",
"vitest": "vitest run",
"vitest:watch": "vitest dev",
"vitest:ci": "vitest run --reporter=dot"
"vitest:ci": "vitest run --reporter=dot",
"prepare": "husky"
},
"peerDependencies": {
"@hookform/resolvers": "^3.9.0",
Expand Down Expand Up @@ -125,6 +126,8 @@
},
"devDependencies": {
"@chromatic-com/storybook": "^3.2.3",
"@commitlint/cli": "^19.7.1",
"@commitlint/config-conventional": "^19.7.1",
"@emoji-mart/data": "^1.2.1",
"@emoji-mart/react": "^1.1.1",
"@emotion/is-prop-valid": "^1.3.1",
Expand Down Expand Up @@ -162,10 +165,11 @@
"@typescript-eslint/parser": "^8.24.1",
"@vitejs/plugin-react": "^4.3.4",
"autoprefixer": "^10.4.20",
"chalk": "^5.4.1",
"axe-playwright": "^2.1.0",
"chalk": "^5.4.1",
"chromatic": "^11.25.2",
"consola": "^3.4.0",
"dotenv": "^16.4.7",
"emoji-mart": "^5.6.0",
"eslint": "^9.21.0",
"eslint-plugin-react": "^7.37.4",
Expand All @@ -174,6 +178,7 @@
"eslint-plugin-storybook": "^0.11.3",
"globals": "^16.0.0",
"http-server": "^14.1.1",
"husky": "^9.1.7",
"jsdom": "^26.0.0",
"lodash": "^4.17.21",
"npm-run-all": "^4.1.5",
Expand All @@ -192,8 +197,7 @@
"vite": "^6.1.1",
"vite-plugin-dts": "4.3.0",
"vite-plugin-lib-inject-css": "^2.2.1",
"vitest": "^3.0.5",
"dotenv": "^16.4.7"
"vitest": "^3.0.5"
},
"optionalDependencies": {
"@rollup/rollup-linux-x64-gnu": "^4.34"
Expand Down
Loading

0 comments on commit 52df9fc

Please sign in to comment.