-
Notifications
You must be signed in to change notification settings - Fork 8
Updates to DBX Ruby release process #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 28 commits
85e5dcf
3e526e9
84b5369
040fd64
fde9f93
d0e0dec
066352c
057146a
023a472
73e3905
bdbbe4d
96dfd86
fb201ad
ff75009
1eb56ea
3178251
2752ec6
f89b3ee
cccd2b1
d35fd27
5e58425
85472de
7c3926f
10239c3
339da5f
7c38a00
6da6fb7
e74b084
3eece64
e8adfe6
2947587
83826e7
d681705
a385189
e384925
8fd60d1
7c367f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
name: Build Gem | ||
description: Build a gem for a DBX Ruby project | ||
inputs: | ||
app_id: | ||
description: The APP_ID defined for this project | ||
required: true | ||
app_private_key: | ||
description: The APP_PRIVATE_KEY defined for this project | ||
required: true | ||
artifact: | ||
description: The name to give the generated artifact (e.g. "ruby" or "jruby") | ||
required: false | ||
default: ruby | ||
bundler_cache_version: | ||
description: The cache-version to use for the bundler cache | ||
required: false | ||
default: '0' | ||
gem_name: | ||
description: The name (sans extension) of the gemspec file (e.g. "mongo") | ||
required: true | ||
ref: | ||
description: The reference to checkout (branch, tag, sha, etc) | ||
required: true | ||
ruby_version: | ||
description: The version of Ruby to use (see setup-ruby/action.yml) | ||
default: '3.2' | ||
required: false | ||
rubygems_version: | ||
description: The version of Rubygems to use (see setup-ruby/action.yml) | ||
required: false | ||
default: latest | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Check out the repository | ||
uses: mongodb-labs/drivers-github-tools/secure-checkout@v2 | ||
Check failureCode scanning / zizmor unpinned action reference Error
unpinned action reference
|
||
with: | ||
app_id: ${{ inputs.app_id }} | ||
private_key: ${{ inputs.app_private_key }} | ||
ref: ${{ inputs.ref }} | ||
submodules: true | ||
|
||
- name: Setup Ruby | ||
uses: ruby/setup-ruby@v1 | ||
Check failureCode scanning / zizmor unpinned action reference Error
unpinned action reference
|
||
with: | ||
ruby-version: ${{ inputs.ruby_version }} | ||
rubygems: ${{ inputs.rubygems_version }} | ||
bundler-cache: true | ||
cache-version: ${{ inputs.bundler_cache_version }} | ||
|
||
- name: Get the release version | ||
id: release_version | ||
shell: bash | ||
run: echo "version=$(bundle exec rake version)" >> "$GITHUB_OUTPUT" | ||
|
||
- name: Get the gem file name | ||
shell: bash | ||
id: gem_name | ||
run: echo "name=$(ruby ${{ github.action_path }}/gem_name.rb ${{ inputs.gem_name }} ${{ steps.release_version.outputs.version }})" >> "$GITHUB_OUTPUT" | ||
Check failureCode scanning / zizmor code injection via template expansion Error
code injection via template expansion
Check noticeCode scanning / zizmor code injection via template expansion Note
code injection via template expansion
|
||
|
||
- name: Build the gem | ||
shell: bash | ||
run: | | ||
bundle exec rake build GEMSPEC="${{ inputs.gem_name }}.gemspec" GEM_FILE_NAME="${{ steps.gem_name.outputs.name }}" | ||
Check failureCode scanning / zizmor code injection via template expansion Error
code injection via template expansion
Check noticeCode scanning / zizmor code injection via template expansion Note
code injection via template expansion
|
||
|
||
- name: Save the generated gem file for later | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ inputs.artifact }} | ||
path: ${{ steps.gem_name.outputs.name }} | ||
retention-days: 1 | ||
overwrite: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
# This script generates the name of a gem file based on the provided | ||
# gem name and version. It takes into account whether it is running | ||
# under JRuby to append "-java" to the gem name if necessary. | ||
# | ||
# Usage: | ||
# ruby gem_name.rb <gem_name> <gem_version> | ||
|
||
if ARGV.length != 2 | ||
puts "Usage: ruby gem_name.rb <gem_name> <gem_version>" | ||
exit 1 | ||
end | ||
|
||
gem_name = ARGV.first | ||
gem_version = ARGV.last | ||
|
||
base_name = "#{gem_name}-#{gem_version}" | ||
base_name = "#{base_name}-java" if defined?(JRUBY_VERSION) | ||
|
||
puts "#{base_name}.gem" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# PRs are only eligible for release if they are merged and have | ||
# the `release-candidate` label. | ||
# | ||
# The only events allowed to trigger this action are: | ||
# - push (in which case the commit sha is used to find the corresponding | ||
# PR) | ||
# - workflow_dispatch (in which case the PR is found from the inputs | ||
# on the event) | ||
|
||
name: PR Check | ||
description: Check that a PR is eligible for release | ||
|
||
outputs: | ||
message: | ||
description: The body of the pull request that is being released. | ||
value: ${{ steps.check_pr.outputs.message }} | ||
ref: | ||
description: The ref of the pull request that is being released. | ||
value: ${{ steps.check_pr.outputs.ref }} | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: "Check PR Eligibility" | ||
id: check_pr | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
let pr; | ||
|
||
// was this triggered by a push event? | ||
if (context.eventName == 'push') { | ||
// if so, we need to find the PR that corresponds to the commit | ||
// that was pushed. | ||
// | ||
// because only maintainers can push to protected branches, | ||
// we can assume the user has the correct permissions to do | ||
// this. | ||
const { data: listing } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
commit_sha: context.payload.after, | ||
}); | ||
|
||
if (listing.length == 0) { | ||
throw new Error(`Workflow aborted: No pull request found for the pushed commit (${context.payload.after}).`); | ||
} | ||
|
||
const response = await github.rest.pulls.get({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: listing[0].number, | ||
}); | ||
|
||
pr = response.data; | ||
|
||
// if it wasn't triggered by a push event, was it triggered by | ||
// a workflow_dispatch event? | ||
} else if (context.eventName == 'workflow_dispatch') { | ||
// it is technically possible for users with only write access | ||
// to trigger workflows; we need to make sure that the user | ||
// who triggered this has either admin or maintain access to the | ||
// repository. | ||
const username = context.triggering_actor || context.actor; | ||
|
||
const { data: perms } = await github.rest.repos.getCollaboratorPermissionLevel({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
username, | ||
}); | ||
|
||
if (perms.role_name !== 'admin' && perms.role_name !== 'maintain') { | ||
throw new Error(`User ${username} must have 'admin' or 'maintain' role to initiate the release process. (${perms.role_name})`); | ||
} | ||
|
||
// if so, we grab the PR with the number that was passed in with | ||
// the inputs. | ||
const number = context.payload.inputs.pr; | ||
if (!number) { | ||
throw new Error('Workflow aborted: No pull request number provided. (need `pr` input)'); | ||
} | ||
|
||
const response = await github.rest.pulls.get({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: number, | ||
}); | ||
|
||
pr = response.data; | ||
|
||
// workflow was triggered by an unrecognized/unsupported event | ||
} else { | ||
throw new Error(`Workflow aborted: Unsupported event type: ${context.eventName}.`); | ||
} | ||
|
||
if (!pr) { | ||
throw new Error('No pull request found for the triggered event.'); | ||
} | ||
|
||
if (!pr.merged) { | ||
throw new Error('Pull request is not merged.'); | ||
} | ||
|
||
if (!pr.labels.some(label => label.name == 'release-candidate')) { | ||
throw new Error('Pull request is not a release candidate.'); | ||
} | ||
|
||
console.log('body: >>', pr.body, '<<'); | ||
console.log('ref: >>', pr.merge_commit_sha, '<<'); | ||
|
||
core.setOutput('message', pr.body); | ||
core.setOutput('ref', pr.merge_commit_sha); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cat on keyboard or intentional identifier that's guaranteed to not create conflicts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intentional; I've added a comment to justify it.