Skip to content

Commit

Permalink
Add push to rubygems action
Browse files Browse the repository at this point in the history
  • Loading branch information
uvlad7 committed Oct 29, 2023
1 parent 4a3397e commit 65bce32
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 13 deletions.
61 changes: 59 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,70 @@ jobs:
- name: Test cross-compiled gem
uses: oxidize-rb/actions/test-gem-build@main
with:
platform: ${{ matrix.ruby-platform }}
platform: ${{ matrix.platform }}
ruby-versions: ${{ needs.ci-data.outputs.ruby_versions }}

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: cross-gem-${{ matrix.platform }}
name: cross-gems
path: ${{ steps.cross-gem.outputs.gem-path }}
if-no-files-found: error
retention-days: 1

release:
name: Release
strategy:
matrix:
ruby:
- '2.7.8'
rust:
- "1.72.1"
needs: build
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Ruby & Rust
uses: oxidize-rb/actions/setup-ruby-and-rust@v1
with:
ruby-version: ${{ matrix.ruby }}
rustup-toolchain: ${{ matrix.rust }}
bundler-cache: true
cargo-cache: true
rubygems: '3.4.14'
- name: Ensure version matches the tag
run: |
bundle exec ruby "$GITHUB_WORKSPACE/actions/check_version.rb" "$GITHUB_REF_NAME" \
"$GITHUB_WORKSPACE/xml2json.gemspec" "$GITHUB_WORKSPACE/ext/xml2json/Cargo.toml"
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: cross-gems
- name: Package source gem
run: bundle exec rake build

- name: Push gem
working-directory: pkg/
env:
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_KEY }}
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
ls -l
for i in *.gem; do
if [ -f "$i" ]; then
gem push "$i"
fi
done
- name: Create GitHub release
uses: ncipollo/release-action@v1
with:
allowUpdates: false
generateReleaseNotes: true
draft: false
skipIfReleaseExists: true
26 changes: 15 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,13 @@ PATH
remote: .
specs:
xml2json-rb (0.3.0)
pry
pry-byebug
puma
rack
rackup
rake (~> 13.0)
rake-compiler
rb_sys (~> 0.9.63)
rspec (~> 3.0)
rubocop (~> 1.21)
yard

GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
byebug (11.1.3)
citrus (3.0.2)
coderay (1.1.3)
diff-lcs (1.5.0)
json (2.6.3)
Expand Down Expand Up @@ -76,6 +66,8 @@ GEM
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
toml-rb (2.2.0)
citrus (~> 3.0, > 3.0)
unicode-display_width (2.4.2)
webrick (1.8.1)
yard (0.9.34)
Expand All @@ -84,7 +76,19 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
pry
pry-byebug
puma
rack
rackup
rake (~> 13.0)
rake-compiler
rb_sys (~> 0.9.63)
rspec (~> 3.0)
rubocop (~> 1.21)
toml-rb
xml2json-rb!
yard

BUNDLED WITH
2.4.10
11 changes: 11 additions & 0 deletions actions/check_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require "toml-rb"

tag = ARGV[0]
gemspec = Gem::Specification.load(ARGV[1])
cargo = TomlRB.load_file(ARGV[2])

abort("Gem version does not match tag\n v#{gemspec.version} != #{tag}") if "v#{gemspec.version}" != tag
cargo_version = cargo.dig("package", "version")
abort("Cargo version does not match tag\n v#{cargo_version} != #{tag}") if "v#{cargo_version}" != tag
2 changes: 2 additions & 0 deletions xml2json.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rackup"
# # Cause I want to use rack adapter with puma server
spec.add_development_dependency "puma"
# # For version validation
spec.add_development_dependency "toml-rb"

# For more information and examples about making a new gem, check out our
# guide at: https://bundler.io/guides/creating_gem.html
Expand Down

0 comments on commit 65bce32

Please sign in to comment.