Skip to content

Commit

Permalink
chore(GGM-30): add semantic release config
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztofbranecki committed Feb 29, 2024
1 parent aec9154 commit 6ead03c
Show file tree
Hide file tree
Showing 3 changed files with 357 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/build-and-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
name: Build and publish package to npm registry

on:
workflow_dispatch:
inputs:
release_tag:
description: |
'Version to manually release'
required: true
type: string
dry_run:
description: |
'Dry run mode build but do not publish'
type: boolean
default: true
workflow_call:
inputs:
release_tag:
description: |
'Version to manually release'
required: true
type: string
dry_run:
description: |
'Dry run mode build but do not publish'
type: boolean
default: true

permissions:
id-token: write # required to use OIDC authentication
contents: write # required to checkout the code from the repo and to perform release
packages: write # required to publish to packages
pull-requests: write

jobs:
publish:
runs-on: ubuntu-latest
name: Package Build & Publish
permissions:
contents: read
packages: write # allow GITHUB_TOKEN to publish packages
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: "20"
- run: cd ./package && npm install
- run: cd ./package && npm run build
- uses: JS-DevTools/npm-publish@v3
with:
package: './package/package.json'
token: ${{ secrets.NPM_TOKEN }}
142 changes: 142 additions & 0 deletions .github/workflows/semantic-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
---
name: Semantic Release

on:
push:
branches:
- release
- beta
paths:
- 'package/**'

permissions:
id-token: write # required to use OIDC authentication
contents: write # required to checkout the code from the repo and to perform release
packages: write # required to publish to packages
pull-requests: write

jobs:
check:
name: GitHub Prerequisites Check
runs-on: ubuntu-latest
outputs:
has_gh_secrets: ${{ steps.check-gh-key-secret.outputs.declared }}
steps:
- name: Check for GitHub Secret availability
id: check-gh-key-secret
shell: bash
run: |
if [[ ! -z "${{ secrets.GITHUB_TOKEN }}" ]]; then
echo "All secrets are declared."
echo "declared=true" >> $GITHUB_OUTPUT;
else
echo "GITHUB_TOKEN secret is missing."
exit 1
fi
check_version_number:
name: Check version
needs: [check]
runs-on: ubuntu-latest
if: |
needs.check.outputs.has_gh_secrets
&& github.actor != 'nektos/act'
permissions:
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests
outputs:
new_release_published: ${{ steps.semantic_dry.outputs.new_release_published }}
new_release_version: ${{ steps.semantic_dry.outputs.new_release_version }}
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get semantic release version
uses: cycjimmy/semantic-release-action@v3
id: semantic_dry
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
dry_run: true
branches: |
[
"+([0-9])?(.{+([0-9]),x}).x",
"release",
{
"name": "beta",
"prerelease": true
}
]
extends: |
[email protected]
extra_plugins: |
@semantic-release/[email protected]
@semantic-release/[email protected]
@semantic-release/[email protected]
@semantic-release/[email protected]
tag_version:
name: Add semantic release
needs: [check, check_version_number]
if: |
needs.check.outputs.has_gh_secrets
&& needs.check_version_number.outputs.new_release_published
&& github.actor != 'nektos/act'
permissions:
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests
runs-on: ubuntu-latest
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false # make sure the release step uses its own credentials
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v3
id: semantic
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
semantic_version: 19
branches: |
[
"+([0-9])?(.{+([0-9]),x}).x",
"release",
{
"name": "beta",
"prerelease": true
}
]
extends: |
[email protected]
extra_plugins: |
@semantic-release/[email protected]
@semantic-release/[email protected]
@semantic-release/[email protected]
@semantic-release/[email protected]
- name: Changelog version
if: steps.semantic.outputs.new_release_published == 'true'
run: |
echo ${{ steps.semantic.outputs.new_release_version }}
outputs:
new_release: ${{ steps.semantic.outputs.new_release_published }}
new_version: ${{ steps.semantic.outputs.new_release_version }}

github-publish:
name: GitHub Build & Publish - ${{ needs.tag_version.outputs.new_version }}
needs: [tag_version]
if: |
needs.check.outputs.has_gh_secrets
&& needs.tag_version.outputs.new_release
uses: ./.github/workflows/build-and-publish.yaml
with:
release_tag: ${{ needs.tag_version.outputs.new_version }}
dry_run: false
secrets: inherit
162 changes: 162 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
"tagFormat": "v${version}",
"initialVersion": "0.1.0",
"branches": [
"release",
{
"name": "beta",
"prerelease": true
}
],
"ci": true,
"debug": true,
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits",
"releaseRules": [
{
"type": "revert",
"release": "patch"
},
{
"type": "docs",
"release": "patch"
},
{
"type": "style",
"release": "patch"
},
{
"type": "chore",
"release": "patch"
},
{
"type": "refactor",
"release": "patch"
},
{
"type": "test",
"release": "patch"
},
{
"type": "build",
"release": "patch"
},
{
"type": "ci",
"release": "patch"
},
{
"type": "improvement",
"release": "minor"
}
],
"parserOpts": {
"noteKeywords": [
"BREAKING CHANGE",
"BREAKING CHANGES"
]
}
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits",
"presetConfig": {
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "perf",
"section": "Performance Improvements"
},
{
"type": "revert",
"section": "Reverts"
},
{
"type": "docs",
"section": "Documentation",
"hidden": false
},
{
"type": "style",
"section": "Styles",
"hidden": false
},
{
"type": "chore",
"section": "Miscellaneous Chores",
"hidden": false
},
{
"type": "refactor",
"section": "Code Refactors",
"hidden": false
},
{
"type": "test",
"section": "Tests",
"hidden": false
},
{
"type": "build",
"section": "Build System",
"hidden": false
},
{
"type": "ci",
"section": "CI/CD",
"hidden": false
},
{
"type": "improvement",
"section": "Improvements",
"hidden": false
}
]
}
}
],
[
"@semantic-release/npm",
{
"npmPublish": false,
"pkgRoot": "./package"
}
],
"@semantic-release/github",
[
"@semantic-release/changelog",
{
"changelogFile": "package/changelogs/CHANGELOG.md"
}
],
[
"@semantic-release/exec",
{
"prepareCmd": "mv package/changelogs/CHANGELOG.md package/changelogs/CHANGELOG-${nextRelease.version}.md;"
}
],
[
"@semantic-release/git",
{
"assets": [
"package/package.json",
"package/changelogs/**",
"package/dist/**"
],
"message": "chore(release): ${nextRelease.version} [skip ci]"
}
]
]
}

0 comments on commit 6ead03c

Please sign in to comment.