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

Remove underscores from PREVIEW version-numbers, complying with SemVer and fixing for sbt-release #27

Merged
merged 1 commit into from
Feb 21, 2024

Conversation

rtyley
Copy link
Member

@rtyley rtyley commented Feb 16, 2024

The branch name of update/non_aws caused problems with the PREVIEW release workflow in this recent release run for guardian/atom-maker#96 - this error from sbt-release killed the run:

Version [3.0.0-PREVIEW.updatenon_aws.2024-02-14T1807.431c7567] format is not compatible with ([0-9]+)((?:\.[0-9]+)+)?([\.\-0-9a-zA-Z]*)?

You can see that gha-scala-library-release-workflow's existing branch-name-cleanup code (added with #19) has already cleaned up the original branch name update/non_aws a bit - making it into updatenon_aws with the slash (/) stripped out, but it's the remaining underscore (_) that's causing the problem.

The regex sbt-release is using for version numbers, defined here (specifically the ([\.\-0-9a-zA-Z]*) bit) doesn't like underscores, so the non_aws part is no good, and we get the version format error.

The SemVer spec agrees - underscores are not allowed!

Note that the current semver spec (2.0.0) has a tight constraint on allowable characters in versions:

Identifiers MUST comprise only ASCII alphanumerics and hyphens [0-9A-Za-z-]"

...so sbt-release is correct here, we shouldn't allow underscores. Consequently, this change ensures we strip underscores too!

The branch name of `update/non_aws` caused problems with the PREVIEW release
workflow in this recent run for guardian/atom-maker#96:

https://github.com/guardian/atom-maker/actions/runs/7905475560/job/21578205513

We saw this error from `sbt-release`:

```
Version [3.0.0-PREVIEW.updatenon_aws.2024-02-14T1807.431c7567] format is not compatible with ([0-9]+)((?:\.[0-9]+)+)?([\.\-0-9a-zA-Z]*)?
```

You can see that the existing branch-name-cleanup code in `gha-scala-library-release-workflow`
(see https://github.com/guardian/gha-scala-library-release-workflow/blob/26b2cde0632c786fea6a4fc4b40c7a3cfbaa68bb/.github/workflows/reusable-release.yml#L87 ,
and in particular the `${GITHUB_REF_NAME//[^[:alnum:]-_]/}` part)
has already done a bit of cleanup on the original branch name `update/non_aws` -
making it into `updatenon_aws` with the slash (`/`) stripped out, but it's the
remaining _underscore_ (`_`) that's causing the problem - the regex `sbt-release` is using
for version numbers, defined here:

https://github.com/sbt/sbt-release/blob/v1.4.0/src/main/scala/Version.scala#L58

...specifically the `([\.\-0-9a-zA-Z]*)` bit, doesn't like underscores in version numbers,
so the `non_aws` part is no good, and we get the version format error.

Note that the current semver spec (2.0.0) has a tight constraint on allowable characters
in a version string:

  "Identifiers MUST comprise only ASCII alphanumerics and hyphens [0-9A-Za-z-]"
  -- https://semver.org/#spec-item-9

...so `sbt-release` is correct here, we shouldn't allow underscores.

Consequently, this change ensures we strip underscores too - you can check this at the
bash prompt like this:

```
$ GITHUB_REF_NAME="update/non_aws/roberto-tyley-is-da-coolest.so-true"
$ echo "-PREVIEW.${GITHUB_REF_NAME//[^[:alnum:]-]/}.$(date +%Y-%m-%dT%H%M)"
-PREVIEW.updatenonawsroberto-tyley-is-da-coolestso-true.2024-02-16T1503
```

It would probably be nicer to convert slashes and underscores to dashes, but this at least
should produce stuff that `sbt-release` doesn't mind.
version_suffix="-PREVIEW.${GITHUB_REF_NAME//[^[:alnum:]-_]/}.$(date +%Y-%m-%dT%H%M).${GITHUB_SHA:0:8}"
version_suffix="-PREVIEW.${GITHUB_REF_NAME//[^[:alnum:]-]/}.$(date +%Y-%m-%dT%H%M).${GITHUB_SHA:0:8}"
Copy link
Member Author

Choose a reason for hiding this comment

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

You can check this at the bash prompt like this:

$ GITHUB_REF_NAME="update/non_aws/roberto-tyley-is-da-coolest.so-true"
$ echo "-PREVIEW.${GITHUB_REF_NAME//[^[:alnum:]-]/}.$(date +%Y-%m-%dT%H%M)"
-PREVIEW.updatenonawsroberto-tyley-is-da-coolestso-true.2024-02-16T1503

@rtyley rtyley marked this pull request as ready for review February 16, 2024 15:23
@rtyley rtyley merged commit a7ab2ae into main Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant