Skip to content

Commit

Permalink
update workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
xuan-cao-swi committed Dec 6, 2023
1 parent 272089d commit 59f0e40
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
32 changes: 4 additions & 28 deletions .github/workflows/publish-package-solarwinds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,9 @@ name: Ruby Gem to Github Package
on:
workflow_dispatch:
inputs:
rubygem-path:
gem_name:
required: true
description: 'The path that package you want to publish (should include /)'
# metrics_sdk/
# metrics_api/
# exporter/otlp/

rubygem-name:
required: true
description: 'The name that package you want to publish'
# opentelemetry-metrics-sdk
# opentelemetry-metrics-api
# opentelemetry-exporter-otlp

version:
required: true
description: 'The package version that you wish to publish'
description: 'The name of gem you want to publish (without opentelemetry e.g. exporter-otlp)'

jobs:
build:
Expand All @@ -37,25 +23,15 @@ jobs:
with:
ruby-version: 3.1

- name: Install gems
run: |
cd ${{ github.event.inputs.rubygem-path }}
echo 'gem: --no-document' >> ~/.gemrc
bundle install
- name: Setup secrets
run: |
mkdir ~/.gem
echo -e "---\n:github: Bearer $GITHUB_SECRET_TOKEN" >> ~/.gem/credentials
chmod 0600 ~/.gem/credentials
env:
GITHUB_SECRET_TOKEN: ${{ secrets.GH_PACKAGE_TOKEN }}
GITHUB_SECRET_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build gem and publish to github package
id: gemstep
run: |
gem_name=${{ github.event.inputs.rubygem-name }}
gem_version=${{ github.event.inputs.version }}
cd ${{ github.event.inputs.rubygem-path }}
gem build "${gem_name}.gemspec"
gem push --key github --host https://rubygems.pkg.github.com/solarwinds "${gem_name}-${gem_version}.gem"
.github/workflows/script//sw_build_and_push_gem.sh ${{ github.event.inputs.gem_name }}
38 changes: 38 additions & 0 deletions .github/workflows/script/sw_build_and_push_gem.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh

GEM_NAME="$1"

case $GEM_NAME in
*metrics-sdk)
echo "metrics-sdk"
GEM_PATH="metrics_sdk/"
;;
*metrics-api)
echo "metrics-api"
GEM_PATH="metrics_api/"
;;
*exporter-otlp)
echo "exporter-otlp"
GEM_PATH="exporter/otlp/"
;;
*)
echo "Unknown file type"
GEM_PATH='nowhere'
;;
esac

cd "$GEM_PATH" || exit 1

bundle install

# get gem version using bash
file_to_find="version.rb"
found_file=$(find "." -type f -name "$file_to_find")
gem_version=$(grep -E "VERSION\s*=\s*'[^']+'" "$found_file" | awk -F "'" '{print $2}')

# build and push gem
gem build "opentelemetry-$GEM_NAME.gemspec"
# gem push --key github --host https://rubygems.pkg.github.com/solarwinds "opentelemetry-instrumentation-$GEM_NAME-$gem_version.gem"

# finished
echo "Finished"

0 comments on commit 59f0e40

Please sign in to comment.