Skip to content
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

Add release steps to the buildkite pipeline #544

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions .buildkite/pipeline.release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
agents:
queue: hosted

steps:
- command: "auto/release-gem"
label: ":rubygems:"
key: release
env:
RELEASE_VERSION: "__TEMPLATE__"

35 changes: 33 additions & 2 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,32 @@ agents:
steps:
- command: "auto/run-sorbet"
label: ":sorbet:"
key: sorbet
env:
DOCKER_IMAGE: "ruby"
RUBY_VERSION: "3.1"

- command: "auto/run-require-strict-typing"
label: "typed: strict"
key: strict-typing
env:
DOCKER_IMAGE: "ruby"
RUBY_VERSION: "3.1"

- command: "auto/run-quality"
label: "quality"
key: quality
env:
DOCKER_IMAGE: "ruby"
RUBY_VERSION: "3.1"

- wait

- command: "auto/run-specs"
label: "rspec ({{matrix}})"
key: specs-legacy
depends_on:
- quality
- sorbet
- strict-typing
env:
DOCKER_IMAGE: "ruby"
RUBY_VERSION: "{{matrix}}"
Expand All @@ -39,6 +45,11 @@ steps:

- command: "auto/run-specs"
label: "rspec ({{matrix}})"
key: specs
depends_on:
- quality
- sorbet
- strict-typing
env:
DOCKER_IMAGE: "ruby"
RUBY_VERSION: "{{matrix}}"
Expand All @@ -51,6 +62,11 @@ steps:

- command: "auto/run-specs"
label: "rspec (jruby-{{matrix}})"
key: specs-jruby
depends_on:
- quality
- sorbet
- strict-typing
env:
DOCKER_IMAGE: "jruby"
RUBY_VERSION: "{{matrix}}"
Expand All @@ -62,9 +78,24 @@ steps:

- command: "auto/run-specs"
label: "rspec (jruby-{{matrix}})"
key: specs-jruby-soft
depends_on:
- quality
- sorbet
- strict-typing
env:
DOCKER_IMAGE: "jruby"
RUBY_VERSION: "{{matrix}}"
soft_fail: true
matrix:
- "9.4"

- command: "auto/upload-release-steps"
label: "release?"
key: upload-release
depends_on:
- specs
- specs-legacy
- specs-jruby
- specs-jruby-soft
#branch: main
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uncomment this before merging

50 changes: 50 additions & 0 deletions auto/release-gem
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

set -euo pipefail

echo "--- Request OIDC token"

export BUILDKITE_OIDC_TOKEN="$(buildkite-agent oidc request-token --audience "rubygems.org" --lifetime 60)"

echo "${BUILDKITE_OIDC_TOKEN}" | head -c 20
echo

echo "--- Request rubygems token"

RUBYGEMS_ROLE="rg_oidc_akr_xoy8sqmj25t8ok4rn5sq"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks secret, but not actually that secret


echo "{\"jwt\":\"${BUILDKITE_OIDC_TOKEN}\"}" | head -c 30
echo

#curl -v -s -X POST \
# --fail-with-body \
# -H "Content-Type: application/json" \
# --data "{\"jwt\":\"${BUILDKITE_OIDC_TOKEN}\"}" \
# "https://rubygems.org/api/v1/oidc/api_key_roles/${RUBYGEMS_ROLE}/assume_role"

#--fail-with-body \
RESPONSE=$(curl -s -X POST \
-H "Content-Type: application/json" \
--data "{\"jwt\":\"${BUILDKITE_OIDC_TOKEN}\"}" \
"https://rubygems.org/api/v1/oidc/api_key_roles/${RUBYGEMS_ROLE}/assume_role")

ERROR_MESSAGE=$(echo "${RESPONSE}" | jq -r .error)
GEM_HOST_API_KEY==$(echo "${RESPONSE}" | jq -r .rubygems_api_key)

if [ "${ERROR_MESSAGE}" != "null" ]; then
echo "Requesting API token failed"
echo "ERROR: ${ERROR_MESSAGE}"
exit 1
fi

echo "${GEM_HOST_API_KEY}" | head -c 10

echo "--- Build and publish gem"

cd $(dirname $0)/..

# apt-get update --assume-yes && apt-get install --assume-yes ruby-rubygems
# gem build pdf-reader.gemspec
# GEM_HOST_API_KEY="${GEM_HOST_API_KEY}" gem push "pdf-reader-${RELEASE_VERSION}.gem"

docker run -it -v "${PWD}:/work" -w /work -e GEM_HOST_API_KEY="${GEM_HOST_API_KEY}" ruby:3.4-slim bash -c "gem build pdf-reader.gemspec && gem push \"pdf-reader-${RELEASE_VERSION}.gem\""
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could go back to using the gem available in ubuntu's repositories, this was just be testing to see if the newer rubygems version helped.

23 changes: 23 additions & 0 deletions auto/upload-release-steps
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

set -euo pipefail

#if [ "${BUILDKITE_BRANCH}" != "main" ]; then
# echo "Non main branch, skipping release"
# exit
#fi

GEMSPEC_PATH="$(dirname $0)/../pdf-reader.gemspec"

RELEASE_VERSION=$(grep "spec.version =" $GEMSPEC_PATH | sed -r 's/.*spec.version = "([^"]+)".*/\1/')

echo "version: ${RELEASE_VERSION}"

if [ $(curl -s -o /dev/null -w "%{http_code}" https://rubygems.org/api/v2/rubygems/pdf-reader/versions/${RELEASE_VERSION}.json) == "200" ]; then
echo "Gem version ${RELEASE_VERSION} already found on rubygems, skipping release"
exit
fi

export RELEASE_VERSION

cat $(dirname $0)/../.buildkite/pipeline.release.yml | sed -r 's/__TEMPLATE__/${RELEASE_VERSION}/' | buildkite-agent pipeline upload
2 changes: 1 addition & 1 deletion pdf-reader.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# which will make the gem filesize irritatingly large
Gem::Specification.new do |spec|
spec.name = "pdf-reader"
spec.version = "2.13.0"
spec.version = "2.14.0"
spec.summary = "A library for accessing the content of PDF files"
spec.description = "The PDF::Reader library implements a PDF parser conforming as much as possible to the PDF specification from Adobe"
spec.license = "MIT"
Expand Down