From 554d6ccb706732769cc9ed6f8ffc63af049cd9a9 Mon Sep 17 00:00:00 2001 From: Carson Long <12767276+ctlong@users.noreply.github.com> Date: Tue, 19 Nov 2024 15:41:31 -0800 Subject: [PATCH 1/2] fix(tasks/validate-all-jobs-public): Scan correct directory Scans the `ci` directory, as desired. It was previously trying to scan the `pipelines` directory, which doesn't exist. Uses the ruby 3.1-slim image instead of the older 2.3-slim image. Removes the dependence on the Gemfile at the base of the repo, instead making this a standalone ruby script. --- tasks/validate-all-jobs-public/task | 15 -------- tasks/validate-all-jobs-public/task.rb | 38 +++++++++++++++++++ tasks/validate-all-jobs-public/task.yml | 6 +-- .../validate_jobs_public.rb | 14 ------- 4 files changed, 41 insertions(+), 32 deletions(-) delete mode 100755 tasks/validate-all-jobs-public/task create mode 100755 tasks/validate-all-jobs-public/task.rb delete mode 100644 tasks/validate-all-jobs-public/validate_jobs_public.rb diff --git a/tasks/validate-all-jobs-public/task b/tasks/validate-all-jobs-public/task deleted file mode 100755 index ec6aa5f76..000000000 --- a/tasks/validate-all-jobs-public/task +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -set -exu - -# Inputs -RUNTIME_CI_DIR="${PWD}/${RUNTIME_CI_DIR:?"\$RUNTIME_CI_DIR not set"}" - -pushd "${RUNTIME_CI_DIR}" > /dev/null - PARSED_BUNDLE_VERSION=$(sed -n '/BUNDLED WITH/{;n;p;}' Gemfile.lock) - gem uninstall bundler - gem install bundler --version "$PARSED_BUNDLE_VERSION" - bundle install - bundle exec rspec \ - --color \ - "tasks/validate-all-jobs-public/validate_jobs_public.rb" -popd > /dev/null diff --git a/tasks/validate-all-jobs-public/task.rb b/tasks/validate-all-jobs-public/task.rb new file mode 100755 index 000000000..ac333d82d --- /dev/null +++ b/tasks/validate-all-jobs-public/task.rb @@ -0,0 +1,38 @@ +#!/usr/bin/env ruby + +require 'yaml' + +def find_yaml_files(directory) + yaml_files = Dir.glob(File.join(directory, '**', '*.yaml')) + yml_files = Dir.glob(File.join(directory, '**', '*.yml')) + yaml_files + yml_files +end + +directory = ENV['RUNTIME_CI_DIR'] +if directory.nil? || directory.strip.empty? + puts "Error: Please set the RUNTIME_CI_DIR environment variable to specify the directory." +end + +yaml_files = find_yaml_files(directory) +puts "Found #{yaml_files.size} YAML files in #{directory}" + +failure = false + +yaml_files.each do |file| + puts "Checking #{file}..." + yaml_content = YAML.load_file(file, aliases: true) + next unless yaml_content.is_a?(Hash) && yaml_content.key?('jobs') + yaml_content['jobs'].each do |job| + unless job['public'] == true + puts "- #{job['name']} is not public." + failure = true + end + end +end + +if failure + puts 'Error: Some jobs are not public' + exit 1 +end + +puts 'All jobs are public!' diff --git a/tasks/validate-all-jobs-public/task.yml b/tasks/validate-all-jobs-public/task.yml index 671cd7b8d..eac38a0c7 100644 --- a/tasks/validate-all-jobs-public/task.yml +++ b/tasks/validate-all-jobs-public/task.yml @@ -5,13 +5,13 @@ image_resource: type: docker-image source: repository: ruby - tag: 2.3-slim + tag: 3.1-slim inputs: - name: runtime-ci run: - path: runtime-ci/tasks/validate-all-jobs-public/task + path: runtime-ci/tasks/validate-all-jobs-public/task.rb params: - RUNTIME_CI_DIR: runtime-ci + RUNTIME_CI_DIR: runtime-ci/ci diff --git a/tasks/validate-all-jobs-public/validate_jobs_public.rb b/tasks/validate-all-jobs-public/validate_jobs_public.rb deleted file mode 100644 index d014557b3..000000000 --- a/tasks/validate-all-jobs-public/validate_jobs_public.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'yaml' - -Dir.glob("pipelines/*.yml").each do |f| - job_array = YAML.load_file(f)['jobs'].map{ |j| {:name => j['name'], :public => j['public']} } - job_array.each do |job| - RSpec.describe "pipeline jobs" do - context "for #{f}\##{job[:name]}" do - it "should have public: true" do - expect(job[:public]).to be_truthy - end - end - end - end -end From 486b293d9d973617e1ed7bbacba35a53fb84b729 Mon Sep 17 00:00:00 2001 From: Carson Long <12767276+ctlong@users.noreply.github.com> Date: Tue, 19 Nov 2024 15:58:05 -0800 Subject: [PATCH 2/2] chore: Remove unnecessary Gemfile Removing the Gemfile that, as far as I can tell, was only used by the validate-all-jobs-public task. --- Gemfile | 3 --- Gemfile.lock | 26 -------------------------- 2 files changed, 29 deletions(-) delete mode 100644 Gemfile delete mode 100644 Gemfile.lock diff --git a/Gemfile b/Gemfile deleted file mode 100644 index b0c76457f..000000000 --- a/Gemfile +++ /dev/null @@ -1,3 +0,0 @@ -source 'https://rubygems.org' - -gem 'rspec' diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 462e03252..000000000 --- a/Gemfile.lock +++ /dev/null @@ -1,26 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - diff-lcs (1.3) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.0) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.2) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.0) - -PLATFORMS - ruby - -DEPENDENCIES - rspec - -BUNDLED WITH - 2.0.1