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

Dart Pubspec Support #46

Merged
merged 3 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/continuous-delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

- name: Tag
id: tag
uses: issue-ops/semver@v0.3.2
uses: issue-ops/semver@v1.0.0
with:
manifest-path: package.json
workspace: ${{ github.workspace }}
Expand Down
52 changes: 30 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ type of manifest file located. This action currently supports the following:

| Language | Manifest File |
| -------- | ---------------- |
| Dart | `pubspec.yaml` |
| Node.js | `package.json` |
| Python | `pyproject.toml` |
| Python | `setup.cfg` |
| Python | `setup.py` |
| | `setup.cfg` |
| | `setup.py` |
| Java | `pom.xml` |
| _Other_ | `.version` |

Expand All @@ -29,17 +30,19 @@ Once a version has been located, this action automatically creates or updates
the following tags to point to the specified `ref`, depending on if this is a
prerelease version or not.

| Prerelease | Tag |
| ---------- | --------------------------------------- |
| Yes | `v<major>.<minor>.<patch>-<prerelease>` |
| No | `v<major>.<minor>.<patch>` |
| | `v<major>.<minor>` |
| | `v<major>` |
| Prerelease | Tag |
| ---------- | ----------------------------------------------- |
| Yes | `v<major>.<minor>.<patch>-<prerelease>+<build>` |
| | `v<major>.<minor>.<patch>-<prerelease>` |
| No | `v<major>.<minor>.<patch>+<build>` |
| | `v<major>.<minor>.<patch>` |
| | `v<major>.<minor>` |
| | `v<major>` |

> [!NOTE]
>
> Currently build metadata is not supported. If this is something you'd like to
> see available, [create an issue](https://github.com/issue-ops/semver/issues)!
> Build tags are only created if build metadata is provided/inferred from the
> version string.

## Setup

Expand Down Expand Up @@ -111,24 +114,29 @@ jobs:
## Outputs

The action outputs the following (assuming the version in the manifest file is
`1.2.3-alpha.4`):

| Output | Description | Example |
| ------------------- | ------------------------------------ | --------------- |
| `version` | The full semantic version | `1.2.3-alpha.4` |
| `major-minor-patch` | The major, minor, and patch versions | `1.2.3` |
| `major-minor` | The major and minor versions | `1.2` |
| `major` | The major version | `1` |
| `minor` | The minor version | `2` |
| `patch` | The patch version | `3` |
| `prerelease` | The prerelease version | `alpha.4` |
`1.2.3-alpha.4+build.5`):

| Output | Description | Example |
| ------------------- | ------------------------- | ----------------------- |
| `version` | Full Semantic Version | `1.2.3-alpha.4+build.5` |
| `major-minor-patch` | `<major>.<minor>.<patch>` | `1.2.3` |
| `major-minor` | `<major>.<minor>` | `1.2` |
| `major` | `<major>` | `1` |
| `minor` | `<minor>` | `2` |
| `patch` | `<patch>` | `3` |
| `prerelease` | `<prerelease>` | `alpha.4` |
| `build` | `<build>` | `build.5` |

If the prerelease and/or build versions are not provided, they will not be
included in the full `version` output.

## Errors

If the `overwrite` parameter is `'false'` (the default value), this action will
fail if there is an existing version tag in the repository that matches the
inferred or provided version. This is to prevent releases from overwriting one
another.
another. However, this only applies to the full `version` output. Other tags,
such as `<major>.<minor>` are ignored in this check.

## Example

Expand Down
1 change: 1 addition & 0 deletions __tests__/fixtures/invalid/flutter/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: Example Pubspec
2 changes: 2 additions & 0 deletions __tests__/fixtures/valid/dart/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: Example Pubspec
version: 1.2.3-alpha.4+build.5
68 changes: 60 additions & 8 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ describe('main', () => {
minor: '2',
patch: '3',
prerelease: 'alpha.4',
toString: jest.fn().mockReturnValue('1.2.3-alpha.4'),
build: 'build.5',
toString: jest.fn().mockReturnValue('1.2.3-alpha.4+build.5'),
tag: jest.fn(),
exists: jest.fn().mockImplementation(() => false)
} as Version
Expand Down Expand Up @@ -156,7 +157,8 @@ describe('main', () => {
minor: '2',
patch: '3',
prerelease: 'alpha.4',
toString: jest.fn().mockReturnValue('1.2.3-alpha.4'),
build: 'build.5',
toString: jest.fn().mockReturnValue('1.2.3-alpha.4+build.5'),
tag: jest.fn(),
exists: jest.fn().mockImplementation(() => false)
} as Version
Expand All @@ -172,7 +174,11 @@ describe('main', () => {
expect(setOutputMock).toHaveBeenCalledWith('minor', '2')
expect(setOutputMock).toHaveBeenCalledWith('patch', '3')
expect(setOutputMock).toHaveBeenCalledWith('prerelease', 'alpha.4')
expect(setOutputMock).toHaveBeenCalledWith('version', '1.2.3-alpha.4')
expect(setOutputMock).toHaveBeenCalledWith('build', 'build.5')
expect(setOutputMock).toHaveBeenCalledWith(
'version',
'1.2.3-alpha.4+build.5'
)
expect(runMock).toHaveReturned()
})

Expand All @@ -188,7 +194,7 @@ describe('main', () => {
case 'ref':
return 'refs/heads/main'
case 'use-version':
return '1.2.3-alpha.4'
return '1.2.3-alpha.4+build.5'
case 'overwrite':
return 'true'
default:
Expand All @@ -199,13 +205,56 @@ describe('main', () => {
await main.run()

expect(runMock).toHaveBeenCalled()
expect(setOutputMock).toHaveBeenCalledWith('version', '1.2.3-alpha.4')
expect(setOutputMock).toHaveBeenCalledWith(
'version',
'1.2.3-alpha.4+build.5'
)
expect(setOutputMock).toHaveBeenCalledWith('major-minor-patch', '1.2.3')
expect(setOutputMock).toHaveBeenCalledWith('major-minor', '1.2')
expect(setOutputMock).toHaveBeenCalledWith('major', '1')
expect(setOutputMock).toHaveBeenCalledWith('minor', '2')
expect(setOutputMock).toHaveBeenCalledWith('patch', '3')
expect(setOutputMock).toHaveBeenCalledWith('prerelease', 'alpha.4')
expect(setOutputMock).toHaveBeenCalledWith('build', 'build.5')
expect(runMock).toHaveReturned()
})

it('does not set prerelease or build outputs if they are not present', async () => {
// Ignore the version.tag() call
jest.spyOn(Version.prototype, 'tag').mockImplementation()

// Return valid values for all inputs
jest.spyOn(core, 'getInput').mockImplementation((name: string): string => {
switch (name) {
case 'check-only':
return 'false'
case 'ref':
return 'refs/heads/main'
case 'use-version':
return '1.2.3'
case 'overwrite':
return 'true'
default:
return ''
}
})

await main.run()

expect(runMock).toHaveBeenCalled()
expect(setOutputMock).not.toHaveBeenCalledWith(
'version',
'1.2.3-alpha.4+build.5'
)
expect(setOutputMock).not.toHaveBeenCalledWith('version', '1.2.3-alpha.4')
expect(setOutputMock).toHaveBeenCalledWith('version', '1.2.3')
expect(setOutputMock).toHaveBeenCalledWith('major-minor-patch', '1.2.3')
expect(setOutputMock).toHaveBeenCalledWith('major-minor', '1.2')
expect(setOutputMock).toHaveBeenCalledWith('major', '1')
expect(setOutputMock).toHaveBeenCalledWith('minor', '2')
expect(setOutputMock).toHaveBeenCalledWith('patch', '3')
expect(setOutputMock).not.toHaveBeenCalledWith('prerelease', 'alpha.4')
expect(setOutputMock).not.toHaveBeenCalledWith('build', 'build.5')
expect(runMock).toHaveReturned()
})

Expand Down Expand Up @@ -234,7 +283,8 @@ describe('main', () => {
minor: '2',
patch: '3',
prerelease: 'alpha.4',
toString: jest.fn().mockReturnValue('1.2.3-alpha.4'),
build: 'build.5',
toString: jest.fn().mockReturnValue('1.2.3-alpha.4+build.5'),
tag: jest.fn(),
exists: jest.fn().mockImplementation(() => true)
} as Version
Expand Down Expand Up @@ -275,7 +325,8 @@ describe('main', () => {
minor: '2',
patch: '3',
prerelease: 'alpha.4',
toString: jest.fn().mockReturnValue('1.2.3-alpha.4'),
build: 'build.5',
toString: jest.fn().mockReturnValue('1.2.3-alpha.4+build.5'),
tag: jest.fn(),
exists: jest.fn().mockImplementation(() => true)
} as Version
Expand Down Expand Up @@ -316,7 +367,8 @@ describe('main', () => {
minor: '2',
patch: '3',
prerelease: 'alpha.4',
toString: jest.fn().mockReturnValue('1.2.3-alpha.4'),
build: 'build.5',
toString: jest.fn().mockReturnValue('1.2.3-alpha.4+build.5'),
tag: jest.fn(),
exists: jest.fn().mockImplementation(() => false)
} as Version
Expand Down
Loading