Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: "CodeQL"

on:
push:
pull_request:
schedule:
- cron: '20 0 * * 0'

jobs:
analyze:
name: Analyze (${{ matrix.language }})
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners (GitHub.com only)
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
runs-on: 'ubuntu-latest'
timeout-minutes: 360
permissions:
# required for all workflows
security-events: write

# required to fetch internal or private CodeQL packs
packages: read

# only required for workflows in private repositories
actions: read
contents: read

strategy:
fail-fast: false
matrix:
include:
- language: ruby
build-mode: none
steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
config: |
paths-ignore:
- .evergreen
- spec
- perf
- examples
- test-apps
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- if: matrix.build-mode == 'manual'
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"

88 changes: 88 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: "Gem Release"
run-name: "Gem Release for ${{ github.ref }}"

on:
# for auto-deploy when merging a release-candidate PR
push:
branches:
- 'master'
- '*-stable'

# for manual release
workflow_dispatch:
inputs:
pr:
description: "The number of the merged release candidate PR"
required: true

env:
SILK_ASSET_GROUP: mongoid
GEM_NAME: mongoid
PRODUCT_NAME: Mongoid
PRODUCT_ID: mongoid

permissions:
# required for all workflows
security-events: write

# required to fetch internal or private CodeQL packs
packages: read

# only required for workflows in private repositories
actions: read
pull-requests: read
contents: write

# required by the mongodb-labs/drivers-github-tools/setup@v2 step
# also required by `rubygems/release-gem`
id-token: write

jobs:
check:
name: "Check Release"
runs-on: ubuntu-latest
outputs:
message: ${{ steps.check.outputs.message }}
ref: ${{ steps.check.outputs.ref }}
steps:
- name: "Run the check action"
id: check
uses: jamis/drivers-github-tools/ruby/pr-check@ruby-3643-update-release-process

build:
name: "Build Gems"
needs: check
environment: release
runs-on: ubuntu-latest
steps:
- name: "Run the build action"
uses: jamis/drivers-github-tools/ruby/build@ruby-3643-update-release-process
with:
app_id: ${{ vars.APP_ID }}
app_private_key: ${{ secrets.APP_PRIVATE_KEY }}
artifact: 'ruby-3.2'
gem_name: ${{ env.GEM_NAME }}
ruby_version: 'ruby-3.2'
ref: ${{ needs.check.outputs.ref }}

publish:
name: "Publish Gems"
needs: [ check, build ]
environment: release
runs-on: 'ubuntu-latest'
steps:
- name: "Run the publish action"
uses: jamis/drivers-github-tools/ruby/publish@ruby-3643-update-release-process
with:
app_id: ${{ vars.APP_ID }}
app_private_key: ${{ secrets.APP_PRIVATE_KEY }}
aws_role_arn: ${{ secrets.AWS_ROLE_ARN }}
aws_region_name: ${{ vars.AWS_REGION_NAME }}
aws_secret_id: ${{ secrets.AWS_SECRET_ID }}
dry_run: false
gem_name: ${{ env.GEM_NAME }}
product_name: ${{ env.PRODUCT_NAME }}
product_id: ${{ env.PRODUCT_ID }}
release_message: ${{ needs.check.outputs.message }}
silk_asset_group: ${{ env.SILK_ASSET_GROUP }}
ref: ${{ needs.check.outputs.ref }}
131 changes: 85 additions & 46 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
# rubocop:todo all

require "bundler"
require "bundler/gem_tasks"
Bundler.setup

ROOT = File.expand_path(File.join(File.dirname(__FILE__)))
Expand All @@ -10,34 +10,53 @@ $: << File.join(ROOT, 'spec/shared/lib')

require "rake"
require "rspec/core/rake_task"
require 'mrss/spec_organizer'
require 'rubygems/package'
require 'rubygems/security/policies'

def signed_gem?(path_to_gem)
Gem::Package.new(path_to_gem, Gem::Security::HighSecurity).verify
true
rescue Gem::Security::Exception => e
false
end

$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
require "mongoid/version"

tasks = Rake.application.instance_variable_get('@tasks')
tasks['release:do'] = tasks.delete('release')
if File.exist?('./spec/shared/lib/tasks/candidate.rake')
load 'spec/shared/lib/tasks/candidate.rake'
end

task :gem => :build
desc 'Build the gem'
task :build do
system "gem build mongoid.gemspec"
command = %w[ gem build ]
command << "--output=#{ENV['GEM_FILE_NAME']}" if ENV['GEM_FILE_NAME']
command << (ENV['GEMSPEC'] || 'mongoid.gemspec')
system(*command)
end

task :install => :build do
system "sudo gem install mongoid-#{Mongoid::VERSION}.gem"
# `rake version` is used by the deployment system so get the release version
# of the product beng deployed. It must do nothing more than just print the
# product version number.
#
# See the mongodb-labs/driver-github-tools/ruby/publish Github action.
desc "Print the current value of Mongoid::VERSION"
task :version do
require 'mongoid/version'

puts Mongoid::VERSION
end

# overrides the default Bundler-provided `release` task, which also
# builds the gem. Our release process assumes the gem has already
# been built (and signed via GPG), so we just need `rake release` to
# push the gem to rubygems.
task :release do
raise "Please use ./release.sh to release"
require 'mongoid/version'

if ENV['GITHUB_ACTION'].nil?
abort <<~WARNING
`rake release` must be invoked from the `Mongoid Release` GitHub action,
and must not be invoked locally. This ensures the gem is properly signed
and distributed by the appropriate user.

Note that it is the `rubygems/release-gem@v1` step in the `Mongoid Release`
action that invokes this task. Do not rename or remove this task, or the
release-gem step will fail. Reimplement this task with caution.

mongoid-#{Mongoid::VERSION}.gem was NOT pushed to RubyGems.
WARNING
end

system 'gem', 'push', "mongoid-#{Mongoid::VERSION}.gem"
end

RSpec::Core::RakeTask.new("spec") do |spec|
Expand All @@ -49,6 +68,46 @@ RSpec::Core::RakeTask.new('spec:progress') do |spec|
spec.pattern = "spec/**/*_spec.rb"
end

desc 'Build and validate the evergreen config'
task eg: %w[ eg:build eg:validate ]

# 'eg' == 'evergreen', but evergreen is too many letters for convenience
namespace :eg do
desc 'Builds the .evergreen/config.yml file from the templates'
task :build do
ruby '.evergreen/update-evergreen-configs'
end

desc 'Validates the .evergreen/config.yml file'
task :validate do
system 'evergreen validate --project mongoid .evergreen/config.yml'
end

desc 'Updates the evergreen executable to the latest available version'
task :update do
system 'evergreen get-update --install'
end

desc 'Runs the current branch as an evergreen patch'
task :patch do
system 'evergreen patch --uncommitted --project mongoid --browse --auto-description --yes'
end
end

namespace :generate do
desc 'Generates a mongoid.yml from the template'
task :config do
require 'mongoid'
require 'erb'

template_path = 'lib/rails/generators/mongoid/config/templates/mongoid.yml'
database_name = ENV['DATABASE_NAME'] || 'my_db'

config = ERB.new(File.read(template_path), trim_mode: '-').result(binding)
File.write('mongoid.yml', config)
end
end

CLASSIFIERS = [
[%r,^mongoid/attribute,, :attributes],
[%r,^mongoid/association/[or],, :associations_referenced],
Expand All @@ -64,6 +123,8 @@ RUN_PRIORITY = %i(
)

def spec_organizer
require 'mrss/spec_organizer'

Mrss::SpecOrganizer.new(
root: ROOT,
classifiers: CLASSIFIERS,
Expand Down Expand Up @@ -97,34 +158,12 @@ desc "Generate all documentation"
task :docs => 'docs:yard'

namespace :docs do
desc "Generate yard documention"
desc "Generate yard documentation"
task :yard do
require "mongoid/version"

out = File.join('yard-docs', Mongoid::VERSION)
FileUtils.rm_rf(out)
system "yardoc -o #{out} --title mongoid-#{Mongoid::VERSION}"
end
end

namespace :release do
task :check_private_key do
unless File.exist?('gem-private_key.pem')
raise "No private key present, cannot release"
end
end
end

desc 'Verifies that all built gems in pkg/ are valid'
task :verify do
gems = Dir['pkg/*.gem']
if gems.empty?
puts 'There are no gems in pkg/ to verify'
else
gems.each do |gem|
if signed_gem?(gem)
puts "#{gem} is signed"
else
abort "#{gem} is not signed"
end
end
end
end
26 changes: 0 additions & 26 deletions gem-public_cert.pem

This file was deleted.

6 changes: 5 additions & 1 deletion lib/mongoid/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# frozen_string_literal: true

module Mongoid
VERSION = "7.5.4"
# The current version of Mongoid
#
# Note that this file is automatically updated via `rake candidate:create`.
# Manual changes to this file will be overwritten by that rake task.
VERSION = '7.5.4'
end
8 changes: 8 additions & 0 deletions product.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: Mongoid
description: a Ruby ODM for MongoDB
package: mongoid
jira: https://jira.mongodb.org/projects/MONGOID
version:
number: 7.5.4
file: lib/mongoid/version.rb
Loading
Loading