Skip to content

Commit

Permalink
chore(release): implement semantic-release from GH actions (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
danguilherme authored Apr 30, 2024
1 parent b9fd5b1 commit 0056958
Show file tree
Hide file tree
Showing 10 changed files with 4,234 additions and 47 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: 'Build & Publish'
on:
push:
branches:
- '**'
tags-ignore:
- '**'
permissions:
contents: write
jobs:
release:
name: 'Test, Lint, Build and Release'
runs-on: ubuntu-latest
concurrency:
group: test:${{ github.event_name }}:${{ github.ref }}
cancel-in-progress: true
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Enable Corepack
run: corepack enable
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Install dependencies
run: yarn install --immutable
# Test
- name: 🧪 Test
run: yarn test
# Lint
- name: 📐 Lint
run: yarn lint
# Build
- name: 📦 Build
run: yarn build
# Release
- name: 🚀 Semantic Release
id: release
uses: cycjimmy/semantic-release-action@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
DEBUG: ${{ secrets.ACTIONS_STEP_DEBUG == 'true' && 'semantic-release:*' || '' }}
with:
semantic_version: 22.0.12 # semantic-release version, same as in package.json
- name: 📝 Add release notes to build summary
if: steps.release.outputs.new_release_published == 'true'
run: |
NEW_RELEASE_VERSION=${{ steps.release.outputs.new_release_version }}
echo "# New package version published: \`v$NEW_RELEASE_VERSION\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "yarn add uno-engine@$NEW_RELEASE_VERSION" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
yarn exec ts-node build/append-to-file.ts $GITHUB_STEP_SUMMARY <<"END_OF_CONTENT"
${{ steps.release.outputs.new_release_notes }}
END_OF_CONTENT
- name: ∅ No new package published
if: steps.release.outputs.new_release_published == 'false'
run: |
echo "# No new version published" >> $GITHUB_STEP_SUMMARY
33 changes: 33 additions & 0 deletions .github/workflows/validate-pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'Validate PR Title'
on:
pull_request:
types: [opened, reopened, synchronize, edited]
jobs:
lint-pr-title:
name: 'Lint PR Title'
runs-on: ubuntu-latest
concurrency:
group: lint-pr-title:${{ github.event_name }}:${{ github.ref }}
cancel-in-progress: true
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Enable Corepack
run: corepack enable
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Install dependencies
run: yarn install --immutable
- name: Lint
run: |
yarn lint:commit-message <<"EOM"
${{ github.event.pull_request.title }}
${{ github.event.pull_request.body }}
EOM
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.18.2
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

7 changes: 1 addition & 6 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
{
"recommendations": [
"eg2.tslint",
"streetsidesoftware.code-spell-checker"
]
}
{}
35 changes: 35 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Contributing Guide

## Branching

Use `develop` as the base branch when starting development. Follow our usual standard for branch names:

- `feature/*` for new features.
- `bugfix/*` for bug fixes.
- `chore/*` for non-functional changes.

## Committing

This repo uses [semantic-release](https://github.com/semantic-release/semantic-release) and [conventional commit messages](https://conventionalcommits.org) so prefix your commits with the appropriate change type if you want your changes to appear in [release notes](CHANGELOG.md):

- `feat:` when implementing a new feature.
- `fix:` when implementing a bug fix.
- `chore:` when making changes that do not affect the library functionality.
"Chore" commits do not generate a new release.

When introducing a breaking change, add what has changed in the footer of the comment in the format `BREAKING CHANGE: what has changed`.
[Check out examples in the documentation.](https://www.conventionalcommits.org/en/v1.0.0/#examples)

## Pull Requests

After done with your development, open a pull request to `main`.

Pull requests are merged with the ["Squash and merge" option](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/about-pull-request-merges#squash-and-merge-your-commits), so that the commit history is clean and the commit messages are meaningful. This means that the PR title will be used as the commit summary, thus it must follow the [conventional commit message format described above](#committing). In case of a breaking change, add a `!` after the type (e.g. `feat!: ...` or `fix(Player)!: ...`), and add the breaking change description in the end of the PR description.

## Releasing Changes

Releases are done automatically as soon as changes are merged to main. Keep an eye in the [Release action](https://github.com/spread-ai/machina/actions/workflows/release.yml) to follow the status.

### Build & Bundle

A new version of the library is released when changes are merged to `main`. The release process will build and bundle the library, and publish it to npm.
36 changes: 36 additions & 0 deletions build/append-to-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';

const [, fileLocation, fileName] = process.argv;

if (!fileName) {
const command = `ts-node-esm ${path.relative(process.cwd(), fileLocation)}`;

console.error('Usage:');
console.error(`\t$ ${command} <file-name>`);
console.error('');
console.error('Example:');
console.error(`\t$ echo "more contents!" >> ${command} ./release-notes.md`);
console.error(`\t$ ${command} $GITHUB_STEP_SUMMARY <<"EOF"`);
console.error(`\t multi-line`);
console.error(`\t content`);
console.error(`\t EOF`);
process.exit(1);
}

const releaseNotesLines: string[] = [];

process.stdin.on('data', data => {
releaseNotesLines.push(data.toString());
});

process.stdin.on('end', () => {
const directory = path.dirname(fileName);

if (!fs.existsSync(directory)) {
fs.mkdirSync(directory, { recursive: true });
}

fs.appendFileSync(fileName, releaseNotesLines.join(os.EOL), 'utf-8');
});
67 changes: 62 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{
"name": "uno-engine",
"version": "0.1.1-alpha",
"version": "0.0.0",
"description": "Uno game implementation in JavaScript",
"homepage": "https://github.com/danguilherme/uno#readme",
"main": "dist/main.js",
"scripts": {
"build:web": "webpack --config webpack.config.js",
"build": "yarn run build:ts && yarn run tslint",
"build": "yarn run build:ts && yarn run lint",
"build:ts": "tsc --declaration",
"build:ts:watch": "tsc -w",
"tslint": "tslint -c tslint.json -p tsconfig.json",
"lint": "tslint -c tslint.json -p tsconfig.json",
"test": "jest --coverage --verbose",
"test:watch": "yarn test --watchAll",
"prepublish": "yarn build"
"semantic-release": "semantic-release",
"lint:commit-message": "commitlint --help-url https://github.com/danguilherme/uno/blob/main/CONTRIBUTING.md#committing"
},
"keywords": [
"uno",
Expand All @@ -34,14 +35,70 @@
"shuffle": "^0.2.2"
},
"devDependencies": {
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.1",
"@types/events": "^1.2.0",
"@types/jest": "^23.1.0",
"chai": "^3.5.0",
"jest": "^23.1.0",
"semantic-release": "22.0.12",
"ts-jest": "^22.4.6",
"tslint": "^5.10.0",
"typescript": "^2.9.2",
"typescript": "^5.4.5",
"webpack": "^2.2.1"
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"release": {
"branches": [
"+([0-9])?(.{+([0-9]),x}).x",
"main",
"next",
"next-major",
{
"name": "beta",
"prerelease": true
},
{
"name": "alpha",
"prerelease": true
}
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits"
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits"
}
],
"@semantic-release/npm",
"@semantic-release/github",
[
"@semantic-release/changelog",
{
"changelogFile": "CHANGELOG.md"
}
],
[
"@semantic-release/git",
{
"assets": [
"CHANGELOG.md"
]
}
]
]
},
"packageManager": "[email protected]"
}
9 changes: 2 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@
"outDir": "dist",
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*",
"src/types/*"
]
"*": ["node_modules/*", "src/types/*"]
}
},
"include": [
"src/**/*"
]
"include": ["src/**/*", "build/**/*"]
}
Loading

0 comments on commit 0056958

Please sign in to comment.