Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby GitHub Packages

Ruby GitHub Packages

RubyGems is the default server when publishing a public gem but, sometimes, you can't open source your work. An alternative solution is to use GitHub Packages for publishing private gems so your internal programs, applications, and/or services can have the same convenience as what you'd find when using RubyGems. In this talk, you'll learn how to use Gemsmith to publish your gem to your own GitHub Packages repository while using GitHub Actions to automate the entire process.

Brooke Kuhlmann

April 15, 2022
Tweet

More Decks by Brooke Kuhlmann

Other Decks in Programming

Transcript

  1. • Gemsmith • Server Choices • GitHub Packages + Actions

    • Source Code • Debugging Techniques Overview
  2. New Version 🚀 1. Builds releases notes. 2. Tags version.

    3. Publishes gem. 1 https://docs.github.com/en/actions
  3. No Versions 🚫 💡 Only fi rst version is manual.

    https://docs.github.com/en/actions
  4. Gem::Specification.new do |spec| spec.name = "demo" spec.version = "0.0.0" spec.authors

    = ["Alchemists Engineering"] spec.email = ["[email protected]"] spec.homepage = "https://www.alchemists.io/projects/demo" spec.summary = "This is a demo gem." spec.license = "Nonstandard" spec.metadata = { "allowed_push_host" => "https://rubygems.pkg.github.com/alchemists", "bug_tracker_uri" => "https://github.com/alchemists/demo/issues", "changelog_uri" => "https://www.alchemists.io/projects/demo/versions", "documentation_uri" => "https://www.alchemists.io/projects/demo", "label" => "Demo", "source_code_uri" => "https://github.com/alchemists/demo" } spec.required_ruby_version = "~> 3.1" spec.add_dependency "auto_injector", "~> 0.4" spec.add_dependency "dry-container", "~> 0.9" spec.add_dependency "refinements", "~> 9.2" spec.add_dependency "runcom", "~> 8.2" spec.add_dependency "spek", "~> 0.2" spec.add_dependency "zeitwerk", "~> 2.5" spec.bindir = "exe" spec.executables << "demo" spec.extra_rdoc_files = Dir["README*", "LICENSE*"] spec.files = Dir["*.gemspec", "lib/**/*"] end https://www.alchemists.io/projects/gemsmith
  5. Gem::Specification.new do |spec| spec.name = "demo" spec.version = "0.0.0" spec.authors

    = ["Alchemists Engineering"] spec.email = ["[email protected]"] spec.homepage = "https://www.alchemists.io/projects/demo" spec.summary = "This is a demo gem." spec.license = "Nonstandard" spec.metadata = { "allowed_push_host" => "https://rubygems.pkg.github.com/alchemists", "bug_tracker_uri" => "https://github.com/alchemists/demo/issues", "changelog_uri" => "https://www.alchemists.io/projects/demo/versions", "documentation_uri" => "https://www.alchemists.io/projects/demo", "label" => "Demo", "source_code_uri" => "https://github.com/alchemists/demo" } spec.required_ruby_version = "~> 3.1" spec.add_dependency "auto_injector", "~> 0.4" spec.add_dependency "dry-container", "~> 0.9" spec.add_dependency "refinements", "~> 9.2" spec.add_dependency "runcom", "~> 8.2" spec.add_dependency "spek", "~> 0.2" spec.add_dependency "zeitwerk", "~> 2.5" spec.bindir = "exe" spec.executables << "demo" spec.extra_rdoc_files = Dir["README*", "LICENSE*"] spec.files = Dir["*.gemspec", "lib/**/*"] end https://www.alchemists.io/projects/gemsmith ❗Only update when ready to release
  6. Gem::Specification.new do |spec| spec.name = "demo" spec.version = "0.0.0" spec.authors

    = ["Alchemists Engineering"] spec.email = ["[email protected]"] spec.homepage = "https://www.alchemists.io/projects/demo" spec.summary = "This is a demo gem." spec.license = "Nonstandard" spec.metadata = { "allowed_push_host" => "https://rubygems.pkg.github.com/alchemists", "bug_tracker_uri" => "https://github.com/alchemists/demo/issues", "changelog_uri" => "https://www.alchemists.io/projects/demo/versions", "documentation_uri" => "https://www.alchemists.io/projects/demo", "label" => "Demo", "source_code_uri" => "https://github.com/alchemists/demo" } spec.required_ruby_version = "~> 3.1" spec.add_dependency "auto_injector", "~> 0.4" spec.add_dependency "dry-container", "~> 0.9" spec.add_dependency "refinements", "~> 9.2" spec.add_dependency "runcom", "~> 8.2" spec.add_dependency "spek", "~> 0.2" spec.add_dependency "zeitwerk", "~> 2.5" spec.bindir = "exe" spec.executables << "demo" spec.extra_rdoc_files = Dir["README*", "LICENSE*"] spec.files = Dir["*.gemspec", "lib/**/*"] end (also your gem credentials key) https://www.alchemists.io/projects/gemsmith
  7. Gem::Specification.new do |spec| spec.metadata = { "allowed_push_host" => "https://rubygems.pkg.github.com/alchemists" }

    end https://rubygems.pkg.github.com/alchemists: Bearer <redacted> Gem Speci fi cation Gem Credentials
  8. name: Gemsmith on: push: branches: main jobs: build: runs-on: ubuntu-latest

    container: image: ruby:latest permissions: contents: write packages: write steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: '0' ref: ${{github.head_ref}} - name: Setup run: | git config user.email "[email protected]" git config user.name "Alchemists Publisher" mkdir -p $HOME/.gem printf "%s\n" "https://rubygems.pkg.github.com/alchemists: Bearer ${{secrets.GITHUB_TOKEN}}" > $HOME/.gem/credentials chmod 0600 $HOME/.gem/credentials - name: Install run: gem install gemsmith - name: Publish run: | if git describe --tags --abbrev=0 > /dev/null 2>&1; then gemsmith --publish else printf "%s\n" "First gem version must be manually created. Skipping." https://docs.github.com/en/actions
  9. name: Gemsmith on: push: branches: main jobs: build: runs-on: ubuntu-latest

    container: image: ruby:latest permissions: contents: write packages: write steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: '0' ref: ${{github.head_ref}} - name: Setup run: | git config user.email "[email protected]" git config user.name "Alchemists Publisher" mkdir -p $HOME/.gem printf "%s\n" "https://rubygems.pkg.github.com/alchemists: Bearer ${{secrets.GITHUB_TOKEN}}" > $HOME/.gem/credentials chmod 0600 $HOME/.gem/credentials - name: Install run: gem install gemsmith - name: Publish run: | if git describe --tags --abbrev=0 > /dev/null 2>&1; then gemsmith --publish else printf "%s\n" "First gem version must be manually created. Skipping." https://docs.github.com/en/actions
  10. name: Gemsmith on: push: branches: main jobs: build: runs-on: ubuntu-latest

    container: image: ruby:latest permissions: contents: write packages: write steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: '0' ref: ${{github.head_ref}} - name: Setup run: | git config user.email "[email protected]" git config user.name "Alchemists Publisher" mkdir -p $HOME/.gem printf "%s\n" "https://rubygems.pkg.github.com/alchemists: Bearer ${{secrets.GITHUB_TOKEN}}" > $HOME/.gem/credentials chmod 0600 $HOME/.gem/credentials - name: Install run: gem install gemsmith - name: Publish run: | if git describe --tags --abbrev=0 > /dev/null 2>&1; then gemsmith --publish else printf "%s\n" "First gem version must be manually created. Skipping." https://docs.github.com/en/actions
  11. name: Gemsmith on: push: branches: main jobs: build: runs-on: ubuntu-latest

    container: image: ruby:latest permissions: contents: write packages: write steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: '0' ref: ${{github.head_ref}} - name: Setup run: | git config user.email "[email protected]" git config user.name "Alchemists Publisher" mkdir -p $HOME/.gem printf "%s\n" "https://rubygems.pkg.github.com/alchemists: Bearer ${{secrets.GITHUB_TOKEN}}" > $HOME/.gem/credentials chmod 0600 $HOME/.gem/credentials - name: Install run: gem install gemsmith - name: Publish run: | if git describe --tags --abbrev=0 > /dev/null 2>&1; then gemsmith --publish else printf "%s\n" "First gem version must be manually created. Skipping." https://docs.github.com/en/actions
  12. name: Gemsmith on: push: branches: main jobs: build: runs-on: ubuntu-latest

    container: image: ruby:latest permissions: contents: write packages: write steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: '0' ref: ${{github.head_ref}} - name: Setup run: | git config user.email "[email protected]" git config user.name "Alchemists Publisher" mkdir -p $HOME/.gem printf "%s\n" "https://rubygems.pkg.github.com/alchemists: Bearer ${{secrets.GITHUB_TOKEN}}" > $HOME/.gem/credentials chmod 0600 $HOME/.gem/credentials - name: Install run: gem install gemsmith - name: Publish run: | if git describe --tags --abbrev=0 > /dev/null 2>&1; then gemsmith --publish else printf "%s\n" "First gem version must be manually created. Skipping." Git Tags https://docs.github.com/en/actions
  13. name: Gemsmith on: push: branches: main jobs: build: runs-on: ubuntu-latest

    container: image: ruby:latest permissions: contents: write packages: write steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: '0' ref: ${{github.head_ref}} - name: Setup run: | git config user.email "[email protected]" git config user.name "Alchemists Publisher" mkdir -p $HOME/.gem printf "%s\n" "https://rubygems.pkg.github.com/alchemists: Bearer ${{secrets.GITHUB_TOKEN}}" > $HOME/.gem/credentials chmod 0600 $HOME/.gem/credentials - name: Install run: gem install gemsmith - name: Publish run: | if git describe --tags --abbrev=0 > /dev/null 2>&1; then gemsmith --publish else printf "%s\n" "First gem version must be manually created. Skipping." Packages https://docs.github.com/en/actions
  14. name: Gemsmith on: push: branches: main jobs: build: runs-on: ubuntu-latest

    container: image: ruby:latest permissions: contents: write packages: write steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: '0' ref: ${{github.head_ref}} - name: Setup run: | git config user.email "[email protected]" git config user.name "Alchemists Publisher" mkdir -p $HOME/.gem printf "%s\n" "https://rubygems.pkg.github.com/alchemists: Bearer ${{secrets.GITHUB_TOKEN}}" > $HOME/.gem/credentials chmod 0600 $HOME/.gem/credentials - name: Install run: gem install gemsmith - name: Publish run: | if git describe --tags --abbrev=0 > /dev/null 2>&1; then gemsmith --publish else printf "%s\n" "First gem version must be manually created. Skipping." https://docs.github.com/en/actions
  15. name: Gemsmith on: push: branches: main jobs: build: runs-on: ubuntu-latest

    container: image: ruby:latest permissions: contents: write packages: write steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: '0' ref: ${{github.head_ref}} - name: Setup run: | git config user.email "[email protected]" git config user.name "Alchemists Publisher" mkdir -p $HOME/.gem printf "%s\n" "https://rubygems.pkg.github.com/alchemists: Bearer ${{secrets.GITHUB_TOKEN}}" > $HOME/.gem/credentials chmod 0600 $HOME/.gem/credentials - name: Install run: gem install gemsmith - name: Publish run: | if git describe --tags --abbrev=0 > /dev/null 2>&1; then gemsmith --publish else printf "%s\n" "First gem version must be manually created. Skipping." https://docs.github.com/en/actions
  16. name: Gemsmith on: push: branches: main jobs: build: runs-on: ubuntu-latest

    container: image: ruby:latest permissions: contents: write packages: write steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: '0' ref: ${{github.head_ref}} - name: Setup run: | git config user.email "[email protected]" git config user.name "Alchemists Publisher" mkdir -p $HOME/.gem printf "%s\n" "https://rubygems.pkg.github.com/alchemists: Bearer ${{secrets.GITHUB_TOKEN}}" > $HOME/.gem/credentials chmod 0600 $HOME/.gem/credentials - name: Install run: gem install gemsmith - name: Publish run: | if git describe --tags --abbrev=0 > /dev/null 2>&1; then gemsmith --publish else printf "%s\n" "First gem version must be manually created. Skipping." https://docs.github.com/en/actions
  17. name: Gemsmith on: push: branches: main jobs: build: runs-on: ubuntu-latest

    container: image: ruby:latest permissions: contents: write packages: write steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: '0' ref: ${{github.head_ref}} - name: Setup run: | git config user.email "[email protected]" git config user.name "Alchemists Publisher" mkdir -p $HOME/.gem printf "%s\n" "https://rubygems.pkg.github.com/alchemists: Bearer ${{secrets.GITHUB_TOKEN}}" > $HOME/.gem/credentials chmod 0600 $HOME/.gem/credentials - name: Install run: gem install gemsmith - name: Publish run: | if git describe --tags --abbrev=0 > /dev/null 2>&1; then gemsmith --publish else printf "%s\n" "First gem version must be manually created. Skipping." https://docs.github.com/en/actions
  18. name: Gemsmith on: push: branches: main jobs: build: runs-on: ubuntu-latest

    container: image: ruby:latest permissions: contents: write packages: write steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: '0' ref: ${{github.head_ref}} - name: Setup run: | git config user.email "[email protected]" git config user.name "Alchemists Publisher" mkdir -p $HOME/.gem printf "%s\n" "https://rubygems.pkg.github.com/alchemists: Bearer ${{secrets.GITHUB_TOKEN}}" > $HOME/.gem/credentials chmod 0600 $HOME/.gem/credentials - name: Install run: gem install gemsmith - name: Publish run: | if git describe --tags --abbrev=0 > /dev/null 2>&1; then gemsmith --publish else printf "%s\n" "First gem version must be manually created. Skipping." https://docs.github.com/en/actions
  19. name: Gemsmith on: push: branches: main jobs: build: runs-on: ubuntu-latest

    container: image: ruby:latest permissions: contents: write packages: write steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: '0' ref: ${{github.head_ref}} - name: Setup run: | git config user.email "[email protected]" git config user.name "Alchemists Publisher" mkdir -p $HOME/.gem printf "%s\n" "https://rubygems.pkg.github.com/alchemists: Bearer ${{secrets.GITHUB_TOKEN}}" > $HOME/.gem/credentials chmod 0600 $HOME/.gem/credentials - name: Install run: gem install gemsmith - name: Publish run: | if git describe --tags --abbrev=0 > /dev/null 2>&1; then gemsmith --publish else printf "%s\n" "First gem version must be manually created. Skipping." https://docs.github.com/en/actions
  20. name: Gemsmith on: push: branches: main jobs: build: runs-on: ubuntu-latest

    container: image: ruby:latest permissions: contents: write packages: write steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: '0' ref: ${{github.head_ref}} - name: Setup run: | git config user.email "[email protected]" git config user.name "Alchemists Publisher" mkdir -p $HOME/.gem printf "%s\n" "https://rubygems.pkg.github.com/alchemists: Bearer ${{secrets.GITHUB_TOKEN}}" > $HOME/.gem/credentials chmod 0600 $HOME/.gem/credentials - name: Install run: gem install gemsmith - name: Publish run: | if git describe --tags --abbrev=0 > /dev/null 2>&1; then gemsmith --publish else printf "%s\n" "First gem version must be manually created. Skipping." https://docs.github.com/en/actions
  21. name: Gemsmith on: push: branches: main jobs: build: runs-on: ubuntu-latest

    container: image: ruby:latest permissions: contents: write packages: write steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: '0' ref: ${{github.head_ref}} - name: Setup run: | git config user.email "[email protected]" git config user.name "Alchemists Publisher" mkdir -p $HOME/.gem printf "%s\n" "https://rubygems.pkg.github.com/alchemists: Bearer ${{secrets.GITHUB_TOKEN}}" > $HOME/.gem/credentials chmod 0600 $HOME/.gem/credentials - name: Install run: gem install gemsmith - name: Publish run: | if git describe --tags --abbrev=0 > /dev/null 2>&1; then gemsmith --publish else printf "%s\n" "First gem version must be manually created. Skipping." https://docs.github.com/en/actions
  22. name: Gemsmith on: push: branches: main jobs: build: runs-on: ubuntu-latest

    container: image: ruby:latest permissions: contents: write packages: write steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: '0' ref: ${{github.head_ref}} - name: Setup run: | git config user.email "[email protected]" git config user.name "Alchemists Publisher" mkdir -p $HOME/.gem printf "%s\n" "https://rubygems.pkg.github.com/alchemists: Bearer ${{secrets.GITHUB_TOKEN}}" > $HOME/.gem/credentials chmod 0600 $HOME/.gem/credentials - name: Install run: gem install gemsmith - name: Publish run: | if git describe --tags --abbrev=0 > /dev/null 2>&1; then gemsmith --publish else printf "%s\n" "First gem version must be manually created. Skipping." 🎉 https://docs.github.com/en/actions