Skip to content
Snippets Groups Projects
.gitlab-ci.yml 2.45 KiB
Newer Older
include:
  - 'https://codebase.helmholtz.cloud/m-team/tools/ci-voodoo/-/raw/master/ci-include/github-status-sync.yml'
Gabriel Zachmann's avatar
Gabriel Zachmann committed
  - "https://codebase.helmholtz.cloud/m-team/tools/ci-voodoo/raw/master/ci-include/pipeline-jobs-publish-to-repo.yml"


variables:
Gabriel Zachmann's avatar
Gabriel Zachmann committed
  USE_GORELEASER: "true"
  UPSTREAM_PROJECT: oidc-mytoken/server

Gabriel Zachmann's avatar
Gabriel Zachmann committed
image: golang:1.24
Gabriel Zachmann's avatar
Gabriel Zachmann committed
stages:
  - build
  - test
  - lint
Gabriel Zachmann's avatar
Gabriel Zachmann committed
  - package
  - publish
Gabriel Zachmann's avatar
Gabriel Zachmann committed
  - deploy
Gabriel Zachmann's avatar
Gabriel Zachmann committed

default:
  tags:
    - linux
Gabriel Zachmann's avatar
Gabriel Zachmann committed
  cache:
    paths:
      - .cache

Gabriel Zachmann's avatar
Gabriel Zachmann committed
before_script:
  - mkdir -p .cache
  - export GOPATH=${CI_PROJECT_DIR}/.cache
Gabriel Zachmann's avatar
Gabriel Zachmann committed

test:
  stage: test
  script:
    - go test -v ./...

test_race:
  stage: test
  script:
    - go test -race -v ./...

staticcheck:
Gabriel Zachmann's avatar
Gabriel Zachmann committed
  stage: lint
  before_script:
    - go install honnef.co/go/tools/cmd/staticcheck@latest
Gabriel Zachmann's avatar
Gabriel Zachmann committed
  script:
    - staticcheck ./...
Gabriel Zachmann's avatar
Gabriel Zachmann committed

vet:
  stage: lint
  script:
    - go vet -structtag=false ./...
Gabriel Zachmann's avatar
Gabriel Zachmann committed

build_server:
Gabriel Zachmann's avatar
Gabriel Zachmann committed
  stage: build
Gabriel Zachmann's avatar
Gabriel Zachmann committed
  script:
    - go build github.com/oidc-mytoken/server/cmd/mytoken-server

build_setup:
  stage: build
  script:
    - go build github.com/oidc-mytoken/server/cmd/mytoken-server/mytoken-setup

Gabriel Zachmann's avatar
Gabriel Zachmann committed
package:
  stage: package
Gabriel Zachmann's avatar
Gabriel Zachmann committed
  image:
Gabriel Zachmann's avatar
Gabriel Zachmann committed
    name: goreleaser/goreleaser
    entrypoint: [ "" ]
Gabriel Zachmann's avatar
Gabriel Zachmann committed
  services:
    - docker:dind
Gabriel Zachmann's avatar
Gabriel Zachmann committed
#  only:
#    refs:
#      - tags
#      - prerel
Gabriel Zachmann's avatar
Gabriel Zachmann committed
  variables:
cicd's avatar
cicd committed
    GIT_STRATEGY: clone
cicd's avatar
cicd committed
    GIT_DEPTH: 0
Gabriel Zachmann's avatar
Gabriel Zachmann committed
    REPO_HOST: repo.data.kit.edu
    REPO_USER: cicd
Gabriel Zachmann's avatar
Gabriel Zachmann committed
    DOCKER_REGISTRY: https://index.docker.io/v1/
Gabriel Zachmann's avatar
Gabriel Zachmann committed
  before_script:
    - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin "$DOCKER_REGISTRY"
Gabriel Zachmann's avatar
Gabriel Zachmann committed
  script:
Gabriel Zachmann's avatar
Gabriel Zachmann committed
    - |
Gabriel Zachmann's avatar
Gabriel Zachmann committed
      [[ "$CI_COMMIT_BRANCH" == "${PREREL_BRANCH_NAME}" ]] && {
Gabriel Zachmann's avatar
Gabriel Zachmann committed
          echo "Running set-prerel-version"
          .gitlab-ci-scripts/set-prerel-version.sh
      }
Gabriel Zachmann's avatar
Gabriel Zachmann committed
      [[ "$CI_COMMIT_BRANCH" != "${PREREL_BRANCH_NAME}" ]] && {
          [[ "$CI_COMMIT_BRANCH" != "${CI_DEFAULT_BRANCH}" ]] && {
Gabriel Zachmann's avatar
Gabriel Zachmann committed
              # we're on a devel branch
              echo "Running set-devel-version"
              .gitlab-ci-scripts/set-prerel-version.sh --devstring dev
          }
      }
      .gitlab-ci-scripts/goreleaser.sh

  artifacts:
    paths:
      - "results/*"
Gabriel Zachmann's avatar
Gabriel Zachmann committed
  after_script:
    - curl -d "repo=github.com/oidc-mytoken/server" https://goreportcard.com/checks
Gabriel Zachmann's avatar
Gabriel Zachmann committed
  stage: deploy
Gabriel Zachmann's avatar
Gabriel Zachmann committed
  before_script:
    - mkdir -p /root/.ssh
    - cp $KNOWN_HOSTS /root/.ssh/known_hosts
    - cp $DEPLOYMENT_SSH_KEY /root/.ssh/id_ed25519 && chmod 0600 /root/.ssh/id_ed25519
  script:
    - ssh -4 mytoken.data.kit.edu