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

NH-55892 upload workflow #1

Merged
merged 8 commits into from
Dec 6, 2023
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
34 changes: 34 additions & 0 deletions .github/workflows/push-package-solarwinds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Ruby Gem to SolarWinds Github Package

on:
workflow_dispatch:
inputs:
gem_name:
required: true
description: 'The name of gem you want to publish (without opentelemetry-instrumentation e.g. aws_sdk)'

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: Setup secrets
run: |
mkdir ~/.gem
echo -e "---\n:github: Bearer $GITHUB_SECRET_TOKEN" >> ~/.gem/credentials

Choose a reason for hiding this comment

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

I think this file could be shortened by not setting env below and directly using secrets.GITHUB_TOKEN

Copy link
Author

Choose a reason for hiding this comment

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

I don't think that will work. Do you have any reference that I can take look?

Choose a reason for hiding this comment

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

Ah ok. We can keep it that way.

chmod 0600 ~/.gem/credentials
env:
GITHUB_SECRET_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build gem and publish to github package
id: gemstep
run: |
./script/sw_build_and_push_gem.sh ${{ github.event.inputs.gem_name }}
19 changes: 19 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,19 @@
#!/bin/bash

GEM_NAME="$1"

cd "instrumentation/$GEM_NAME" || 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-instrumentation-$GEM_NAME.gemspec"

Choose a reason for hiding this comment

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

What happens with gem build if there is a typo in the input gem name?

Copy link
Author

@xuan-cao-swi xuan-cao-swi Dec 5, 2023

Choose a reason for hiding this comment

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

actually, if there is a typo of the gem name, then it won't find the correct path, and based on the linted line 5 (cd "instrumentation/$GEM_NAME" || exit), it will exit from shell script (kind remind me to give an exit status code)

Choose a reason for hiding this comment

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

Nice!

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

# finished
echo "Finished"