diff --git a/.github/workflows/gempush.yml b/.github/workflows/gempush.yml index ff0bfb3..2ee97c8 100644 --- a/.github/workflows/gempush.yml +++ b/.github/workflows/gempush.yml @@ -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}}" \ No newline at end of file diff --git a/lib/fastlane/plugin/bundletool/actions/bundletool_action.rb b/lib/fastlane/plugin/bundletool/actions/bundletool_action.rb index 25a166f..b57ee40 100644 --- a/lib/fastlane/plugin/bundletool/actions/bundletool_action.rb +++ b/lib/fastlane/plugin/bundletool/actions/bundletool_action.rb @@ -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 diff --git a/spec/bundletool_action_spec.rb b/spec/bundletool_action_spec.rb index 0229272..1383805 100644 --- a/spec/bundletool_action_spec.rb +++ b/spec/bundletool_action_spec.rb @@ -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')