Skip to content

Commit

Permalink
Fix regex (#5)
Browse files Browse the repository at this point in the history
Fixes the semver regex.

Drive-by:
* Replaces the `Makefile` with an `invoke` task file.
* Adjusts `CircleCI` configuration.
  • Loading branch information
rgreinho authored Dec 16, 2019
1 parent 7c6b494 commit ed915c5
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 78 deletions.
16 changes: 12 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2.1
executors:
golang:
docker:
- image: circleci/golang:1.12
- image: circleci/golang:1.13-buster
working_directory: ~/project

repo_cache_key: &repo_cache_key
Expand Down Expand Up @@ -36,7 +36,9 @@ jobs:
command: |
go get -u golang.org/x/tools/cmd/goimports
go get -u golang.org/x/lint/golint
make test
sudo apt-get install python3.7 python3-pip
pip3 install invoke
inv test
build:
executor: golang
steps:
Expand All @@ -45,7 +47,10 @@ jobs:
key: *repo_cache_key
- run:
name: Build the artifact
command: make build
command: |
sudo apt-get install python3.7 python3-pip
pip3 install invoke
inv dist
publish:
executor: golang
steps:
Expand All @@ -54,7 +59,10 @@ jobs:
key: *repo_cache_key
- run:
name: Build the artifacts for all the selected architectures and published a new GitHub release
command: make publish
command: |
sudo apt-get install python3.7 python3-pip
pip3 install invoke
inv publish
workflows:
version: 2
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [[1.1.1]] - 2019-12-16

### Change

- Replace the `Makefile` by an `Invoke` task file.

### Fixed

- Fix the semver regex to make if work for calver as well.

## [[1.1.0]] - 2019-07-19

## [[1.0.0]] - 2019-06-23

Initial release.

[//]: # (Release links)
[1.0.0]: https://github.com/rgreinho/keeparelease/releases/tag/1.1.0
[1.1.0]: https://github.com/rgreinho/keeparelease/releases/tag/1.1.0
[1.1.1]: https://github.com/rgreinho/keeparelease/releases/tag/1.1.1


[//]: # (Issue/PR links)
56 changes: 0 additions & 56 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion keeparelease/keeparelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// re is the regex matching a semver in a markdown H2 header.
var re = regexp.MustCompile(`^\#\#\s+\[\[{1,2}(?P<full_version>(?P<major>(?:0|[1-9][0-9]*))\.(?P<minor>(?:0|[1-9][0-9]*))\.(?P<patch>(?:0|[1-9][0-9]*))(\-(?P<prerelease>(?:0|[1-9A-Za-z-][0-9A-Za-z-]*)(\.(?:0|[1-9A-Za-z-][0-9A-Za-z-]*))*))?(\+(?P<build>[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?)\]{1,2}\s+-?\s+(?P<date>.*)`)
var re = regexp.MustCompile(`^\#\#\s+\[{1,2}(?P<full_version>(?P<Major>0|[1-9]\d*)\.(?P<Minor>0|[1-9]\d*)\.(?P<Patch>0|[1-9]\d*)(?P<PreReleaseTagWithSeparator>-(?P<PreReleaseTag>(?:[a-z-][\da-z-]+|[\da-z-]+[a-z-][\da-z-]*|0|[1-9]\d*)(?:\.(?:[a-z-][\da-z-]+|[\da-z-]+[a-z-][\da-z-]*|0|[1-9]\d*))*))?(?P<BuildMetadataWithSeparator>\+(?P<BuildMetadata>[\da-z-]+(?:\.[\da-z-]+)*))?)`)

// ParseChangelog parses a ChangeLog respecting the Keep A Changelog format.
// Returns the title of the last release as well as its content.
Expand Down
89 changes: 72 additions & 17 deletions keeparelease/keeparelease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/lithammer/dedent"
)

const changelog string = `
const semverChangelog string = `
# Changelog
All notable changes to this project will be documented in this file.
Expand Down Expand Up @@ -42,27 +42,82 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#2]: https://github.com/rgreinho/keeparelease/pull/2
`

const calverChangelog string = `
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Calendar Versioning](https://calver.org/).
## [Unreleased]
## Added
- Add a mechanism to configure the common tools using environment variables.
## [19.12.1]
### Added
- Add the following features to docgen-nodes-reboot:
- Ability to skip the n first nodes.
- Ability to target a specific node by ID.
- Ability to exit on failure instead of moving forward to the next step.
### Changed
- Replace all the output statements by logging statements associated with the appropriate loggin level.
### Fixed
- Fix the AWS EC2 rate limit issue with docgen-nodes-reboot.
`

func TestParseChangelog00(t *testing.T) {
title, content, err := ParseChangelog(changelog)
if err != nil {
t.Fatalf("failed to parse the changelog: %s", err)
}
expectedTitle := "0.4.0"
expectedContent := trimEdges(dedent.Dedent(`
### Added
testcases := []struct {
changelog string
expectedTitle string
expectedContent string
}{
{semverChangelog, "0.4.0", trimEdges(dedent.Dedent(`
### Added
- A feature
- A feature
### Fixed
### Fixed
- A fix
`), " \n")
- A fix
`), " \n")},
{calverChangelog, "19.12.1", trimEdges(dedent.Dedent(`
### Added
if dedent.Dedent(title) != dedent.Dedent(expectedTitle) {
t.Fatalf("Error: title is %s, but expected is %s", title, expectedTitle)
}
if content != expectedContent {
t.Fatalf("Error: content is %s, \nbut expected is %s.", content, expectedContent)
- Add the following features to docgen-nodes-reboot:
- Ability to skip the n first nodes.
- Ability to target a specific node by ID.
- Ability to exit on failure instead of moving forward to the next step.
### Changed
- Replace all the output statements by logging statements associated with the appropriate loggin level.
### Fixed
- Fix the AWS EC2 rate limit issue with docgen-nodes-reboot.
`), " \n")},
}

for _, tc := range testcases {
title, content, err := ParseChangelog(tc.changelog)
if err != nil {
t.Fatalf("failed to parse the changelog: %s", err)
}

if dedent.Dedent(title) != dedent.Dedent(tc.expectedTitle) {
t.Fatalf("title is %q, but expected is %q", title, tc.expectedTitle)
}
if content != tc.expectedContent {
t.Fatalf("content is %q, \nbut expected is %q.", content, tc.expectedContent)
}
}
}
103 changes: 103 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
from pathlib import Path
import re
from zipfile import ZipFile

from invoke import task

# Configuration values.
BUILD_DIR = "dist"
GOARCH = "amd64"
PLATFORMS = ["linux", "darwin", "windows"]
PROJECT = "keeparelease"
TEST_CMD = f"go test -v -cover -coverprofile=coverage.out ./{PROJECT}"


@task
def ci(c):
"""Run the full CI suite"""
c.run("goimports -d .")
c.run("golint ./...")
c.run("go vet ./...")
c.run(TEST_CMD)


@task
def clean(c):
"""Remove unwanted files in project (!DESTRUCTIVE!)."""
c.run("git clean -ffdx")
c.run("git reset --hard")


@task
def dist(c, p=""):
"""Build binaries for the targeted platforms."""
build_dir = Path(BUILD_DIR).resolve()

# Get the tag.
tag = c.run("git describe", hide=True)

# Build all the projects.
p = Path(PROJECT)
output = build_dir / p.name
builder(c, p, tag.stdout.strip(), output)


@task
def publish(c):
"""Create a GitHub release."""
build_dir = Path(BUILD_DIR)
if not build_dir.exists:
raise FileNotFoundError("there is nothing to publish.")

# Get the tag.
tag = c.run("git describe", hide=True)

# Get the assets to publish.
assets = [
f"-a {x}"
for x in build_dir.iterdir()
if x.is_file() and str(x).endswith(".zip")
]

# Prepare the command to run
cmd = f'keeparelease -t {tag.stdout.strip()} {" ".join(assets)}'

# Run it.
c.run(cmd)


@task(default=True)
def setup(c):
"""Setup the full environment."""
c.run("go mod tidy")


@task
def test(c):
"""Run the unit tests."""
c.run(TEST_CMD)


@task
def view_coverage(c, html=False):
"""View code coverage."""
out = "html" if html else "func"
c.run(f"go tool cover -{out}=coverage.out")


def builder(c, project, tag, output):
"""Build a project."""
if not project.exists():
raise ValueError(f"project {project} cannot be found in {project.resolve()}")
with c.cd(f"{project}"):
for platform in PLATFORMS:
cmd = (
f"GOOS={platform} GOARCH={GOARCH}"
f" go build -o {output.resolve()}-{tag}-{platform}-{GOARCH}"
)
c.run(cmd)


@task(dist, publish)
def release(c):
"""Build and publish."""

0 comments on commit ed915c5

Please sign in to comment.