Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto version bump #202

Merged
merged 40 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1dbab8c
feat: auto version bump
sameer-coder Dec 9, 2022
93a41be
chore: action yml updated
sameer-coder Dec 9, 2022
648820b
chore: corrections in yaml
sameer-coder Dec 9, 2022
5b59f68
chore: correct action condition
sameer-coder Dec 9, 2022
82793fa
chore: minor changes
sameer-coder Dec 12, 2022
f2ae228
chore: query to get commits changed
sameer-coder Dec 12, 2022
6e426f5
chore: readme update
sameer-coder Dec 12, 2022
c52f849
chore: added tests
sameer-coder Dec 12, 2022
83b7707
chore: more tests added
sameer-coder Dec 12, 2022
d26d977
chore: coverage improved
sameer-coder Dec 12, 2022
83a1fa1
chore: lint fix
sameer-coder Dec 12, 2022
3dd744b
chore: bump logic triggered from action yaml
sameer-coder Dec 13, 2022
b594ed5
chore: readability changes
sameer-coder Dec 13, 2022
99c81ec
chore: fixed tests
sameer-coder Dec 14, 2022
188352f
chore: more tests
sameer-coder Dec 14, 2022
df340ee
chore: using conventional commits parser
sameer-coder Dec 15, 2022
8e6fdee
chore: removed unnecessary default params
sameer-coder Dec 15, 2022
2c3bace
chore: console.log removed
sameer-coder Dec 15, 2022
a35fd85
chore: lint fix
sameer-coder Dec 15, 2022
12be444
chore: using conventionalcommits npm package
sameer-coder Dec 19, 2022
f6ca3bd
chore: removed unused npm package
sameer-coder Dec 19, 2022
c9627d1
Merge branch 'main' of https://github.com/nearform/optic-release-auto…
sameer-coder Jan 3, 2023
75d68e8
chore: added support for base tag when auto bump
sameer-coder Jan 5, 2023
92ef817
chore: corrected fetch depth
sameer-coder Jan 5, 2023
edda212
chore: tests fixed
sameer-coder Jan 5, 2023
932c2c8
tests updated
sameer-coder Jan 6, 2023
70ee1c2
chore: fetch-depth test
sameer-coder Jan 6, 2023
563d2d4
chore: restoring fetch-depth
sameer-coder Jan 6, 2023
86bb339
chore: base-tag is no longer a required field
sameer-coder Jan 6, 2023
68874d7
chore: fix tests again
sameer-coder Jan 6, 2023
7eac288
chore: only fetch full commit history if auto bump
sameer-coder Jan 6, 2023
747e234
chore: logging
sameer-coder Jan 6, 2023
7e77ce0
chore: tag correction
sameer-coder Jan 6, 2023
6ca93d4
chore: sorting tags
sameer-coder Jan 6, 2023
56033fb
chore: fixed bug with fetching tags
sameer-coder Jan 6, 2023
370fdc6
chore: readme updated
sameer-coder Jan 9, 2023
ea1fbb4
chore: readme updated
sameer-coder Jan 10, 2023
29fe874
Merge branch 'main' of https://github.com/nearform/optic-release-auto…
sameer-coder Jan 12, 2023
95c79bc
chore: coverage 100
sameer-coder Jan 12, 2023
9cd8957
chore: pr updates
sameer-coder Jan 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ on:
default: 'patch'
type: choice
options:
- auto
- patch
- minor
- major
baseTag:
description: 'base release tag'
pull_request:
types: [closed]

Expand All @@ -29,3 +32,4 @@ jobs:
semver: ${{ github.event.inputs.semver }}
sync-semver-tags: 'true'
build-command: npm ci
base-tag: ${{ github.event.inputs.baseTag }}
sameer-coder marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ on:
default: "patch"
type: choice
options:
- auto
- patch
- minor
- major
Expand Down Expand Up @@ -88,6 +89,10 @@ When you merge this PR:

When you close the PR without merging it: nothing will happen.

## Using 'auto' bump version option
If you choose the "auto" option for semver version updates, the action will attempt to determine the new version number based on the commit messages. For this option to work, the repository must use the conventional commits standard. You can refer the [conventional commits documention](https://www.conventionalcommits.org/en/v1.0.0/)
for more information.

## Using branches filter

In case you want to reduce the amount of the relase workflow runs, you can configure a workflow to run only for pull requests that target specific branches.
Expand Down Expand Up @@ -193,7 +198,7 @@ Please note that in case of a prerelease the `sync-semver-tags` input will be tr
| Input | Required | Description |
| --- | --- | --- |
| `github-token` | No | This is your GitHub token, it's [already available](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret) to your GitHub action |
| `semver` | Yes | The version you want to bump (`patch|minor|major`). |
| `semver` | Yes | The version you want to bump (`auto|patch|minor|major`). |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't actually up to date. when we introduced support for prereleases we included more options. maybe, instead of listing them, we should just link the npm docs page

| `commit-message`| No | The commit message template. The keyword `{version}` will be replaced with the new version. (_Default: `Release {version}`_) |
| `npm-token` | No | This is your Npm Publish token. Read [how to create](https://docs.npmjs.com/creating-and-viewing-access-tokens#creating-tokens-on-the-website) access tokens. Required only if you want to release to Npm. If you omit this, no Npm release will be published. |
| `optic-url` | No | URL if you have a custom application that serves OTP. <br /> (_Default: <Optic service URL>_) |
Expand All @@ -209,6 +214,7 @@ Please note that in case of a prerelease the `sync-semver-tags` input will be tr
| `artifact-path`| No | Set this input to the distribution folder or file you want to add as the main asset for your release. It will be downloadable from the release page and a preview of it will be available in the pull request. |
| `version-prefix` | No | A prefix to apply to the version number, which reflects in the tag and GitHub release names. <br /> (_Default: 'v'_) |
| `prerelease-prefix` | No | A prefix to apply to the prerelease version number. |
| `base-tag` | No | Base release tag to use for analysing commits when semver `auto` option is enabled. |
## Motivation

*Why do I need this when I can create Npm automation tokens?*
Expand Down
22 changes: 14 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ inputs:
prerelease-prefix:
description: 'A prefix to apply to the prerelease version number'
required: false
base-tag:
sameer-coder marked this conversation as resolved.
Show resolved Hide resolved
description: 'Base release tag to use for analysing commits when auto version bump is enabled'
required: false

runs:
using: 'composite'
Expand All @@ -86,12 +89,15 @@ runs:
shell: 'bash'

- name: Version bump
uses: actions/github-script@v6
id: version-bump
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
npm version --no-git-tag-version --preid=${{ inputs.prerelease-prefix }} ${{ inputs.semver }}
echo "PACKAGE_VERSION=$(echo $(node -p "require('./package.json').version"))" >> $GITHUB_OUTPUT
shell: 'bash'
with:
result-encoding: string
github-token: ${{ inputs.github-token }}
script: |
const { bumpVersion } = require('${{ github.action_path }}/dist/index.js')
return await bumpVersion({ inputs: ${{ toJSON(inputs) }} })

- name: Build the package
if: ${{ inputs.build-command }}
Expand All @@ -107,14 +113,14 @@ runs:
with:
github-token: ${{ inputs.github-token }}
script: |
const script = require('${{ github.action_path }}/dist/index.js')
await script({ github, context, inputs: ${{ toJSON(inputs) }}, packageVersion: "${{ steps.version-bump.outputs.PACKAGE_VERSION }}" })
const { runAction } = require('${{ github.action_path }}/dist/index.js')
await runAction({ github, context, inputs: ${{ toJSON(inputs) }}, packageVersion: ${{ steps.version-bump.outputs.result }} })

- name: Release the package
uses: actions/github-script@v6
if: ${{ github.event_name == 'pull_request' }}
with:
github-token: ${{ inputs.github-token }}
script: |
const script = require('${{ github.action_path }}/dist/index.js')
await script({ github, context, inputs: ${{ toJSON(inputs) }} })
const { runAction } = require('${{ github.action_path }}/dist/index.js')
await runAction({ github, context, inputs: ${{ toJSON(inputs) }} })
30 changes: 30 additions & 0 deletions dist/commit.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
*{{#if scope}} **{{scope}}:**
{{~/if}} {{#if subject}}
{{~subject}}
{{~else}}
{{~header}}
{{~/if}}

{{~!-- commit link --}}{{~#if hash}} {{#if @root.linkReferences~}}
([{{shortHash}}]({{commitUrlFormat}}))
{{~else}}
{{~shortHash}}
{{~/if}}{{~/if}}

{{~!-- commit references --}}
{{~#if references~}}
, closes
{{~#each references}} {{#if @root.linkReferences~}}
[
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}{{this.prefix}}{{this.issue}}]({{issueUrlFormat}})
{{~else}}
{{~#if this.owner}}
{{~this.owner}}/
{{~/if}}
{{~this.repository}}{{this.prefix}}{{this.issue}}
{{~/if}}{{/each}}
{{~/if}}

Empty file added dist/footer.hbs
Empty file.
9 changes: 9 additions & 0 deletions dist/header.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## {{#if @root.linkCompare~}}
[{{version}}]({{compareUrlFormat}})
{{~else}}
{{~version}}
{{~/if}}
{{~#if title}} "{{title}}"
{{~/if}}
{{~#if date}} ({{date}})
{{/if}}
Loading