Categorygithub.com/productboardlabs/gitlab-tools
modulepackage
0.2.0
Repository: https://github.com/productboardlabs/gitlab-tools.git
Documentation: pkg.go.dev

# README

gitlab-tools

Tooling to help out with our usage of Gitlab

Table of contents

Usage

Gitlab-tools offers the following commands:

is-latest-commit

is-latest-commit is used to compare a given commit against a given branch to verify that the commit is truly the latest compared to the Github API. This allows the user to fail pipelines that may be redundant if needed.

Usage: gitlab-tools is-latest-commit

Configuration

FlagEnv VariableRequiredDescriptionFrom version
github-tokenGITHUB_TOKENtrueGithub token with API permissionsv0.1.0
repositoryGITHUB_REPOSITORYtrueGithub repository name in format owner/repov0.1.0
referenceCI_COMMIT_REF_NAMEtrueBranch name to check againstv0.1.0
commitCI_COMMIT_SHAtrueFull commit SHA which will be used to compare against the latest on given branchv0.1.0

set-status-check

set-status-check allows a user arbitrarily set a status check for a given commit. This allows us to mirror the job status to Github from Gitlab as by default the Gitlab <> Github integration only displays ci/gitlab/gitlab.com in the status section in Github. This leads to improved DX.

Usage: gitlab-tools set-status-check --status pending

FlagEnv VariableRequiredDescriptionFrom version
github-tokenGITHUB_TOKENtrueGithub token with API permissionsv0.2.0
repositoryGITHUB_REPOSITORYtrueGithub repository name in format owner/repov0.2.0
statusSTATUStrueStatus to be set, allowed are: error, failure, pending or successv0.2.0
exit-codenonefalseSets status based on a given error code overrides status flagv0.2.0
commitCI_COMMIT_SHAtrueCommit sha for which to set the statusv0.2.0
status-nameCI_JOB_STAGE/CI_JOB_NAMEtrueName of status that will be shown in Githubv0.2.0
descriptionSTATUS_DESCRIPTIONfalseExtra information to show in Github. e.g. number of failed checksv0.2.0
urlCI_JOB_URLfalseLink to the given job in Gitlabv0.2.0

CI

To use in Gitlab you can use the following template:

check-branch:
    stage: check-branch # a stage which preceeds an expensive pipeline
    image: alpine:latest # any image can be used
    variables:
        GIT_STRATEGY: none # Git is not needed
        GITHUB_REPOSITORY: productboardlabs/gitlab-tools # repo name in owner/repo format
        GITHUB_TOKEN: sometoken
    cache: {}
    rules:
        # run only on branches. Can be set up for master as well
        - if: '$CI_COMMIT_BRANCH != "master"'
        when: on_success
        - when: never
    before_script:
        - wget https://raw.githubusercontent.com/productboardlabs/gitlab-tools/master/godownloader-gitlab-tools.sh -O - | sh
    script:
        - ./bin/gitlab-tools is-latest-commit

Contributing

This repo uses https://magefile.org/ to handle running command. Please run go install github.com/magefile/mage in order to use mage.

To test: mage test

# Packages

No description provided by the author