-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: actions to publish stable and alpha
Conventional commits Commitlint
- Loading branch information
1 parent
564f3a8
commit ba5568f
Showing
11 changed files
with
769 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
npx --no -- commitlint --edit "$1" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@factorialco:registry=https://npm.pkg.github.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default { extends: ['@commitlint/config-conventional'] }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.