Skip to content

Commit

Permalink
Add dry run mode
Browse files Browse the repository at this point in the history
Having a dry run mode is very useful, e.g. in a CI/CD pipeline the dry
run mode can be run on feature branches and pull requests to verify that
the Gauge specs are in a valid state for publishing.  If they are not
valid then the CI/CD pipeline build can fail, alerting the submitter
of the pull request to amend them on the feature branch.  This ensures
that the Gauge specs are always in good shape to be automatically
published by the CI/CD pipeline upon any push to the trunk branch (e.g.
upon a successful pull request merge).

The dry run mode is set by setting a `DRY_RUN` environment variable
or property (we can't use a command-line flag for this as [Gauge does
not propagate command line flags to documentation plugins][1]).

[1]: getgauge/spectacle#42 (comment)
  • Loading branch information
johnboyes authored Aug 15, 2021
1 parent 2414803 commit 78451bc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 6 additions & 4 deletions internal/confluence/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,14 @@ func makeSpecsMap(m *gauge_messages.SpecDetails) map[string]Spec {
func (p *Publisher) Publish(specPaths []string) {
var err error

logger.Infof(true, "Preparing to publish Gauge specs to Confluence ...")
logger.Infof(true, "Checking specs are in a valid state for publishing to Confluence ...")

err = p.space.setup()
if err != nil {
p.printFailureMessage(err)
return
}

logger.Infof(true, "Checking specs can be published ...")

for _, specPath := range specPaths {
err = p.dryRunChecks(specPath)
if err != nil {
Expand All @@ -65,8 +63,12 @@ func (p *Publisher) Publish(specPaths []string) {
}
}

logger.Infof(true, "Checking finished successfully ...")
if env.GetBoolean("DRY_RUN") {
logger.Infof(true, "Dry run finished successfully")
return
}

logger.Infof(true, "Checking finished successfully")
logger.Infof(true, "Publishing Gauge specs to Confluence ...")

err = p.space.deleteAllPagesExceptHomepage()
Expand Down
7 changes: 7 additions & 0 deletions internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package env
import (
"fmt"
"os"
"strings"
)

// GetRequired returns an environment variable value or panics if not present.
Expand All @@ -16,3 +17,9 @@ func GetRequired(key string) string {

return value
}

// GetBoolean returns true if the environment variable exists and has a value of "true"
func GetBoolean(key string) bool {
value := os.Getenv(key)
return strings.ToLower(value) == "true"
}

0 comments on commit 78451bc

Please sign in to comment.