Skip to content

Commit

Permalink
Add conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenyeargin committed Jan 20, 2024
1 parent 8e69a54 commit 03638f6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/gem-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ jobs:
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
OWNER: ${{ github.repository_owner }}

- name: Check if version exists
id: checkversionexists
run: |
rake check_version
echo "VERSION_EXISTS=$?" >> $GITHUB_OUTPUT
- name: Publish to RubyGems
if: steps.checkversionexists.outputs.VERSION_EXISTS == '0'
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
Expand Down
20 changes: 20 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
require 'rubygems'
require 'rspec/core/rake_task'
require 'net/http'
require 'uri'
require 'gtfs'

RSpec::Core::RakeTask.new do |t|
t.pattern = './spec/**/*_spec.rb'
end

task :default => [:spec]

# Task to check if versin exists on rubygems
task :check_version do
version = GTFS::VERSION
# query api
url = "https://rubygems.org/api/v2/rubygems/gtfs/versions/#{version}"

response = Net::HTTP.get_response(URI.parse(url))

if response.code == '200'
puts "Version #{version} exists on rubygems"
exit 1
end

puts "Version #{version} does not exist on rubygems"
exit 0
end

0 comments on commit 03638f6

Please sign in to comment.