Skip to content

Commit

Permalink
feat(action-release): add semantic release action
Browse files Browse the repository at this point in the history
  • Loading branch information
JoffreyPlouvier committed Feb 28, 2023
1 parent 7965bdd commit dd6a851
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 0 deletions.
42 changes: 42 additions & 0 deletions actions/release/semantic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Release: Semantic

## Behavior

Apply semantic relase n specified commit.

## Usage

```yaml
jobs:
sem-ver:
runs-on: ubuntu-latest
steps:
- name: "Checkout Code"
uses: "actions/checkout@v3"
with:
persist-credentials: false

- name: "Semantic release"
uses: "meero-com/github-actions-shared-workflows/actions/release/semantic@main"
with:
github-token: ${{ secrets.API_TOKEN_GITHUB }}
npm-token: ${{ secrets.NPM_TOKEN }}
```
Beware of using a `@ref` (`@main` in the example above) which suits your stability requirements in your workflow:

* Use `@main` if you always want to use the latest version of the workflow.
* Use `@<tag>` if you wan to use a specific frozen version of the workflow.

## Protected repositories/branches

To operate on protected branches you must pass a github Personal Access Token as github-token.
AND
Avoid persisting credentials as part of actions/checkout@v3 by setting the parameter persist-credentials: false.

```yaml
- name: "Checkout Code"
uses: "actions/checkout@v3"
with:
persist-credentials: false
```
41 changes: 41 additions & 0 deletions actions/release/semantic/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: "Advance or create tag"
description: "Advance or create tag"

inputs:
github-token:
description: The GitHub token used to create an authenticated client
required: true
npm-token:
description: The GitHub token used to create an authenticated client
required: true
branch:
description: The branch on which releases should happen
default: "main"
required: false

runs:
using: "composite"
steps:
- uses: actions/setup-node@v3
with:
node-version: '16.x'

- name: Semantic Release
uses: cycjimmy/semantic-release-action@v3
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
NPM_TOKEN: ${{ inputs.npm-token }}
with:
branch: ${{ inputs.branch }}
dry_run: false
extends: |
meero-com/github-actions-shared-workflows
extra_plugins: |
@semantic-release/commit-analyzer@9.0.2
@semantic-release/release-notes-generator@10.0.3
@semantic-release/changelog@6.0.1
@semantic-release/github@8.0.6
@semantic-release/git@10.0.1
@semantic-release/exec@6.0.3
@semantic-release/npm@9.0.1
conventional-changelog-conventionalcommits@4.3.0
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "meero-com-github-actions-shared-workflows",
"version": "1.0.0",
"description": "Shared workflows for Meero GitHub Actions runs.",
"main": "release.config.js",
"files": [
"release.config.js"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/meero-com/github-actions-shared-workflows.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/meero-com/github-actions-shared-workflows/issues"
},
"homepage": "https://github.com/meero-com/github-actions-shared-workflows#readme"
}
97 changes: 97 additions & 0 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
module.exports = {
ci: true,
debug: false,
dryRun: false,
// eslint-disable-next-line no-template-curly-in-string
tagFormat: "from-remote:v${version}",
branches: [
// stable
{ name: 'main' },
],
plugins: [
/**
* analyze commits with conventional-changelog
* ref: https://github.com/semantic-release/commit-analyzer#readme
*/
[
"@semantic-release/commit-analyzer",
{
preset: "conventionalcommits",
releaseRules: [
{ type: "ci", release: "patch" },
{ type: "build", release: "patch" },
],
},
],
/**
* generate changelog content with conventional-changelog
* ref: https://github.com/semantic-release/release-notes-generator#readme
*/
[
"@semantic-release/release-notes-generator",
{
preset: "conventionalcommits",
presetConfig: {
types: [
{ type: 'feat', section: 'Features' },
{ type: 'feature', section: 'Features' },
{ type: 'fix', section: 'Bug Fixes' },
{ type: 'perf', section: 'Performance Improvements' },
{ type: 'revert', section: 'Reverts' },
{ type: 'chore', section: 'Miscellaneous Chores' },
{ type: 'refactor', section: 'Code Refactoring' },
// hidden CHANGELOG sections
{ type: 'docs', section: 'Documentation', hidden: true },
{ type: 'style', section: 'Styles', hidden: true },
{ type: 'test', section: 'Tests', hidden: true },
{ type: 'build', section: 'Build System', hidden: true },
{ type: 'ci', section: 'Continuous Integration', hidden: true },
],
},
},
],
/**
* create or update a changelog file
* ref: https://github.com/semantic-release/changelog#readme
*/
[
"@semantic-release/changelog",
{
changelogFile: "CHANGELOG.md",
},
],
/**
* Export version on a file
*/
[
"@semantic-release/exec",
{
verifyReleaseCmd: "echo \"${nextRelease.version}\" > version"
},
],
/**
* update package.json version
* ref: https://github.com/semantic-release/npm#readme
*/
[
"@semantic-release/npm",
{
npmPublish: false,
},
],
/**
* publish a GitHub release and comment on released PR/Issues
* ref: https://github.com/semantic-release/github#readme
*/
[
"@semantic-release/github",
{
assets: [
{ path: "CHANGELOG.md", label: "CHANGELOG.md" },
{ path: "package.json", label: "package.json" },
],
successComment: false,
},
],
],
};

0 comments on commit dd6a851

Please sign in to comment.