resource

package module
v1.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

README

Table of Contents

GitLab Releases Resource

Fetches and creates versioned GitLab releases. Note that check will skip tags that do not have associated releases.

⚠️ Limitations ⚠️

GitLab has a known bug (28978, 375489) making impossible to download assets published to a project using a private-token. When using in with such release, download assets will contain the plain HTML of GitLab's sign-in page.

Once fixed, this Concourse resource will behave as expected with no further modification.

Source Configuration

  • repository: Required. The repository name that contains the releases.
  • access_token: Required. Used for accessing a release in a private-repo during an in and pushing a release to a repo during an out. The access token you create is only required to have the repo or public_repo scope.
  • gitlab_api_url: Optional. If you use a non-public GitLab deployment then you can set your API URL here.
  • insecure: Optional. Default false. When set to true, Concourse will allow insecure connection to your GitLab API.
  • tag_filter: Optional. If set, override default tag filter regular expression of v?([^v].*). If the filter includes a capture group, the capture group is used as the release version; otherwise, the entire matching substring is used as the version.
Examples
- name: gl-release
  type: gitlab-release
  source:
    repository: group/project
    access_token: abcdef1234567890
- get: gl-release
- put: gl-release
  params:
    tag: path/to/tag/file
    body: path/to/body/file
    globs:
    - paths/to/files/to/upload-*.tgz

To get a specific version of a release:

- get: gl-release
  version: { tag: 'v0.0.1' }

To set a custom tag filter:

- name: gl-release
  type: gitlab-release
  source:
    owner: concourse
    repository: concourse
    tag_filter: "version-(.*)"

Behavior

check: Check for released versions

Releases are listed and sorted by their tag, using https://github.com/cppforlife/go-semi-semantic. Few example:

  • v1.0.0 < v1.0.5 < v1.10.0 < v2.0.0 (intuitive behaviour)
  • v1.0.0-dev1 < v1.0.0-dev2 < v1.0.0 (empty dash postfix takes priority)
  • v1.0.0-dev10 < v1.0.0-rc1 (dash postfixes are compared alphabetically)
  • v1.0.0.1 < v1.0.0_dev (non integer parts are compared alphabetically, 1 < 0_dev)

If version is specified, check returns releases from the specified version on. Otherwise, check returns the latest release.

in: Fetch assets from a release

Fetches artifacts from the given release version. If the version is not specified, the latest version is chosen using semver semantics.

Also creates the following files:

  • tag containing the git tag name of the release being fetched.
  • version containing the version determined by the git tag of the release being fetched.
  • body containing the body text of the release.
  • commit_sha containing the commit SHA the tag is pointing to.
Parameters
  • globs: Optional. A list of globs for files that will be downloaded from the release. If not specified, all assets will be fetched.
  • include_sources: Optional. A list of source format to download from the release. If not specified, no sources will be fetched (i.e.: ["zip", "tar.gz","tar.bz2", "tar"]).
  • include_source_tarball: Optional. Enables downloading of the source artifact tarball for the release as source.tar.gz. Defaults to false. Equivalent to include_sources: ["tar.gz"].
  • include_source_zip: Optional. Enables downloading of the source artifact tarball for the release as source.zip. Defaults to false. Equivalent to include_sources: ["zip"].
out: Publish a release

Given a commit_sha and tag, this tags the commit and creates a release on GitLab, then uploads the files matching the patterns in globs to the release.

Parameters
  • commitish: Optional, if tag is not specified. A path to a file containing the commitish (SHA, tag, branch name) that the new tag and release should be associated with.
  • tag: Required. A path to a file containing the name of the Git tag to use for the release.
  • tag_prefix: Optional. If specified, the tag read from the file will be prepended with this string. This is useful for adding v in front of version numbers.
  • name: Optional. A path to a file containing the name of the release. Defaults to tag value.
  • body: Optional. A path to a file containing the body text of the release.
  • globs: Optional. A list of globs for files that will be uploaded alongside the created release.

Development

Prerequisites
  • Go lang is required - version 1.16 is tested; earlier versions may also work.
  • Docker is required - version 19.03.x is tested; earlier versions may also work.
  • go mod is used for dependency management of the golang packages.
Running the tests

The tests have been embedded with the Dockerfile, ensuring that the testing environment is consistent across any docker enabled platform. When the Docker image builds, the tests are run inside the Docker container, on failure they will stop the building process.

Run the tests with the following command:

docker build -t gitlab-release-resource .
Contributing

Please make all pull requests to the master branch and ensure tests pass locally.

Credits

This project was initially created by @edtan and forked from gitlab-release-resource which is no longer maintained. It has been re-imported to get rid of the fork relationship to the repository github-release-resource.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NotFound = errors.New("object not found")
)

Functions

func Fatal

func Fatal(doing string, err error)

func Sayf

func Sayf(message string, args ...interface{})

Types

type CheckCommand

type CheckCommand struct {
	// contains filtered or unexported fields
}

func NewCheckCommand

func NewCheckCommand(gitlab GitLab) *CheckCommand

func (*CheckCommand) Run

func (c *CheckCommand) Run(request CheckRequest) ([]Version, error)

type CheckRequest

type CheckRequest struct {
	Source  Source  `json:"source"`
	Version Version `json:"version"`
}

func NewCheckRequest

func NewCheckRequest() CheckRequest

type GitLab

type GitLab interface {
	ListTags() ([]*gitlab.Tag, error)
	ListTagsUntil(tag_name string) ([]*gitlab.Tag, error)
	ListReleases() ([]*gitlab.Release, error)
	GetRelease(tag_name string) (*gitlab.Release, error)
	GetTag(tag_name string) (*gitlab.Tag, error)
	CreateTag(tag_name string, ref string) (*gitlab.Tag, error)
	CreateRelease(name string, tag string, description *string) (*gitlab.Release, error)
	UpdateRelease(name string, tag string, description *string) (*gitlab.Release, error)

	UploadProjectFile(file string) (*gitlab.ProjectFile, error)
	DownloadProjectFile(url, file string) error

	GetReleaseLinks(tag string) ([]*gitlab.ReleaseLink, error)
	CreateReleaseLink(tag string, name string, url string) (*gitlab.ReleaseLink, error)
	DeleteReleaseLink(tag string, links *gitlab.ReleaseLink) error
}

type GitlabClient

type GitlabClient struct {
	// contains filtered or unexported fields
}

func NewGitLabClient

func NewGitLabClient(source Source) (*GitlabClient, error)

func (*GitlabClient) CreateRelease

func (g *GitlabClient) CreateRelease(name string, tag string, description *string) (*gitlab.Release, error)
func (g *GitlabClient) CreateReleaseLink(tag string, name string, url string) (*gitlab.ReleaseLink, error)

func (*GitlabClient) CreateTag

func (g *GitlabClient) CreateTag(tag_name string, ref string) (*gitlab.Tag, error)
func (g *GitlabClient) DeleteReleaseLink(tag string, link *gitlab.ReleaseLink) error

func (*GitlabClient) DownloadProjectFile

func (g *GitlabClient) DownloadProjectFile(fileURL, destPath string) error

func (*GitlabClient) GetRelease

func (g *GitlabClient) GetRelease(tag_name string) (*gitlab.Release, error)
func (g *GitlabClient) GetReleaseLinks(tag string) ([]*gitlab.ReleaseLink, error)

func (*GitlabClient) GetTag

func (g *GitlabClient) GetTag(tag_name string) (*gitlab.Tag, error)

func (*GitlabClient) ListReleases

func (g *GitlabClient) ListReleases() ([]*gitlab.Release, error)

func (*GitlabClient) ListTags

func (g *GitlabClient) ListTags() ([]*gitlab.Tag, error)

func (*GitlabClient) ListTagsUntil

func (g *GitlabClient) ListTagsUntil(tag_name string) ([]*gitlab.Tag, error)

func (*GitlabClient) UpdateRelease

func (g *GitlabClient) UpdateRelease(name string, tag string, description *string) (*gitlab.Release, error)

func (*GitlabClient) UploadProjectFile

func (g *GitlabClient) UploadProjectFile(filepath string) (*gitlab.ProjectFile, error)

type InCommand

type InCommand struct {
	// contains filtered or unexported fields
}

func NewInCommand

func NewInCommand(gitlab GitLab, writer io.Writer) *InCommand

func (*InCommand) Run

func (c *InCommand) Run(destDir string, request InRequest) (InResponse, error)

type InParams

type InParams struct {
	Globs                []string `json:"globs"`
	IncludeSources       []string `json:"include_sources"`
	IncludeSourceTarball bool     `json:"include_source_tarball"`
	IncludeSourceZip     bool     `json:"include_source_zip"`
}

type InRequest

type InRequest struct {
	Source  Source   `json:"source"`
	Version *Version `json:"version"`
	Params  InParams `json:"params"`
}

func NewInRequest

func NewInRequest() InRequest

type InResponse

type InResponse struct {
	Version  Version        `json:"version"`
	Metadata []MetadataPair `json:"metadata"`
}

type MetadataPair

type MetadataPair struct {
	Name     string `json:"name"`
	Value    string `json:"value"`
	URL      string `json:"url"`
	Markdown bool   `json:"markdown"`
}

type OutCommand

type OutCommand struct {
	// contains filtered or unexported fields
}

func NewOutCommand

func NewOutCommand(gitlab GitLab, writer io.Writer) *OutCommand

func (*OutCommand) Run

func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, error)

type OutParams

type OutParams struct {
	NamePath      string `json:"name"`
	BodyPath      string `json:"body"`
	TagPath       string `json:"tag"`
	CommitishPath string `json:"commitish"`
	TagPrefix     string `json:"tag_prefix"`

	Globs []string `json:"globs"`
}

type OutRequest

type OutRequest struct {
	Source Source    `json:"source"`
	Params OutParams `json:"params"`
}

func NewOutRequest

func NewOutRequest() OutRequest

type OutResponse

type OutResponse struct {
	Version  Version        `json:"version"`
	Metadata []MetadataPair `json:"metadata"`
}

type Source

type Source struct {
	Repository string `json:"repository"`

	GitLabAPIURL string `json:"gitlab_api_url"`
	AccessToken  string `json:"access_token"`
	Insecure     bool   `json:"insecure"`

	TagFilter string `json:"tag_filter"`
}

type Version

type Version struct {
	Tag       string `json:"tag,omitempty"`
	CommitSHA string `json:"commit_sha,omitempty"`
}

Directories

Path Synopsis
cmd
check command
in command
out command
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL