githubactions-golang Plugin

This plugin creates some Golang GitHub Actions workflows.

Usage

This plugin depends on the following environment variable:

  • GITHUB_TOKEN

Set it before using this plugin.

If you don’t know how to create this token, check out: - Creating a personal access token

If Docker image build/push is enabled (see the example below), you also need to set the following two environment variables: - DOCKERHUB_USERNAME - DOCKERHUB_TOKEN

  1. tools:
  2. # name of the tool
  3. - name: githubactions-golang
  4. # id of the tool instance
  5. instanceID: default
  6. # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool.
  7. dependsOn: []
  8. # options for the plugin
  9. options:
  10. # the repo's owner. It should be case-sensitive here; strictly use your GitHub user name; please change the value below.
  11. owner: YOUR_GITHUB_USERNAME
  12. # the repo's org. If you set this property, then the new repo will be created under the org you're given, and the "owner" setting above will be ignored.
  13. org: YOUR_ORGANIZATION_NAME
  14. # the repo where you'd like to setup GitHub Actions; please change the value below to an existing repo.
  15. repo: YOUR_REPO_NAME
  16. # programming language specific settings
  17. language:
  18. name: go
  19. # version of the language
  20. version: "1.17"
  21. # main branch of the repo (to which branch the plugin will submit the workflows)
  22. branch: main
  23. build:
  24. # default to false
  25. enable: True
  26. # build command, OPTIONAL, the given value below is default value
  27. command: "go build ./..."
  28. test:
  29. # default to false
  30. enable: True
  31. # test command, OPTIONAL, the given value below is default value
  32. command: "go test ./..."
  33. coverage:
  34. # default to false
  35. enable: False
  36. # go test profile subcommand, OPTIONAL, the given value below is default value
  37. profile: "-race -covermode=atomic"
  38. output: "coverage.out"
  39. docker:
  40. # docker build/push related, default to false
  41. enable: True
  42. registry:
  43. # dockerhub or harbor, default to dockerhub
  44. type: dockerhub
  45. # dockerhub/harbor username
  46. username: YOUR_DOCKERHUB_USERNAME
  47. # dockerhub/harbor image repository name
  48. repository: YOUR_DOCKERHUB_REPOSITORY

Some parameters are optional. See the default values and optional parameters in the example above.

Use Together with the github-repo-scaffolding-golang Plugin

This plugin can be used together with the github-repo-scaffolding-golang plugin (see document here.)

For example, you can first use github-repo-scaffolding-golang to bootstrap a Golang repo, then use this plugin to set up basic GitHub Actions CI workflows. In this scenario:

  • This plugin can specify github-repo-scaffolding-golang as a dependency, so that the dependency is first satisfied before executing this plugin.
  • This plugin can refer to github-repo-scaffolding-golang‘s output to reduce copy/paste human error.

See the example below:

  1. ---
  2. tools:
  3. - name: github-repo-scaffolding-golang
  4. instanceID: default
  5. options:
  6. owner: IronCore864
  7. repo: go-webapp-devstream-demo
  8. branch: main
  9. image_repo: ironcore864/go-webapp-devstream-demo
  10. - name: githubactions-golang
  11. instanceID: default
  12. dependsOn: ["github-repo-scaffolding-golang.default"]
  13. options:
  14. owner: ${{github-repo-scaffolding-golang.default.outputs.owner}}
  15. repo: ${{github-repo-scaffolding-golang.default.outputs.repo}}
  16. language:
  17. name: go
  18. version: "1.17"
  19. branch: main
  20. build:
  21. enable: True
  22. test:
  23. enable: True
  24. coverage:
  25. enable: True
  26. docker:
  27. enable: True
  28. registry:
  29. type: dockerhub
  30. username: [[ dockerhubUsername ]]
  31. repository: ${{github-repo-scaffolding-golang.default.outputs.repo}}

In the example above:

  • We put ggithub-repo-scaffolding-golang.default as dependency by using the dependsOn keyword.
  • We used github-repo-scaffolding-golang.default‘s output as input for the githubactions-golang plugin.

Pay attention to the ${{ xxx }} part in the example. ${{ TOOL_NAME.TOOL_INSTANCE_ID.outputs.var}} is the syntax for using an output.