diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-15 21:09:34 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-15 21:09:34 +0300 |
commit | a84aefe0bb8fc2ad47ab67cb4ddcfbb7aecfbd5e (patch) | |
tree | dfcd00dc9603a8c652211c6066ceae0c97df1a7f /scripts | |
parent | 16cdacff02fbf0069182e090df2eeaa754007957 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/check-template-changes | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/scripts/check-template-changes b/scripts/check-template-changes new file mode 100755 index 00000000000..1a3060fe1bb --- /dev/null +++ b/scripts/check-template-changes @@ -0,0 +1,105 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require 'tmpdir' + +@template = ARGV.first + +if @template.nil? + puts "Usage: #{__FILE__} <path_to_project_template>" + exit 1 +end + +@name = File.basename(@template).delete_suffix('.tar.gz') +@extracted_template_dir = Dir.mktmpdir(@name) +@master_template_dir = Dir.mktmpdir(@name) + +def extract(dest) + system('tar', 'xf', @template, '-C', dest, exception: true) +end + +def cleanup + FileUtils.rm_rf(@extracted_template_dir) + FileUtils.rm_rf(@master_template_dir) +end + +def repo_details + Dir.chdir(@extracted_template_dir) do + system('git', 'clone', 'project.bundle', @name, exception: true) + end + + Dir.chdir(File.join(@extracted_template_dir, @name)) do + head_commit = `git cat-file -p HEAD` + lines = head_commit.split("\n") + + repository = lines + .find { |line| line.start_with?('Template repository: ') } + .rpartition(' ').last + + commit_sha = lines + .find { |line| line.start_with?('Commit SHA: ') } + .rpartition(' ').last + + [repository, commit_sha] + end +end + +puts "Extracting template to: #{@extracted_template_dir}" + +extract(@extracted_template_dir) +branch = `git rev-parse --abbrev-ref HEAD`.chomp +system('git', 'checkout', 'master', exception: true) +extract(@master_template_dir) +system('git', 'checkout', branch, exception: true) + +puts +puts '🧐 Comparing new template with master' +puts + +system('git', '--no-pager', 'diff', '--no-index', @master_template_dir, @extracted_template_dir) + +puts +puts '--- end diff ---' + +repository, commit_sha = repo_details + +puts +puts "📝 Template is created from #{repository} at commit #{commit_sha}" + +unless repository.start_with?('https://gitlab.com/gitlab-org/project-templates/') + puts '❌ This template does not have the correct origin' + cleanup + exit 1 +end + +puts '🧐 Verifying that template repo matches remote' +puts + +remote_repo_dir = Dir.mktmpdir(@name) + +system('git', 'clone', repository, remote_repo_dir, exception: true) + +Dir.chdir(remote_repo_dir) do + system('git', 'checkout', commit_sha, exception: true) + system('git', '--no-pager', 'show') +end + +extracted_template_repo_dir = File.join(@extracted_template_dir, @name) + +FileUtils.rm_rf(File.join(extracted_template_repo_dir, '.git')) +FileUtils.cp_r(File.join(remote_repo_dir, '.git'), extracted_template_repo_dir) + +Dir.chdir(extracted_template_repo_dir) do + status = `git status` + puts status + puts + + if status.include?('nothing to commit, working tree clean') + puts "✅ Template is up to date with remote commit #{commit_sha}" + else + puts '❌ Template is not synced with remote' + end +end + +FileUtils.rm_rf(remote_repo_dir) +cleanup |