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
24 changes: 13 additions & 11 deletions .github/workflows/build_for_github_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,37 @@ jobs:
echo 'gem: --no-document' >> ~/.gemrc
bundle install

- name: Grab current version
- name: Build gem
run: bundle exec rake build

- name: Extract version from built gem
id: version
run: |
echo "gem_version=`ruby -e 'require "./lib/solarwinds_apm/version"; puts SolarWindsAPM::Version::STRING'`" >> $GITHUB_OUTPUT
GEM_FILE=$(ls pkg/solarwinds_apm-*.gem | head -1)
VERSION=$(basename "$GEM_FILE" .gem | sed 's/solarwinds_apm-//')
echo "gem_version=$VERSION" >> $GITHUB_OUTPUT

- name: Build gem and publish to github package
- name: Publish to github package
id: gemstep
run: |
mkdir ~/.gem
mkdir -p ~/.gem
echo -e "---\n:github: Bearer $GITHUB_SECRET_TOKEN" >> ~/.gem/credentials
chmod 0600 ~/.gem/credentials
bundle exec rake build_gem_for_github_package[${{ steps.version.outputs.gem_version }}]
bundle exec rake push_gem_to_github_package[${{ steps.version.outputs.gem_version }}]
gem push --key github --host https://rubygems.pkg.github.com/solarwinds pkg/solarwinds_apm-${{ steps.version.outputs.gem_version }}.gem
env:
GITHUB_SECRET_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload to artifact
uses: actions/upload-artifact@v6
with:
name: solarwinds_apm-${{ steps.version.outputs.gem_version }}.gem
path: builds/solarwinds_apm-${{ steps.version.outputs.gem_version }}.gem
path: pkg/solarwinds_apm-${{ steps.version.outputs.gem_version }}.gem

# extract the built layer from artifacts, then scan it with reverselab
reverselab_scan_gem:
needs:
- publish_to_github_package
runs-on: ubuntu-latest
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v6
Expand All @@ -64,15 +66,15 @@ jobs:
uses: actions/download-artifact@v7
with:
name: solarwinds_apm-${{ env.SOLARWINDS_APM_VERSION }}.gem
path: builds
path: pkg
env:
SOLARWINDS_APM_VERSION: ${{needs.publish_to_github_package.outputs.apm_ruby_version}}

- name: Scan build artifact on the Portal
id: rl-scan
uses: reversinglabs/gh-action-rl-scanner-cloud-only@v1
with:
artifact-to-scan: builds/solarwinds_apm-${{ env.SOLARWINDS_APM_VERSION }}.gem
artifact-to-scan: pkg/solarwinds_apm-${{ env.SOLARWINDS_APM_VERSION }}.gem
rl-verbose: true
rl-portal-server: solarwinds
rl-portal-org: SolarWinds
Expand Down
23 changes: 7 additions & 16 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,38 +142,29 @@ See [CONTRIBUTING.md](CONTRIBUTING.md#code-quality) for details.
For local testing:

```bash
bundle exec rake build_gem
bundle exec rake build
```

Output: `builds/solarwinds_apm-X.Y.Z.gem`

The script shows SHA256 checksum and lists the last 5 built gems.

### Build for GitHub Packages

```bash
bundle exec rake build_gem_for_github_package[7.1.0]
```
Output: `pkg/solarwinds_apm-X.Y.Z.gem`

### Push to GitHub Packages

Requires credentials in `~/.gem/credentials`:

```bash
bundle exec rake push_gem_to_github_package[7.1.0]
gem push --key github --host https://rubygems.pkg.github.com/solarwinds pkg/solarwinds_apm-{version}.gem
```

### Build and Publish to RubyGems
### Publish to RubyGems

**For maintainers only:**

Requires `GEM_HOST_API_KEY` environment variable and gem >= 3.0.5.

```bash
gem build solarwinds_apm.gemspec
gem push solarwinds_apm-{version}.gem
gem push pkg/solarwinds_apm-{version}.gem
```

Requires `GEM_HOST_API_KEY` environment variable and gem >= 3.0.5.

## Pull Request Guidelines

For complete PR guidelines, see [CONTRIBUTING.md](CONTRIBUTING.md).
Expand Down
63 changes: 0 additions & 63 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,69 +113,6 @@ def docker_cmd_execute(cmd)
end
end

################ Build Gem Task ################
desc 'Build gem locally for testing'
task :build_gem do
puts "\n=== building for MRI ===\n"
FileUtils.mkdir_p('builds') if Dir['builds'].empty?
File.delete('Gemfile.lock') if Dir['Gemfile.lock'].size == 1

puts "\n=== install required dependencies ===\n"
system('bundle install --without development --without test')

puts "\n=== clean & compile & build ===\n"
system('gem build solarwinds_apm.gemspec')

gemname = Dir['solarwinds_apm*.gem'].first
FileUtils.mv(gemname, 'builds/')

built_gem = Dir['builds/solarwinds_apm*.gem']

puts "\n=== last 5 built gems ===\n"
puts built_gem

puts "\n=== SHA256 ===\n"
system("shasum -a256 #{built_gem.first}")

puts "\n=== Finished ===\n"
end

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

gems = Dir["builds/solarwinds_apm-#{version}.gem"]
gem_to_push = nil
if gems.empty?
Rake::Task['build_gem'].execute
gem_to_push = Dir['builds/solarwinds_apm*.gem'].first
else
gem_to_push = gems.first
end

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*.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

# 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 'Push to github package. Run as bundle exec rake build_gem_push_to_github_package[<version>]'
task :push_gem_to_github_package, [:version] do |_, args|
exit 1 unless system('gem', 'push', '--key', 'github', '--host', 'https://rubygems.pkg.github.com/solarwinds',
"builds/solarwinds_apm-#{args[:version]}.gem")
puts "\n=== Finished ===\n"
end

desc 'Build gem for github package'
task :build_gem_for_github_package, [:version] do |_, args|
find_or_build_gem(args[:version])
end

desc 'Run rubocop and generate result. Run as bundle exec rake rubocop
If want to safely autocorrect enabled, just use bundle exec rake rubocop auto-safe
If want to all autocorrect enabled, just use bundle exec rake rubocop auto-all
Expand Down