Skip to content

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:

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

The following content is an example of the "tool file".

For more information on the main config, the tool file and the var file of DevStream, see Core Concepts Overview and DevStream Configuration.

YAML
tools:
# name of the tool
- name: githubactions-golang
  # id of the tool instance
  instanceID: default
  # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool.
  dependsOn: [ ]
  # options for the plugin
  options:
    # the repo's owner. It should be case-sensitive here; strictly use your GitHub user name; please change the value below.
    owner: YOUR_GITHUB_USERNAME
    # the repo where you'd like to setup GitHub Actions; please change the value below to an existing repo.
    # 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.
    org: YOUR_ORGANIZATION_NAME
    repo: YOUR_REPO_NAME
    # programming language specific settings
    language:
      name: go
      # version of the language
      version: "1.18"
    # main branch of the repo (to which branch the plugin will submit the workflows)
    branch: main
    build:
      # default to false
      enable: True
      # build command, OPTIONAL, the given value below is default value
      command: "go build ./..."
    test:
      # default to false
      enable: True
      # test command, OPTIONAL, the given value below is default value
      command: "go test ./..."
      coverage:
        # default to false
        enable: False
        # go test profile subcommand, OPTIONAL, the given value below is default value
        profile: "-race -covermode=atomic"
        output: "coverage.out"
    docker:
      # docker build/push related, default to false
      enable: True
      registry:
        # dockerhub or harbor, default to dockerhub
        type: dockerhub
        # dockerhub/harbor username
        username: YOUR_DOCKERHUB_USERNAME
        # dockerhub/harbor image repository name
        repository: YOUR_DOCKERHUB_REPOSITORY

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

Use Together with the repo-scaffolding Plugin

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

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

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

See the example below:

YAML
---
tools:
- name: repo-scaffolding
  instanceID: golang-github
  options:
    owner: IronCore864
    repo: go-webapp-devstream-demo
    branch: main
    imageRepo: ironcore864/go-webapp-devstream-demo
- name: githubactions-golang
  instanceID: default
  dependsOn: ["repo-scaffolding.golang-github"]
  options:
    owner: ${{repo-scaffolding.golang-github.outputs.owner}}
    repo: ${{repo-scaffolding.golang-github.outputs.repo}}
    language:
      name: go
      version: "1.18"
    branch: main
    build:
      enable: True
    test:
      enable: True
      coverage:
        enable: True
    docker:
      enable: True
      registry:
        type: dockerhub
        username: [[ dockerhubUsername ]]
        repository: ${{repo-scaffolding.golang-github.outputs.repo}}

In the example above:

  • We put repo-scaffolding.golang-github as dependency by using the dependsOn keyword.
  • We used repo-scaffolding.golang-github'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.