Skip to content

Add CI/CD for GitHub to registration features

Taras Tadai requested to merge 422285-add-ci-cd-for-github-to-reg-features into master

What does this MR do and why?

We want to add CI/CD for GitHub to Registration features available to users who have service ping data sharing enabled.

Screenshots or screen recordings

Before After
enable_reg_features_off enable_reg_features_on
ci_cd_for_github_new_project_off ci_cd_for_github_new_project_on
ci_cd_for_github_webhook_off ci_cd_for_github_webhook_on
ci_cd_for_github_webhook_off2 ci_cd_for_github_webhook_on2
ci_cd_for_github_PR_status
ci_cd_for_github_pipeline_on

How to set up and validate locally

Requirements

  • Make sure you have gitlab runner installed.
  • Make sure you have instance or project runner to process pipelines. Instance runner can be created the same way as project runner but from Admin Area -> CI/CD -> Runners (/admin/runners).
  • Make sure you have some env accessible from the internet otherwise GitHub won't be able to access your dev env to trigger webhook endpoint. You may use something like ngrok(if allowed to use on dev env), I used my personal web server to proxy requests to local dev env. Please setup this before verification.
  • You must use some domain name(not localhost) for you dev env otherwise it will not create webhook on GitHub side for localhost or 127.0.0.1 address:

config/gitalb.yml

production: &base
  #
  # 1. GitLab app settings
  # ==========================

  ## GitLab settings
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: test.example.com
    port: 3000
    https: false

config/environments/development.rb

Rails.application.configure do
  config.hosts << "test.example.com"
# ...
end

Steps

  1. Testing previous behavior:
    • Make sure you're on a Premium plan GitLab GDK instance
    • Enable GitHub integration:
      • ci_cd_for_github_integration_on
    • Follow documentation steps to create CI/CD for GitHub. Below are the same steps with some tips to verify it.
    • Create new GitHub project with README.md file and .gitlab-ci.yml:
stages:
  - build
  - test

job_build:
  stage: build
  script:
    - echo "Building the project"

job_test:
  stage: test
  script:
    - echo "Running tests"
  • In GitHub, create a token https://github.com/settings/tokens/new with repo and admin:repo_hook scopes
  • In GitLab, create a new project:
    • On new project page select Run CI/CD for external repository.
    • Click on GitHub button.
    • For Personal access token, paste the token.
    • Select List Repositories.
    • Select Connect to select the repository.
  • Verify you have new Webhook on GitHub side:
    • ci_cd_for_github_webhook
  • Verify you have new GitHub integration on GitLab side for this new project:
    • ci_cd_for_github_project_github_integration
  • Verify you have new mirroring on GitLab side for this new project:
    • ci_cd_for_github_project_mirroring
  • Create new branch on GitHub side
  • Modify README.md file inside this new branch and create new PR.
  • Verify project pipelines on GitLab side.
  • Verify webhook status on GitHub side (Settings -> Webhooks -> Select webhook -> Recent Deliveries).
  • Verify PR status.
  1. When registration features are enabled:
    • Make sure you're on a free plan GitLab GDK instance (for example, remove current license or stub #current to return nil)
    • Make sure you have the Registration Features checkbox enabled (Admin -> Settings -> Metrics and profiling -> Usage statistics -> Enable Service Ping & Enable Registration Features)
    • Follow steps from 1. to verify it.
  2. When registration features are disabled:
    • Make sure you're on a free plan GitLab GDK instance
    • Make sure you have the registration features checkbox disabled (Admin -> Settings -> Metrics and profiling -> Usage statistics -> Enable Registration Features)
    • Verify you don't have Run CI/CD for external repository on new project page.
  3. Make sure that the new text appears on the docs page:
    • run gdk restart gitlab-docs
    • go to <local_gitlab_docs_host>/ee/user/admin_area/settings/usage_statistics.html#registration-features-program and make sure the new section is on the page and the link works
Updated doc Link page
ci_cd_for_github_docs ci_cd_for_github_docs2

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #422285 (closed)

Edited by Taras Tadai

Merge request reports