Skip to content

Commit

Permalink
Merge pull request #95 from solarwinds/github-package-upload
Browse files Browse the repository at this point in the history
GitHub package upload
  • Loading branch information
xuan-cao-swi authored Dec 4, 2023
2 parents f7073a9 + a286fee commit 03f042a
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 13 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/build_for_github_package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright (c) 2023 SolarWinds, LLC.
# All rights reserved.

name: Ruby Gem to Github Package

on:
workflow_dispatch:

jobs:
build:
name: Build + Publish to Github Package
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Ruby 3.1 and bundle
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1

- name: Install gems
run: |
echo 'gem: --no-document' >> ~/.gemrc
bundle install
- name: Install swig 4.0.2
run: |
apt udate && apt install -y --no-install-recommends bison
curl -SL https://github.com/swig/swig/archive/refs/tags/v4.0.2.tar.gz | tar xzC /tmp
cd /tmp/swig-4.0.2
./autogen.sh && ./configure && make && sudo make install
cd -
- name: Grab current version
id: version
run: |
echo "gem_version=`ruby -e 'require "./lib/solarwinds_apm/version"; puts SolarWindsAPM::Version::STRING'`" >> $GITHUB_OUTPUT
- name: Build gem and publish to github package
id: gemstep
run: |
mkdir ~/.gem
echo -e "---\n:github: Bearer $GITHUB_SECRET_TOKEN" >> ~/.gem/credentials
chmod 0600 ~/.gem/credentials
bundle exec rake build_gem_push_to_github_package[${{ steps.version.outputs.gem_version }}]
env:
GITHUB_SECRET_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38 changes: 27 additions & 11 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,10 @@ task :build_gem do
puts "\n=== Finished ===\n"
end

desc 'Build gem and push to packagecloud. Run as bundle exec rake build_gem_push_to_packagecloud[<version>]'
task :build_gem_push_to_packagecloud, [:version] do |_, args|

require 'package_cloud'
def find_or_build_gem(version)
abort('No version specified.') if version.to_s.empty?

abort('Require PACKAGECLOUD_TOKEN') if ENV['PACKAGECLOUD_TOKEN'].nil? || ENV['PACKAGECLOUD_TOKEN'].empty?
abort('No version specified.') if args[:version].nil? || args[:version].empty?

gems = Dir["builds/solarwinds_apm-#{args[:version]}.gem"]
gems = Dir["builds/solarwinds_apm-#{version}.gem"]
gem_to_push = nil
if gems.empty?
Rake::Task['build_gem'].execute
Expand All @@ -364,15 +359,36 @@ task :build_gem_push_to_packagecloud, [:version] do |_, args|
gem_to_push = gems.first
end

puts "\n=== Gem will be pushed #{gem_to_push} ===\n"
puts "\n=== Gem will be pushed #{gem_to_push} ==="
gem_to_push_version = gem_to_push&.match(/-\d*.\d*.\d*/).to_s.delete!('-')
gem_to_push_version = gem_to_push&.match(/-\d*.\d*.\d*.pre/).to_s.delete!('-') if args[:version].include? 'pre'
gem_to_push_version = gem_to_push&.match(/-\d*.\d*.\d*.prev[0-9]*/).to_s.delete!('-') if version.include? 'prev'

abort('Could not find the required gem file.') if gem_to_push.nil? || gem_to_push_version != version

gem_to_push
end

abort('Could not find the required gem file.') if gem_to_push.nil? || gem_to_push_version != args[:version]
desc 'Build gem and push to packagecloud. Run as bundle exec rake build_gem_push_to_packagecloud[<version>]'
task :build_gem_push_to_packagecloud, [:version] do |_, args|

require 'package_cloud'

abort('Require PACKAGECLOUD_TOKEN') if ENV['PACKAGECLOUD_TOKEN'].to_s.empty?

gem_to_push = find_or_build_gem(args[:version])

cli = PackageCloud::CLI::Entry.new
cli.push('solarwinds/solarwinds-apm-otel-ruby', gem_to_push.strip)
puts "\n=== Finished ===\n"
end

# need set the credentials under ~/.gem/credentials
# for download, easiest way is to set BUNDLE_RUBYGEMS__PKG__GITHUB__COM
# but there are other auth methods. see more on https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-rubygems-registry
desc 'Build gem and push to github package. Run as bundle exec rake build_gem_push_to_github_package[<version>]'
task :build_gem_push_to_github_package, [:version] do |_, args|
gem_to_push = find_or_build_gem(args[:version])
exit 1 unless system('gem', 'push', '--key', 'github', '--host', 'https://rubygems.pkg.github.com/solarwinds', gem_to_push.to_s)
puts "\n=== Finished ===\n"
end

Expand Down
2 changes: 1 addition & 1 deletion lib/solarwinds_apm/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Version
MAJOR = 6 # breaking,
MINOR = 0 # feature,
PATCH = 0 # fix => BFF
PRE = 'preV5'.freeze # for pre-releases into packagecloud, set to nil for production releases into rubygems
PRE = 'prev5'.freeze # for pre-releases into packagecloud, set to nil for production releases into rubygems

STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
end
Expand Down
3 changes: 2 additions & 1 deletion solarwinds_apm.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Gem::Specification.new do |s|
s.metadata = {'changelog_uri' => 'https://github.com/solarwinds/apm-ruby/releases',
'documentation_uri' => 'https://documentation.solarwinds.com/en/success_center/observability/default.htm#cshid=config-ruby-agent',
'homepage_uri' => 'https://documentation.solarwinds.com/en/success_center/observability/content/intro/landing-page.html',
'source_code_uri' => 'https://github.com/solarwinds/apm-ruby'}
'source_code_uri' => 'https://github.com/solarwinds/apm-ruby',
'github_repo' => 'https://github.com/solarwinds/apm-ruby.git'}

s.extra_rdoc_files = ['LICENSE']
# s.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^(test|gemfiles)/}) }
Expand Down

0 comments on commit 03f042a

Please sign in to comment.