Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
Remove need for Space config vars in dry run mode (#60)
Browse files Browse the repository at this point in the history
* Remove need for Space config vars in dry run mode

* Remove Space config vars from CI/CD when dry run

* Refactor config var functional test method

* Bump plugin minor version
  • Loading branch information
johnboyes authored Sep 17, 2021
1 parent d3bb0b2 commit fbb55f0
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 24 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/publish-specs-to-prod-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ jobs:
- name: Dry Run publish specs
env:
CONFLUENCE_BASE_URL: ${{ secrets.CONFLUENCE_BASE_URL }}
CONFLUENCE_USERNAME: ${{ secrets.CONFLUENCE_USERNAME }}
CONFLUENCE_TOKEN: ${{ secrets.CONFLUENCE_TOKEN }}
DRY_RUN: "true"
run: |
cd functional-tests
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/publish-specs-to-test-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ jobs:
- name: Dry Run publish specs
env:
CONFLUENCE_BASE_URL: ${{ secrets.CONFLUENCE_BASE_URL }}
CONFLUENCE_USERNAME: ${{ secrets.CONFLUENCE_USERNAME }}
CONFLUENCE_TOKEN: ${{ secrets.CONFLUENCE_TOKEN }}
DRY_RUN: "true"
run: |
cd functional-tests
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ spec headings).
This is very useful e.g. **in a CI/CD pipeline the plugin can run in dry run mode on feature branches and pull
requests.** 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 three config variables which are mandatory for actual publishing (`CONFLUENCE_BASE_URL`, `CONFLUENCE_USERNAME` and
`CONFLUENCE_TOKEN`) do not need to be provided when doing a dry run.

___
If the `CONFLUENCE_SPACE_KEY` is not provided, the plugin will derive the Space key to be used based on the remote Git repository URL. This convention ensures that each Git repository has its own unique Confluence space key derived from it, i.e. a one to one mapping between each Git repository and its associated one to one space.

Expand Down
11 changes: 10 additions & 1 deletion functional-tests/specs/check_config_vars.spec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Configuration variables are required to be set
# Configuration variables are required to be set, unless in dry run mode
Tags: create-space-manually

|config variable |
Expand All @@ -12,6 +12,15 @@ Tags: create-space-manually
* Required configuration variable <config variable> must be set


## Configuration variables are not required to be set in dry run mode

* Activate dry run mode

* Publish Confluence Documentation with no <config variable> configured and assert "did" succeed

* Output contains "Dry run finished successfully"


________________________________________________________________________________________________

Read more about [Gauge's configuration documentation](https://docs.gauge.org/configuration.html)
4 changes: 1 addition & 3 deletions functional-tests/specs/concepts/check_config_vars.cpt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Required configuration variable <configVar> must be set

* Initialize an empty Gauge project

* Publish Confluence Documentation for the current project with no <configVar> configured
* Publish Confluence Documentation with no <configVar> configured and assert "did not" succeed

* Output contains "Aborting: " <configVar> " is not set. Set it and try again."
* Output contains "See https://github.com/agilepathway/gauge-confluence#plugin-setup"
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ public void publishConfluenceDocumentationForCurrentProject() throws Exception {

@Step("Publish Confluence Documentation for the current project and assert <did|did not> succeed")
public void publishConfluenceDocumentationForCurrentProjectAndAssertResult(String didOrDidNotSucceed) throws Exception {
boolean success = (didOrDidNotSucceed.equalsIgnoreCase("did"));
assertOn(getCurrentProject().publishConfluenceDocumentation(), success);
boolean result = (didOrDidNotSucceed.equalsIgnoreCase("did"));
assertOn(getCurrentProject().publishConfluenceDocumentation(), result);
}

@Step("Publish Confluence Documentation for the current project with no <variable> configured")
public void publishConfluenceDocumentationForCurrentProjectWithConfigVarUnset(String configVar) throws Exception {
assertOn(getCurrentProject().publishConfluenceDocumentationWithConfigVarUnset(configVar), false);
@Step("Publish Confluence Documentation with no <variable> configured and assert <did|did not> succeed")
public void publishConfluenceDocumentationWithConfigVarUnset(String configVar, String didOrDidNotSucceed) throws Exception {
new ProjectInit().projectInit();
boolean result = (didOrDidNotSucceed.equalsIgnoreCase("did"));
assertOn(getCurrentProject().publishConfluenceDocumentationWithConfigVarUnset(configVar), result);
}

@Step("Publish Confluence Documentation for two projects")
Expand Down
8 changes: 8 additions & 0 deletions internal/confluence/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@ type Client struct {

// NewClient initialises a new Client.
func NewClient() Client {
if env.GetBoolean("DRY_RUN") {
return dummyClient()
}

httpClient := http.NewClient(baseEndpoint(), username(), token())
goconfluenceClient, err := goconfluence.NewAPI(baseEndpoint(), username(), token())
util.Fatal("Error while creating Confluence API Client", err)

return Client{httpClient, goconfluenceClient}
}

func dummyClient() Client {
return Client{http.NewClient("", "", ""), nil}
}

// PublishPage publishes a page to Confluence as a child of the given parent page.
func (c *Client) PublishPage(spaceKey, title, body, parentPageID string) (pageID string, err error) {
requestContent := &goconfluence.Content{
Expand Down
8 changes: 8 additions & 0 deletions internal/confluence/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,15 @@ func keyFmt(u *url.URL) string {
return strings.ToUpper(alphanumeric)
}

func (s *space) checkRequiredConfigVars() {
env.GetRequired("CONFLUENCE_BASE_URL")
env.GetRequired("CONFLUENCE_USERNAME")
env.GetRequired("CONFLUENCE_TOKEN")
}

func (s *space) setup() error { // nolint:funlen
s.checkRequiredConfigVars()

key, err := retrieveOrGenerateKey()
if err != nil {
return err
Expand Down
8 changes: 0 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/agilepathway/gauge-confluence/gauge_messages"
"github.com/agilepathway/gauge-confluence/internal/confluence"
"github.com/agilepathway/gauge-confluence/internal/env"
"github.com/agilepathway/gauge-confluence/internal/logger"
"github.com/agilepathway/gauge-confluence/util"
"google.golang.org/grpc"
Expand Down Expand Up @@ -47,7 +46,6 @@ func (h *handler) stopServer() {

func main() {
logger.Initialize(loglevel())
checkRequiredConfigVars()

err := os.Chdir(projectRoot)
util.Fatal("failed to change directory to project root.", err)
Expand All @@ -65,12 +63,6 @@ func main() {
server.Serve(l) //nolint:errcheck,gosec
}

func checkRequiredConfigVars() {
env.GetRequired("CONFLUENCE_BASE_URL")
env.GetRequired("CONFLUENCE_USERNAME")
env.GetRequired("CONFLUENCE_TOKEN")
}

// providedSpecsPaths returns the specs paths passed in
// by the user of the plugin (converted to absolute paths by the
// core Gauge engine).
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "confluence",
"version": "0.16.1",
"version": "0.17.0",
"name": "Confluence",
"description": "Publishes Gauge specifications to Confluence",
"install": {
Expand Down

0 comments on commit fbb55f0

Please sign in to comment.