Skip to content

Commit

Permalink
updates CI to publish in ruby gems
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinGonzalez committed Aug 12, 2021
1 parent cdc916b commit 2b0b11c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 29 deletions.
58 changes: 34 additions & 24 deletions .github/workflows/gempush.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,54 @@
name: Ruby Gem
name: Test-Build-Publish

on:
pull_request:
branches:
- master
push:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
with:
path: vendor/bundle
key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile') }}
restore-keys: |
${{ runner.os }}-gem-
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
- name: Install dependencies
run: bundle check || bundle install --jobs=4 --retry=3 --path vendor/bundle
- name: Run tests
run: bundle exec rake
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: test-results
path: test-results
build:
name: Build + Publish
name: "Build and Publish Gem"
needs: test
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'no-publish')"

steps:
- uses: actions/checkout@master
- uses: actions/checkout@v2
- name: Set up Ruby 2.6
uses: actions/setup-ruby@v1
with:
version: 2.6.x

- name: Publish to GPR
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:github: Bearer ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
gem build *.gemspec
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
env:
GEM_HOST_API_KEY: ${{secrets.GPR_AUTH_TOKEN}}
OWNER: username
ruby-version: 2.6.x

- name: Publish to RubyGems
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
mkdir -p ~/.gem
touch ~/.gem/credentials
chmod 0600 ~/.gem/credentials
printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}\n" > ~/.gem/credentials
gem build *.gemspec
gem push *.gem
env:
GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
RUBYGEMS_API_KEY: "${{secrets.RUBYGEMS_API_KEY}}"
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def self.download_bundletool(version)
end
end
puts_success('Downloading bundletool')
rescue StandardError => e
rescue OpenURI::HTTPError => e
clean_temp!
puts_error!("Something went wrong when downloading bundletool version #{version}. \nError message\n #{e.message}")
false
Expand Down
9 changes: 5 additions & 4 deletions spec/bundletool_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@
bundletool_version: '0.11.0',
aab_path: aab_path)
end

it 'throws error when downloading bundletool fails' do
aab_path = 'path/example.aab'
allow(File).to receive(:file?).with(aab_path).and_return(true)
bundletool_url = 'https://github.com/google/bundletool/releases/download/0.11.0/bundletool-all-0.11.0.jar'
allow(Kernel).to receive(:open).with(bundletool_url).and_raise(StandardError.new('error'))
bundletool_version = 'wrong-version'

expect(FastlaneCore::UI).to receive(:user_error!).with("Something went wrong when downloading bundletool version 0.11.0. \nError message\n error")
expect(FastlaneCore::UI).to receive(:user_error!).with("Something went wrong when downloading bundletool version #{bundletool_version}. \nError message\n 404 Not Found")

Fastlane::Actions::BundletoolAction.run(verbose: true,
bundletool_version: '0.11.0',
bundletool_version: bundletool_version,
aab_path: aab_path,
apk_output_path: '/resources/example.apk')
end

it 'throws .aab file does not exist UI.user_error! when providing invalid .aab file path' do
invalid_path = 'some_invalid_dir/example.aab'
expect(FastlaneCore::UI).to receive(:user_error!).with('.aab file at some_invalid_dir/example.aab does not exist')
Expand Down

0 comments on commit 2b0b11c

Please sign in to comment.