Skip to content

Commit

Permalink
fix: prerelease tags (#1223)
Browse files Browse the repository at this point in the history
## Proposed change

<!-- Please include a summary of the changes and the related issue.
Please also include relevant motivation and context. List any
dependencies that is required for this change. -->

## Related issues

- 🐛 Fixes #(issue)
- 🚀 Feature #(issue)

<!-- Please make sure to follow the contributing guidelines on
https://github.com/amadeus-digital/Otter/blob/main/CONTRIBUTING.md -->
  • Loading branch information
mrednic-1A authored Jan 16, 2024
2 parents cc8fa31 + 1b156e2 commit 36803c7
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ jobs:
uses: ./tools/github-actions/new-version
with:
defaultBranch: main
defaultBranchPrereleaseName: alpha
releaseBranchRegExp: 'release\/(0|[1-9]\d*)\.(0|[1-9]\d*)(\.0-(?:alpha|beta|next|rc))?$'
defaultBranchPrereleaseName: prerelease
releaseBranchRegExp: 'release\/(0|[1-9]\d*)\.(0|[1-9]\d*)(\.0-(?:next|prerelease|rc))?$'
- name: Create release
if: github.event_name != 'pull_request' && github.event_name != 'merge_group'
run: gh release create v${{ steps.newVersion.outputs.nextVersionTag }} --generate-notes ${{ contains( steps.newVersion.outputs.nextVersionTag, '-' ) && '--prerelease' || '' }} --target ${{ github.ref_name }}
Expand Down
4 changes: 2 additions & 2 deletions tools/github-actions/cascading/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## Overview

This plugin is meant to implement the Bitbucket cascading mechanism on GitHub.
For the moment, the branching model supported is the following one : release/Maj.min[.0-alpha|beta|next|rc] and a default branch from your choice.
For the moment, the branching model supported is the following one : release/Maj.min[.0-next|prerelease|rc] and a default branch from your choice.
This pattern is restrictive on purpose, to prevent any issue where some non-release branches could match as well.

## Task options
Expand All @@ -32,7 +32,7 @@ The cascading task is logging a lot of information, don't hesitate to have a loo
## Usage example

```yaml
- name: Cascading
- name: Cascading
id: cascading
uses: AmadeusITGroup/otter/tools/github-actions/cascading@8
with:
Expand Down
8 changes: 4 additions & 4 deletions tools/github-actions/cascading/src/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ describe('helpers', () => {
expect(sortBranches(['release/1.2', 'release/2.2', 'release/3.2'])).toEqual(['release/1.2', 'release/2.2', 'release/3.2']);
expect(sortBranches(['release/1.2', 'release/0.1', 'release/3.1', 'release/0.4']))
.toEqual(['release/0.1', 'release/0.4', 'release/1.2', 'release/3.1']);
expect(sortBranches(['release/3.0.0-next', 'release/2.5.0-alpha', 'release/1.2', 'release/2.4', 'release/0.1']))
.toEqual(['release/0.1', 'release/1.2', 'release/2.4', 'release/2.5.0-alpha', 'release/3.0.0-next']);
expect(sortBranches(['release/3.0.0-next', 'release/3.0.0-prerelease', 'release/2.5.0-prerelease', 'release/1.2', 'release/2.4', 'release/0.1']))
.toEqual(['release/0.1', 'release/1.2', 'release/2.4', 'release/2.5.0-prerelease', 'release/3.0.0-next', 'release/3.0.0-prerelease']);
});

it('formatGitBranchOutput', () => {
const fakeOutput = ' remotes/origin/test/3.2 \n remotes/origin/release/0.1.0-test \n remotes/origin/release/0.1-test \n ' +
'remotes/origin/feature/whatever \n remotes/origin/release/0.1 \n remotes/origin/release/1.2 \n remotes/origin/bugfix/whatever ' +
'\r\n remotes/origin/release/2.4 \n remotes/origin/release/2.5.0-alpha \r\n remotes/origin/release/3.0.0-next';
expect(extractBranchesFromGitOutput(fakeOutput)).toEqual(['release/0.1', 'release/1.2', 'release/2.4', 'release/2.5.0-alpha', 'release/3.0.0-next']);
'\r\n remotes/origin/release/2.4 \n remotes/origin/release/2.5.0-prerelease \r\n remotes/origin/release/3.0.0-rc \r\n remotes/origin/release/3.0.0-next';
expect(extractBranchesFromGitOutput(fakeOutput)).toEqual(['release/0.1', 'release/1.2', 'release/2.4', 'release/2.5.0-prerelease', 'release/3.0.0-rc', 'release/3.0.0-next']);
});

it('Extract packages name from multiline package json content', () => {
Expand Down
4 changes: 2 additions & 2 deletions tools/github-actions/cascading/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function sortBranches(branches: string[]) {
}

/**
* Extract just the branches matching the release/min.maj[.0-alpha|beta|next|rc] format
* Extract just the branches matching the release/min.maj[.0-next|prerelease|rc] format
* @param gitOutput
*/
export function extractBranchesFromGitOutput(gitOutput: string) {
Expand All @@ -35,7 +35,7 @@ export function extractBranchesFromGitOutput(gitOutput: string) {
.replace(/ /g, '')
.replace('remotes/origin/', '')
)
.filter((val) => /release\/(0|[1-9]\d*)\.(0|[1-9]\d*)(\.0-(alpha|beta|next|rc))?$/.test(val));
.filter((val) => /release\/(0|[1-9]\d*)\.(0|[1-9]\d*)(\.0-(next|prerelease|rc))?$/.test(val));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tools/github-actions/new-version/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: 'New version'
description: 'Compute the next-version of your branch, based on repository tags'
inputs:
defaultBranchPrereleaseName:
description: 'Default branch pre-release tag (eg. alpha)'
description: 'Default branch pre-release tag (eg. prerelease)'
required: false
defaultBranch:
description: 'If your branching model relies on a default branch that is not a release branch (such as master or develop), you can specify its name here so the task will compute versions for builds happening on that branch.'
description: 'If your branching model relies on a default branch that is not a release branch (such as main or develop), you can specify its name here so the task will compute versions for builds happening on that branch.'
required: false
defaultBranchVersionMask:
description: 'You can specify a version mask if you want to bypass the default mechanism of the task when it comes to default branch version computation.'
Expand All @@ -15,7 +15,7 @@ inputs:
releaseBranchRegExp:
description: 'Versioned release branch regular expression'
required: false
default: 'release\/(0|[1-9]\d*)\.(0|[1-9]\d*)(\.0-(?:alpha|beta|next|rc))?$'
default: 'release\/(0|[1-9]\d*)\.(0|[1-9]\d*)(\.0-(?:next|prerelease|rc))?$'
outputs:
nextVersionTag:
description: 'Next version Tag'
Expand Down
10 changes: 5 additions & 5 deletions tools/github-actions/new-version/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This task computes new version candidates based on the repository tags as well as the branch on which it is executed.
It supports in terms of branching model:

* By default, release branches named ``release/Major.Minor[.0-alpha|beta|next|rc]`` (configurable through releaseBranchRegExp)
* By default, release branches named ``release/Major.Minor[.0-next|prerelease|rc]`` (configurable through releaseBranchRegExp)
* One default branch that can be parametrised (``master``, ``develop``, ...)

If the plugin doesn't support the current branch it raises a warning that says that the version cannot be computed.
Expand All @@ -21,9 +21,9 @@ If run on a compatible branch, the plug-in will compute the next version as foll
* If no tag is found, the plug-in returns ``Major.Minor.0``
* If run on a pull request build, it doesn't increment the patch version but instead concatenate ``-pr.buildId`` to the latest, or to ``Major.Minor.0``

### On a pre-release branch ``release/Major.Minor.0-(alpha|beta|next|rc)``
### On a pre-release branch ``release/Major.Minor.0-(next|prerelease|rc)``

It behaves the same as above, but instead of producing ``Major.Minor.0`` it would produce ``release/Major.Minor.0-(alpha|beta|next|rc).0``
It behaves the same as above, but instead of producing ``Major.Minor.0`` it would produce ``release/Major.Minor.0-(next|prerelease|rc).0``

### On a default branch

Expand All @@ -46,6 +46,6 @@ See [Action specifications](action.yml) directly for more information about the
uses: AmadeusITGroup/otter/tools/github-actions/new-version@9
with:
defaultBranch: main
defaultBranchPrereleaseName: alpha
releaseBranchRegExp: 'release\/(0|[1-9]\d*)\.(0|[1-9]\d*)(\.0-(?:alpha|beta|next|rc))?$'
defaultBranchPrereleaseName: prerelease
releaseBranchRegExp: 'release\/(0|[1-9]\d*)\.(0|[1-9]\d*)(\.0-(?:next|prerelease|rc))?$'
```
4 changes: 2 additions & 2 deletions tools/github-actions/new-version/src/new-version.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('New Version', () => {
baseBranch: '2.6',
isPullRequest: false,
prPreReleaseTag: 'pr',
releaseBranchRegExp: new RegExp(/release\/(0|[1-9]\d*)\.(0|[1-9]\d*)(\.0-(alpha|beta|next|rc))?$/)
releaseBranchRegExp: new RegExp(/release\/(0|[1-9]\d*)\.(0|[1-9]\d*)(\.0-(next|prerelease|rc))?$/)
};

const defaultTags = ['0.10.0', '2.6.0', '3.1.5', '3.2.4', '3.2.5.0', 'whatever', '3.3.0-alpha.0', '3.3.0-alpha.0', '3.3.0-rc.0'];
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('New Version', () => {
isPullRequest: false,
defaultBranch: 'develop',
prPreReleaseTag: 'pr',
releaseBranchRegExp: new RegExp(/release\/(0|[1-9]\d*)\.(0|[1-9]\d*)(\.0-(alpha|beta|next|rc))?$/)
releaseBranchRegExp: new RegExp(/release\/(0|[1-9]\d*)\.(0|[1-9]\d*)(\.0-(next|prerelease|rc))?$/)
};

it('should compute release versions correctly', () => {
Expand Down
2 changes: 1 addition & 1 deletion tools/github-actions/new-version/src/new-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class NewVersion {
// If release branch, we filter all versions that do not satisfy the branch name to exclude 3.6.0-alpha.2 when building branch release/3.6 for example
parsedSortedTags = parsedSortedTags.filter((parsedTag) => semver.satisfies(parsedTag, `~${versionMask}`));
} else {
const releaseTags = [...this.defaultBranchPrereleaseName ? [this.defaultBranchPrereleaseName] : [], 'alpha', 'beta', 'rc'];
const releaseTags = [...this.defaultBranchPrereleaseName ? [this.defaultBranchPrereleaseName] : [], 'prerelease', 'rc'];
parsedSortedTags = parsedSortedTags.filter((parsedTag) =>
parsedTag.prerelease.length === 0 || releaseTags.includes(`${parsedTag.prerelease[0]}`)
);
Expand Down

0 comments on commit 36803c7

Please sign in to comment.