From 3e081e239e978a335c8c5cc24310812272f5479f Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Wed, 14 Apr 2021 21:44:53 +0100 Subject: [PATCH 01/46] Control type of release and tagging - Add input release: Whether to push release versions - Add input pre-release: Whether to push pre-release versions - Add input tag-release: After pushing a new gem version, git tag with the version string --- CHANGELOG.md | 4 ++++ action.yml | 38 +++++++++++++++++++++++++++++++++++--- parse-gemspec | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 3 deletions(-) create mode 100755 parse-gemspec diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c2bd7a..c04dad2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +- Add input release: Whether to push release versions +- Add input pre-release: Whether to push pre-release versions +- Add input tag-release: After pushing a new gem version, git tag with the version string + ## [1.0.0] - 2021-04-15 - Add basic action that pushes gems to the repository diff --git a/action.yml b/action.yml index 3ff1163..1ef358b 100644 --- a/action.yml +++ b/action.yml @@ -1,11 +1,20 @@ # See: https://docs.github.com/en/actions/creating-actions name: Gem Push author: FreeAgent -description: Push gem packages to a rubygems compatible repo +description: Push gem packages to a rubygems compatible repository inputs: package-glob: - description: "File glob to match the .gem files to push" + description: File glob to match the .gem files to push default: "pkg/*.gem" + release: + description: Whether to push release versions + default: true + pre-release: + description: Whether to push pre-release versions + default: true + tag-release: + description: After pushing a new gem version, git tag with the version string + default: true runs: using: "composite" @@ -15,10 +24,26 @@ runs: env: # Expects GEM_HOST and GEM_HOST_API_KEY to be set GEM_GLOB: ${{ inputs.package-glob }} + ACTION_PATH: ${{ github.action_path }} + INPUT_RELEASE: ${{ inputs.release }} + INPUT_PRE_RELEASE: ${{ inputs.pre-release }} + INPUT_TAG_RELEASE: ${{ inputs.tag-release }} run: | + PATH="$ACTION_PATH:$PATH" + + if parse-gemspec --is-pre-release; then + if [[ $INPUT_PRE_RELEASE != true ]]; then + echo Ignoring pre-release. Set input pre-release: true, to release + exit 0 + fi + elif [[ $INPUT_RELEASE != true ]]; then + echo Ignoring release. Set input release: true, to release + exit 0 + fi + if ! gem push --host "$GEM_HOST" $GEM_GLOB | tee push.out; then gemerr=$? - if grep "has already been pushed" push.out; then + if grep -q "has already been pushed" push.out; then echo Gem Already Pushed exit 0 fi @@ -26,4 +51,11 @@ runs: cat push.out | sed 's/^/::error::/' exit $gemerr fi + + if [[ $INPUT_TAG_RELEASE == true ]]; then + tagname="v$( parse-gemspec --version )" + git tag -a -m "Gem release $tagname" $tagname + git push origin $tagname + fi + exit 0 diff --git a/parse-gemspec b/parse-gemspec new file mode 100755 index 0000000..565f611 --- /dev/null +++ b/parse-gemspec @@ -0,0 +1,46 @@ +#!/usr/bin/env ruby + +require "json" +require 'optparse' + +gemspecs = Dir["*.gemspec"] + +if gemspecs.empty? + warn "No gemspec found" + exit 10 +end + +if gemspecs.count > 1 + warn "More than one gemspec found" + exit 10 +end + +spec = Gem::Specification.load(gemspecs.first) +exit 10 unless spec + +# json_hash = { +# name: spec.name, +# version: spec.version, +# isPreRelease: spec.version.prerelease? +# } +# puts json_hash.to_json + + + +OptionParser.new do |opts| + opts.banner = "Usage: #{File.basename($0)} [options]" + opts.on("-h", "--help", "Prints this help") do + puts opts + exit + end + opts.on("--name", "Output gemspec name") do |v| + puts spec.name + end + opts.on("--version", "Output gemspec gem version") do |v| + puts spec.version + end + opts.on("--is-pre-release", "Exit 0 if pre-release, 1 otherwise") do |v| + exit 0 if spec.version.prerelease? + exit 1 + end +end.parse! From 02cb8ab8be8ab6daa23269641ce159d4127ee70c Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Thu, 15 Apr 2021 11:33:51 +0100 Subject: [PATCH 02/46] Pull out the bash to it's own script Makes testing, debugging, editing and linting easier. --- action.yml | 35 +++-------------------------------- gem-push-action | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 32 deletions(-) create mode 100755 gem-push-action diff --git a/action.yml b/action.yml index 1ef358b..6663ba0 100644 --- a/action.yml +++ b/action.yml @@ -23,39 +23,10 @@ runs: shell: bash env: # Expects GEM_HOST and GEM_HOST_API_KEY to be set - GEM_GLOB: ${{ inputs.package-glob }} - ACTION_PATH: ${{ github.action_path }} + INPUT_PACKAGE_GLOB: ${{ inputs.package-glob }} INPUT_RELEASE: ${{ inputs.release }} INPUT_PRE_RELEASE: ${{ inputs.pre-release }} INPUT_TAG_RELEASE: ${{ inputs.tag-release }} run: | - PATH="$ACTION_PATH:$PATH" - - if parse-gemspec --is-pre-release; then - if [[ $INPUT_PRE_RELEASE != true ]]; then - echo Ignoring pre-release. Set input pre-release: true, to release - exit 0 - fi - elif [[ $INPUT_RELEASE != true ]]; then - echo Ignoring release. Set input release: true, to release - exit 0 - fi - - if ! gem push --host "$GEM_HOST" $GEM_GLOB | tee push.out; then - gemerr=$? - if grep -q "has already been pushed" push.out; then - echo Gem Already Pushed - exit 0 - fi - echo ::error::Gem Push Failed - cat push.out | sed 's/^/::error::/' - exit $gemerr - fi - - if [[ $INPUT_TAG_RELEASE == true ]]; then - tagname="v$( parse-gemspec --version )" - git tag -a -m "Gem release $tagname" $tagname - git push origin $tagname - fi - - exit 0 + PATH="${{ github.action_path }}:$PATH" + gem-push-action diff --git a/gem-push-action b/gem-push-action new file mode 100755 index 0000000..53409bd --- /dev/null +++ b/gem-push-action @@ -0,0 +1,38 @@ +#!/usr/bin/bash +set -e -o pipefail + +if parse-gemspec --is-pre-release; then + if [[ $INPUT_PRE_RELEASE != true ]]; then + echo Ignoring pre-release. Set input pre-release: true, to release + exit 0 + fi +elif [[ $INPUT_RELEASE != true ]]; then + echo Ignoring release. Set input release: true, to release + exit 0 +fi + +# tee the output to get it in the logs but capture as we can't tell why gem +# push failed from the exit code, so need to grep the output. Gem existing is +# ok, other errors not. Avoids playing games setting up auth up differently for +# gem query. +# Note: the glob is intentially unquoted, we want a glob! +if ! gem push --host "$GEM_HOST" $INPUT_PACKAGE_GLOB | tee push.out; then + gemerr=$? + if grep -q "has already been pushed" push.out; then + echo Gem Already Pushed + exit 0 + fi + echo ::error::Gem Push Failed + sed 's/^/::error::/' push.out + exit $gemerr +fi + +if [[ $INPUT_TAG_RELEASE == true ]]; then + tagname="v$( parse-gemspec --version )" + git config user.name "$(git log -1 --pretty=format:%an)" + git config user.email "$(git log -1 --pretty=format:%ae)" + git tag -a -m "Gem release $tagname" "$tagname" + git push origin "$tagname" +fi + +exit 0 From 2474662ff9ea03d8690a2fedeb1513322421ae6c Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Thu, 15 Apr 2021 12:30:28 +0100 Subject: [PATCH 03/46] Add pushed-version output --- CHANGELOG.md | 7 ++++--- action.yml | 5 +++++ gem-push-action | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c04dad2..e7dca5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,10 @@ ## [Unreleased] -- Add input release: Whether to push release versions -- Add input pre-release: Whether to push pre-release versions -- Add input tag-release: After pushing a new gem version, git tag with the version string +- Add: input release: Whether to push release versions +- Add: input pre-release: Whether to push pre-release versions +- Add: input tag-release: After pushing a new gem version, git tag with the version string +- Add: output pushed-version: the version of the gem pushed to the repository ## [1.0.0] - 2021-04-15 diff --git a/action.yml b/action.yml index 6663ba0..974fbe7 100644 --- a/action.yml +++ b/action.yml @@ -15,11 +15,16 @@ inputs: tag-release: description: After pushing a new gem version, git tag with the version string default: true +outputs: + pushed-version: + description: "The version of the gem pushed to the repository" + value: ${{ steps.push-gem.outputs.pushed-version }} runs: using: "composite" steps: - name: Push Gem + id: push-gem shell: bash env: # Expects GEM_HOST and GEM_HOST_API_KEY to be set diff --git a/gem-push-action b/gem-push-action index 53409bd..a590549 100755 --- a/gem-push-action +++ b/gem-push-action @@ -27,6 +27,8 @@ if ! gem push --host "$GEM_HOST" $INPUT_PACKAGE_GLOB | tee push.out; then exit $gemerr fi +echo "::set-output name=pushed-version::$( parse-gemspec --version )" + if [[ $INPUT_TAG_RELEASE == true ]]; then tagname="v$( parse-gemspec --version )" git config user.name "$(git log -1 --pretty=format:%an)" From 41d931fbc7355ae6661f9ec7aa35013e42fa0c22 Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Thu, 15 Apr 2021 12:54:49 +0100 Subject: [PATCH 04/46] Docs for new options --- README.md | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 85af67d..7f1c845 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ If the gem version already exists in the repo the action will no-op and still se ## Usage +### Basic Setup + +Build and push all new version of the gem: + ```yaml steps: - uses: actions/checkout@v2 @@ -36,6 +40,62 @@ If you want to use a different gem host or key: gem_host_api_key: ${{ secrets.EXAMPLE_APYI_KEY }} ``` +### Separate release and pre-release workflow + +You probably don't want to push all versions from any branch. More likely you would want to push release versions from your default branch (e.g. main) and pre-release from PR builds. To help with this the release and pre-release inputs can be used: + +```yaml +name: Gem Build and Release +on: + push: + branches: + - main + pull_request: + +jobs: + test: + name: Gem / Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + - name: Test + run: bundle exec rake + + release: + name: Gem / Release + needs: test + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + + - name: Build Gem + run: bundle exec rake build + + - name: Setup GPR + uses: fac/rubygems-setup-gpr-action@v1 + with: + token: ${{ secrets.github_token }} + + # Release production gem version from default branch + - name: Push Release Gem + if: github.ref == 'refs/heads/main' + uses: fac/rubygems-push-action@devp/v1.1.0 + + # PR branch builds will release pre-release gems + - name: Push Pre-Release Gem + if: github.ref != 'refs/heads/main' + uses: fac/rubygems-push-action@devp/v1.1.0 + with: + release: false + pre-release: true +``` + +Here we run the test on its own job, so that it gets it's own status on the PR, that you can require separately from the release job in your branch protection. +The release job runs if the tests pass, we always package the gem to test that works. For release we use a conditional along with the actions inputs to push release versions for the main branch only and push pre-releases for PR. + ## Inputs ### package-glob @@ -49,9 +109,28 @@ File glob to match the gem file to push. The default `pkg/*.gem` picks up gems b package-glob: build/special.gem ``` +### release + +Whether to push new release versions of the gem. Defaults to true. + +### pre-release + +Whether to push new pre-release versions of the gem. Defaults to true. + +### tag-release + +When true (the default), after pushing a new gem version tag the repo with +the version number prefixed with `v`. e.g. after pushing version `0.1.0`, the +tag will be `v0.1.0`. This is the same behavior as `gem tag`, but internally +implemented to work with older gem versions. + +The tag commit and push will be made as the author of the commit being tagged. + ## Outputs -None. +### pushed-version + +If we pushed a gem to the repository, this will be set to the version pushed. ## Environment Variables From 200d4a5dfac584d8dd794df2331c20e47288ce1c Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Thu, 15 Apr 2021 12:56:10 +0100 Subject: [PATCH 05/46] Version v1.1.0 --- CHANGELOG.md | 2 ++ README.md | 4 ++-- gem-push-action | 2 +- parse-gemspec | 20 +++++++------------- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7dca5e..1a47a1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## [Unreleased] +## [1.1.0] - 2021-04-15 + - Add: input release: Whether to push release versions - Add: input pre-release: Whether to push pre-release versions - Add: input tag-release: After pushing a new gem version, git tag with the version string diff --git a/README.md b/README.md index 7f1c845..ed4b019 100644 --- a/README.md +++ b/README.md @@ -82,12 +82,12 @@ jobs: # Release production gem version from default branch - name: Push Release Gem if: github.ref == 'refs/heads/main' - uses: fac/rubygems-push-action@devp/v1.1.0 + uses: fac/rubygems-push-action@v1 # PR branch builds will release pre-release gems - name: Push Pre-Release Gem if: github.ref != 'refs/heads/main' - uses: fac/rubygems-push-action@devp/v1.1.0 + uses: fac/rubygems-push-action@v1 with: release: false pre-release: true diff --git a/gem-push-action b/gem-push-action index a590549..d186e14 100755 --- a/gem-push-action +++ b/gem-push-action @@ -13,7 +13,7 @@ fi # tee the output to get it in the logs but capture as we can't tell why gem # push failed from the exit code, so need to grep the output. Gem existing is -# ok, other errors not. Avoids playing games setting up auth up differently for +# ok, other errors not. Avoids playing games setting up auth differently for # gem query. # Note: the glob is intentially unquoted, we want a glob! if ! gem push --host "$GEM_HOST" $INPUT_PACKAGE_GLOB | tee push.out; then diff --git a/parse-gemspec b/parse-gemspec index 565f611..7b5eea9 100755 --- a/parse-gemspec +++ b/parse-gemspec @@ -1,6 +1,5 @@ #!/usr/bin/env ruby -require "json" require 'optparse' gemspecs = Dir["*.gemspec"] @@ -18,26 +17,21 @@ end spec = Gem::Specification.load(gemspecs.first) exit 10 unless spec -# json_hash = { -# name: spec.name, -# version: spec.version, -# isPreRelease: spec.version.prerelease? -# } -# puts json_hash.to_json - - +def puts!(msg) + puts msg + exit +end OptionParser.new do |opts| opts.banner = "Usage: #{File.basename($0)} [options]" opts.on("-h", "--help", "Prints this help") do - puts opts - exit + puts! opts end opts.on("--name", "Output gemspec name") do |v| - puts spec.name + puts! spec.name end opts.on("--version", "Output gemspec gem version") do |v| - puts spec.version + puts! spec.version end opts.on("--is-pre-release", "Exit 0 if pre-release, 1 otherwise") do |v| exit 0 if spec.version.prerelease? From 7d07098954f4a43f2d3acd2510863f87d8502c71 Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Thu, 15 Apr 2021 15:25:57 +0100 Subject: [PATCH 06/46] Review: add docs on ruby requirements --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index ed4b019..d6f6570 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,15 @@ If the gem version already exists in the repo the action will no-op and still se ## Usage +The action expects that you have already checked out your gem and setup your ruby environment (bundle installed), such that gem and ruby commands are availiable. The easiest way to do this is using `actions/checkout` and `ruby/setup-ruby` actions with a `.ruby-version` file. See example below. + ### Basic Setup Build and push all new version of the gem: ```yaml steps: + # Setup ruby environment - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 # .ruby-version From 659a9b37d7dbc768536c3fb62db40567b8d0b754 Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Thu, 15 Apr 2021 15:35:06 +0100 Subject: [PATCH 07/46] Review: better messages when skipping push --- gem-push-action | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gem-push-action b/gem-push-action index d186e14..6136108 100755 --- a/gem-push-action +++ b/gem-push-action @@ -3,11 +3,11 @@ set -e -o pipefail if parse-gemspec --is-pre-release; then if [[ $INPUT_PRE_RELEASE != true ]]; then - echo Ignoring pre-release. Set input pre-release: true, to release + echo "Ignoring pre-release. To release, pass pre-release: true as an input" exit 0 fi elif [[ $INPUT_RELEASE != true ]]; then - echo Ignoring release. Set input release: true, to release + echo "Ignoring release. To release, pass release: true as an input" exit 0 fi From 09563f0fc9fc14df85b8bc9bdd742e6a3ddfe6fe Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Thu, 15 Apr 2021 16:16:43 +0100 Subject: [PATCH 08/46] v1.2.0 rename to ruby-gem-push-action The previous naming was confusing and contentious. rubygems- made it look like it was for the actual rubygems site and registry. The intention was to show this is a ruby action dealing with gems. Changing the prefix to `ruby-gem-` to fix that. See: fac/dev-platform#62 --- CHANGELOG.md | 3 +++ README.md | 24 +++++++++++++----------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a47a1a..77d9e9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # CHANGELOG ## [Unreleased] +## [1.2.0] - 2021-04-15 + +- Change: name to ruby-gem-push-action. Old name still works due to GH redirects. ## [1.1.0] - 2021-04-15 diff --git a/README.md b/README.md index d6f6570..9388734 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,13 @@ ## Description -Action to push gems to a gem cutter compatible repository. Probably RubyGems or GitHub Package Repository. It expects the authentication to have already been setup, using the environment variables GEM_HOST and GEM_HOST_API_KEY. See [fac/rubygems-setup-gpr-action](https://github.com/fac/rubygems-setup-gpr-action) for an action to set this up for you to push to GPR. +Action to push gems to a gem cutter compatible repository. Probably RubyGems or GitHub Packages. It expects the authentication to have already been setup, using the environment variables GEM_HOST and GEM_HOST_API_KEY. See [fac/ruby-gem-setup-github-packages-action](https://github.com/fac/ruby-gem-setup-github-packages-action) for an action to set this up for you to push to GitHub. -If the gem version already exists in the repo the action will no-op and still set a success status. This makes it easier to integrate into workflows, safe to re-run (intentionally of accidentally) and wont push duplicate/replacement packages. +If the gem version already exists in the repo the action will no-op and still set a success status. This makes it easier to integrate into workflows, safe to re-run (intentionally or accidentally) and wont push duplicate/replacement packages. ## Usage -The action expects that you have already checked out your gem and setup your ruby environment (bundle installed), such that gem and ruby commands are availiable. The easiest way to do this is using `actions/checkout` and `ruby/setup-ruby` actions with a `.ruby-version` file. See example below. +The action expects that you have already checked out your gem and setup your ruby environment (bundle installed), such that gem and ruby commands are available. The easiest way to do this is using `actions/checkout` and `ruby/setup-ruby` actions with a `.ruby-version` file. See example below. ### Basic Setup @@ -19,28 +19,30 @@ Build and push all new version of the gem: # Setup ruby environment - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 # .ruby-version + with: + bundler-cache: true # bundle install and cache - name: Build Gem shell: bash run: bundle exec rake build - name: Setup GPR - uses: fac/rubygems-setup-gpr-action@v1 + uses: fac/ruby-gem-setup-github-packages-action@v1 with: token: ${{ secrets.github_token }} - name: Push Gem - uses: fac/rubygems-push-action@v1 + uses: fac/ruby-gem-push-action@v1 ``` If you want to use a different gem host or key: ```yaml - name: Push Gem - uses: fac/rubygems-push-action@v1 + uses: fac/ruby-gem-push-action@v1 env: gem_host: http://gems.example.com - gem_host_api_key: ${{ secrets.EXAMPLE_APYI_KEY }} + gem_host_api_key: ${{ secrets.EXAMPLE_API_KEY }} ``` ### Separate release and pre-release workflow @@ -78,19 +80,19 @@ jobs: run: bundle exec rake build - name: Setup GPR - uses: fac/rubygems-setup-gpr-action@v1 + uses: fac/ruby-gem-setup-github-packages-action@v1 with: token: ${{ secrets.github_token }} # Release production gem version from default branch - name: Push Release Gem if: github.ref == 'refs/heads/main' - uses: fac/rubygems-push-action@v1 + uses: fac/ruby-gem-push-action@v1 # PR branch builds will release pre-release gems - name: Push Pre-Release Gem if: github.ref != 'refs/heads/main' - uses: fac/rubygems-push-action@v1 + uses: fac/ruby-gem-push-action@v1 with: release: false pre-release: true @@ -107,7 +109,7 @@ File glob to match the gem file to push. The default `pkg/*.gem` picks up gems b ```yaml - name: Push Gem - uses: fac/rubygems-push-action@v1 + uses: fac/ruby-gem-push-action@v1 with: package-glob: build/special.gem ``` From 72934f9caa56ecf3b6f67b37ae17cd4ba264154b Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Thu, 15 Apr 2021 17:56:50 +0100 Subject: [PATCH 09/46] Clean up gem push output handling Review feedback. Let the normal logging through unhindered but log errors as GH errors. Avoids double logging in some cases. --- CHANGELOG.md | 4 ++++ gem-push-action | 15 ++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77d9e9d..396da47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ ## [Unreleased] ## [1.2.0] - 2021-04-15 +- Fix: clean shell log handling for `gem push` call + +## [1.2.0] - 2021-04-15 + - Change: name to ruby-gem-push-action. Old name still works due to GH redirects. ## [1.1.0] - 2021-04-15 diff --git a/gem-push-action b/gem-push-action index 6136108..cdf7ebd 100755 --- a/gem-push-action +++ b/gem-push-action @@ -11,19 +11,16 @@ elif [[ $INPUT_RELEASE != true ]]; then exit 0 fi -# tee the output to get it in the logs but capture as we can't tell why gem -# push failed from the exit code, so need to grep the output. Gem existing is -# ok, other errors not. Avoids playing games setting up auth differently for -# gem query. +# Capture as we can't tell why gem push failed from the exit code and it logs +# everything to stdout, so need to grep the output. Gem existing is ok, other +# errors not. Avoids playing games setting up auth differently for gem query. # Note: the glob is intentially unquoted, we want a glob! -if ! gem push --host "$GEM_HOST" $INPUT_PACKAGE_GLOB | tee push.out; then +if ! gem push --host "$GEM_HOST" $INPUT_PACKAGE_GLOB >push.out; then gemerr=$? + sed 's/^Error:/::error::/' push.out if grep -q "has already been pushed" push.out; then - echo Gem Already Pushed - exit 0 + exit 0 fi - echo ::error::Gem Push Failed - sed 's/^/::error::/' push.out exit $gemerr fi From 8c659cebf5013b965781d628dd8c4d64a9308ab0 Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Fri, 16 Apr 2021 10:45:32 +0100 Subject: [PATCH 10/46] Version v1.3.0 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 396da47..df24cde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # CHANGELOG ## [Unreleased] -## [1.2.0] - 2021-04-15 +## [1.3.0] - 2021-04-16 - Fix: clean shell log handling for `gem push` call From 2fde64aacfd2acb27459a817bdbba700d6eb746a Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Sat, 17 Apr 2021 21:26:22 +0100 Subject: [PATCH 11/46] Pull the gemhost out of the spec --- gem-push-action | 5 +++++ parse-gemspec | 16 ++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/gem-push-action b/gem-push-action index cdf7ebd..a1ae1e8 100755 --- a/gem-push-action +++ b/gem-push-action @@ -1,6 +1,11 @@ #!/usr/bin/bash set -e -o pipefail +# By default read the gem host from the gemspec, if they dont match the push +# will fail! Allow override if GEM_HOST is already exported. +push_host="$(parse-gemspec --push-host)" +export GEM_HOST="${GEM_HOST:-$push_host}" + if parse-gemspec --is-pre-release; then if [[ $INPUT_PRE_RELEASE != true ]]; then echo "Ignoring pre-release. To release, pass pre-release: true as an input" diff --git a/parse-gemspec b/parse-gemspec index 7b5eea9..04e8183 100755 --- a/parse-gemspec +++ b/parse-gemspec @@ -24,15 +24,15 @@ end OptionParser.new do |opts| opts.banner = "Usage: #{File.basename($0)} [options]" - opts.on("-h", "--help", "Prints this help") do - puts! opts - end - opts.on("--name", "Output gemspec name") do |v| - puts! spec.name - end - opts.on("--version", "Output gemspec gem version") do |v| - puts! spec.version + opts.on("-h", "--help", "Prints this help") do puts! opts end + + opts.on("--name", "Output name") do |v| puts! spec.name end + opts.on("--version", "Output gem version") do |v| puts! spec.version end + opts.on("--metadata", "Output metadata") do |v| puts! spec.metadata end + opts.on("--push-host", "Output metadata.allowed_push_host") do |v| + puts! spec.metadata.dig "allowed_push_host" end + opts.on("--is-pre-release", "Exit 0 if pre-release, 1 otherwise") do |v| exit 0 if spec.version.prerelease? exit 1 From ceea7da4cc5f7c5ad12359ac29fee4706727b2c9 Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Sun, 18 Apr 2021 04:07:49 +0100 Subject: [PATCH 12/46] Add key-name input --- action.yml | 10 +++++++--- gem-push-action | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 974fbe7..2ef02d9 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,9 @@ inputs: tag-release: description: After pushing a new gem version, git tag with the version string default: true + key-name: + description: "Name of credentials key to use from ~/.gem/credentials. Use github for gh packages." + default: "" outputs: pushed-version: description: "The version of the gem pushed to the repository" @@ -29,9 +32,10 @@ runs: env: # Expects GEM_HOST and GEM_HOST_API_KEY to be set INPUT_PACKAGE_GLOB: ${{ inputs.package-glob }} - INPUT_RELEASE: ${{ inputs.release }} - INPUT_PRE_RELEASE: ${{ inputs.pre-release }} - INPUT_TAG_RELEASE: ${{ inputs.tag-release }} + INPUT_RELEASE: ${{ inputs.release }} + INPUT_PRE_RELEASE: ${{ inputs.pre-release }} + INPUT_TAG_RELEASE: ${{ inputs.tag-release }} + INPUT_KEY_NAME: ${{ inputs.key-name }} run: | PATH="${{ github.action_path }}:$PATH" gem-push-action diff --git a/gem-push-action b/gem-push-action index a1ae1e8..fbb6d05 100755 --- a/gem-push-action +++ b/gem-push-action @@ -20,7 +20,7 @@ fi # everything to stdout, so need to grep the output. Gem existing is ok, other # errors not. Avoids playing games setting up auth differently for gem query. # Note: the glob is intentially unquoted, we want a glob! -if ! gem push --host "$GEM_HOST" $INPUT_PACKAGE_GLOB >push.out; then +if ! gem push --key="$INPUT_KEY_NAME" --host "$GEM_HOST" $INPUT_PACKAGE_GLOB >push.out; then gemerr=$? sed 's/^Error:/::error::/' push.out if grep -q "has already been pushed" push.out; then From 4c5df944b8a82623b6caf612718f623625849a52 Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Sun, 18 Apr 2021 04:28:20 +0100 Subject: [PATCH 13/46] Rename input to just key --- action.yml | 8 ++++---- gem-push-action | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 2ef02d9..a30f728 100644 --- a/action.yml +++ b/action.yml @@ -3,6 +3,9 @@ name: Gem Push author: FreeAgent description: Push gem packages to a rubygems compatible repository inputs: + key: + description: "Name of credentials key to use from ~/.gem/credentials. Use github for gh packages." + default: "" package-glob: description: File glob to match the .gem files to push default: "pkg/*.gem" @@ -15,9 +18,6 @@ inputs: tag-release: description: After pushing a new gem version, git tag with the version string default: true - key-name: - description: "Name of credentials key to use from ~/.gem/credentials. Use github for gh packages." - default: "" outputs: pushed-version: description: "The version of the gem pushed to the repository" @@ -35,7 +35,7 @@ runs: INPUT_RELEASE: ${{ inputs.release }} INPUT_PRE_RELEASE: ${{ inputs.pre-release }} INPUT_TAG_RELEASE: ${{ inputs.tag-release }} - INPUT_KEY_NAME: ${{ inputs.key-name }} + INPUT_KEY: ${{ inputs.key }} run: | PATH="${{ github.action_path }}:$PATH" gem-push-action diff --git a/gem-push-action b/gem-push-action index fbb6d05..20a59ee 100755 --- a/gem-push-action +++ b/gem-push-action @@ -20,7 +20,7 @@ fi # everything to stdout, so need to grep the output. Gem existing is ok, other # errors not. Avoids playing games setting up auth differently for gem query. # Note: the glob is intentially unquoted, we want a glob! -if ! gem push --key="$INPUT_KEY_NAME" --host "$GEM_HOST" $INPUT_PACKAGE_GLOB >push.out; then +if ! gem push --key="$INPUT_KEY" --host "$GEM_HOST" $INPUT_PACKAGE_GLOB >push.out; then gemerr=$? sed 's/^Error:/::error::/' push.out if grep -q "has already been pushed" push.out; then From 7edee15f3e08af231ab125e88232ad0a63fb36fd Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Sun, 18 Apr 2021 04:41:11 +0100 Subject: [PATCH 14/46] Remove release option, make pre-release input either or. Only do one type of release, so we only need one boolean instead of 2, which is a little confusing and allows for release anything and release nothing cases. One option simplifies all around. Pass the gem glob via the command call, like proper file arguments ;-) --- action.yml | 11 +++-------- gem-push-action | 15 ++++++--------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/action.yml b/action.yml index a30f728..e7492b1 100644 --- a/action.yml +++ b/action.yml @@ -9,12 +9,9 @@ inputs: package-glob: description: File glob to match the .gem files to push default: "pkg/*.gem" - release: - description: Whether to push release versions - default: true pre-release: - description: Whether to push pre-release versions - default: true + description: Whether to push pre-release versions, instead of release versions (the default). + default: false tag-release: description: After pushing a new gem version, git tag with the version string default: true @@ -31,11 +28,9 @@ runs: shell: bash env: # Expects GEM_HOST and GEM_HOST_API_KEY to be set - INPUT_PACKAGE_GLOB: ${{ inputs.package-glob }} - INPUT_RELEASE: ${{ inputs.release }} INPUT_PRE_RELEASE: ${{ inputs.pre-release }} INPUT_TAG_RELEASE: ${{ inputs.tag-release }} INPUT_KEY: ${{ inputs.key }} run: | PATH="${{ github.action_path }}:$PATH" - gem-push-action + gem-push-action ${{ inputs.package-glob }} diff --git a/gem-push-action b/gem-push-action index 20a59ee..e0f9f11 100755 --- a/gem-push-action +++ b/gem-push-action @@ -1,26 +1,23 @@ #!/usr/bin/bash set -e -o pipefail +GEM_FILE="$1" + # By default read the gem host from the gemspec, if they dont match the push # will fail! Allow override if GEM_HOST is already exported. push_host="$(parse-gemspec --push-host)" -export GEM_HOST="${GEM_HOST:-$push_host}" +GEM_HOST="${GEM_HOST:-$push_host}" -if parse-gemspec --is-pre-release; then - if [[ $INPUT_PRE_RELEASE != true ]]; then +if parse-gemspec --is-pre-release && [[ $INPUT_PRE_RELEASE != true ]]; +then echo "Ignoring pre-release. To release, pass pre-release: true as an input" exit 0 - fi -elif [[ $INPUT_RELEASE != true ]]; then - echo "Ignoring release. To release, pass release: true as an input" - exit 0 fi # Capture as we can't tell why gem push failed from the exit code and it logs # everything to stdout, so need to grep the output. Gem existing is ok, other # errors not. Avoids playing games setting up auth differently for gem query. -# Note: the glob is intentially unquoted, we want a glob! -if ! gem push --key="$INPUT_KEY" --host "$GEM_HOST" $INPUT_PACKAGE_GLOB >push.out; then +if ! gem push --key="$INPUT_KEY" --host "$GEM_HOST" "$GEM_FILE" >push.out; then gemerr=$? sed 's/^Error:/::error::/' push.out if grep -q "has already been pushed" push.out; then From af505bec03193f13331d9a85a719305169008f3b Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Sun, 18 Apr 2021 05:45:47 +0100 Subject: [PATCH 15/46] Pass inputs as command line opts --- action.yml | 11 ++++------- gem-push-action | 44 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/action.yml b/action.yml index e7492b1..24d6ea0 100644 --- a/action.yml +++ b/action.yml @@ -26,11 +26,8 @@ runs: - name: Push Gem id: push-gem shell: bash - env: - # Expects GEM_HOST and GEM_HOST_API_KEY to be set - INPUT_PRE_RELEASE: ${{ inputs.pre-release }} - INPUT_TAG_RELEASE: ${{ inputs.tag-release }} - INPUT_KEY: ${{ inputs.key }} run: | - PATH="${{ github.action_path }}:$PATH" - gem-push-action ${{ inputs.package-glob }} + #PATH="${{ github.action_path }}:$PATH" + args="" + '${{ inputs.tag-release }}' && args="$args -t" + gem-push-action -k "${{inputs.key}}" $args ${{ inputs.package-glob }} diff --git a/gem-push-action b/gem-push-action index e0f9f11..9c2343e 100755 --- a/gem-push-action +++ b/gem-push-action @@ -1,6 +1,42 @@ -#!/usr/bin/bash +#!/usr/bin/env bash set -e -o pipefail +# Get access to ./parse-gemspec and be callable from anywhere +SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &>/dev/null && pwd )" +PATH="$SRCDIR:$PATH" + +KEY="" +PRE_RELEASE=false +TAG_RELEASE=false + +usage() { + echo "Usage: $0 [-k KEY] [-p] GEMFILE" + echo + echo Options: + echo " GEMFILE The pre-built .gem pkg you want to push" + echo " -k KEY Set the gem host credentials key name. Default: '$KEY'" + echo " -p Do a pre-release, ignore otherwise. Default: $PRE_RELEASE" + echo " -t After pushing a new version, git tag the current ref. Default: $TAG_RELEASE" + echo " -h Show this help" + exit 0 +} + +while getopts ":hk:pt" opt; do + case ${opt} in + h ) usage + ;; + k ) KEY=$OPTARG + ;; + p ) PRE_RELEASE=true + ;; + t ) TAG_RELEASE=true + ;; + \? ) usage + ;; + esac +done +shift $((OPTIND -1)) + GEM_FILE="$1" # By default read the gem host from the gemspec, if they dont match the push @@ -8,7 +44,7 @@ GEM_FILE="$1" push_host="$(parse-gemspec --push-host)" GEM_HOST="${GEM_HOST:-$push_host}" -if parse-gemspec --is-pre-release && [[ $INPUT_PRE_RELEASE != true ]]; +if parse-gemspec --is-pre-release && [[ $PRE_RELEASE != true ]]; then echo "Ignoring pre-release. To release, pass pre-release: true as an input" exit 0 @@ -17,7 +53,7 @@ fi # Capture as we can't tell why gem push failed from the exit code and it logs # everything to stdout, so need to grep the output. Gem existing is ok, other # errors not. Avoids playing games setting up auth differently for gem query. -if ! gem push --key="$INPUT_KEY" --host "$GEM_HOST" "$GEM_FILE" >push.out; then +if ! gem push --key="$KEY" --host "$GEM_HOST" "$GEM_FILE" >push.out; then gemerr=$? sed 's/^Error:/::error::/' push.out if grep -q "has already been pushed" push.out; then @@ -28,7 +64,7 @@ fi echo "::set-output name=pushed-version::$( parse-gemspec --version )" -if [[ $INPUT_TAG_RELEASE == true ]]; then +if [[ $TAG_RELEASE == true ]]; then tagname="v$( parse-gemspec --version )" git config user.name "$(git log -1 --pretty=format:%an)" git config user.email "$(git log -1 --pretty=format:%ae)" From 37f190e54b037338ab3d62892a87e614dba1174e Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Sun, 18 Apr 2021 05:53:22 +0100 Subject: [PATCH 16/46] Clean up option/input names --- action.yml | 10 +++++----- gem-push-action | 4 ---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/action.yml b/action.yml index 24d6ea0..f42c058 100644 --- a/action.yml +++ b/action.yml @@ -6,13 +6,13 @@ inputs: key: description: "Name of credentials key to use from ~/.gem/credentials. Use github for gh packages." default: "" - package-glob: + gem-glob: description: File glob to match the .gem files to push default: "pkg/*.gem" pre-release: description: Whether to push pre-release versions, instead of release versions (the default). default: false - tag-release: + tag: description: After pushing a new gem version, git tag with the version string default: true outputs: @@ -27,7 +27,7 @@ runs: id: push-gem shell: bash run: | - #PATH="${{ github.action_path }}:$PATH" + PATH="${{ github.action_path }}:$PATH" args="" - '${{ inputs.tag-release }}' && args="$args -t" - gem-push-action -k "${{inputs.key}}" $args ${{ inputs.package-glob }} + '${{ inputs.tag }}' && args="$args -t" + gem-push-action -k "${{inputs.key}}" $args ${{inputs.gem-glob}} diff --git a/gem-push-action b/gem-push-action index 9c2343e..b04b40c 100755 --- a/gem-push-action +++ b/gem-push-action @@ -1,10 +1,6 @@ #!/usr/bin/env bash set -e -o pipefail -# Get access to ./parse-gemspec and be callable from anywhere -SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &>/dev/null && pwd )" -PATH="$SRCDIR:$PATH" - KEY="" PRE_RELEASE=false TAG_RELEASE=false From b55d8595402f706433f20fc04db91b8e0ab855a3 Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Sun, 18 Apr 2021 12:00:29 +0100 Subject: [PATCH 17/46] Update docs to match v2 --- CHANGELOG.md | 2 ++ README.md | 83 ++++++++++++++++++++-------------------------------- 2 files changed, 34 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df24cde..773a683 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # CHANGELOG +TODO: v2 changes + ## [Unreleased] ## [1.3.0] - 2021-04-16 diff --git a/README.md b/README.md index 9388734..9c48e98 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,11 @@ ## Description -Action to push gems to a gem cutter compatible repository. Probably RubyGems or GitHub Packages. It expects the authentication to have already been setup, using the environment variables GEM_HOST and GEM_HOST_API_KEY. See [fac/ruby-gem-setup-github-packages-action](https://github.com/fac/ruby-gem-setup-github-packages-action) for an action to set this up for you to push to GitHub. +Action to push gems to a gem cutter compatible repository. Basically RubyGems or GitHub Packages. It expects the authentication to have already been setup, `~/.gem/credentials` contains a token for the repo and you know the name of the key. +See [fac/ruby-gem-setup-github-packages-action](https://github.com/fac/ruby-gem-setup-github-packages-action) for an action to set this up for you. It is actually pretty easy if pushing to the same repo. If the gem version already exists in the repo the action will no-op and still set a success status. This makes it easier to integrate into workflows, safe to re-run (intentionally or accidentally) and wont push duplicate/replacement packages. +It will still raise an error visible in the summary, letting you know the version already exists. ## Usage @@ -16,38 +18,29 @@ Build and push all new version of the gem: ```yaml steps: - # Setup ruby environment - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 # .ruby-version with: - bundler-cache: true # bundle install and cache + bundler-cache: true # bundle install + - run: bundle exec rake build - - name: Build Gem - shell: bash - run: bundle exec rake build - - - name: Setup GPR - uses: fac/ruby-gem-setup-github-packages-action@v1 + - uses: fac/ruby-gem-setup-github-packages-action@v2 with: token: ${{ secrets.github_token }} - - name: Push Gem - uses: fac/ruby-gem-push-action@v1 + - uses: fac/ruby-gem-push-action@v2 + with: + key: github ``` -If you want to use a different gem host or key: - -```yaml - - name: Push Gem - uses: fac/ruby-gem-push-action@v1 - env: - gem_host: http://gems.example.com - gem_host_api_key: ${{ secrets.EXAMPLE_API_KEY }} -``` +Note, that the ruby-gem-push-action, will push to the host given in the gemspec. The token needs to match. Trying to push to a different host will fail. ### Separate release and pre-release workflow -You probably don't want to push all versions from any branch. More likely you would want to push release versions from your default branch (e.g. main) and pre-release from PR builds. To help with this the release and pre-release inputs can be used: + +By the default, the action releases, (er!) release versions, that is, non pre-release versions, those are skipped over with a message. Setting the input `pre-release: true`, reverses that, releasing new pre-release versions and skipping over live releases. That way, you can have 2 calls to the action, using the workflow to decide the logic. + +Say you want to push release versions from your default branch (main) and pre-release versions from PR builds: ```yaml name: Gem Build and Release @@ -69,32 +62,32 @@ jobs: release: name: Gem / Release - needs: test + needs: test # Only release IF the tests pass runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 + - run: bundle exec rake build - - name: Build Gem - run: bundle exec rake build - - - name: Setup GPR - uses: fac/ruby-gem-setup-github-packages-action@v1 + # Setup repo auth + - uses: fac/ruby-gem-setup-github-packages-action@v2 with: token: ${{ secrets.github_token }} # Release production gem version from default branch - - name: Push Release Gem + - name: Release Gem if: github.ref == 'refs/heads/main' - uses: fac/ruby-gem-push-action@v1 + uses: fac/ruby-gem-push-action@v2 + with: + key: github # PR branch builds will release pre-release gems - - name: Push Pre-Release Gem + - name: Pre-Release Gem if: github.ref != 'refs/heads/main' - uses: fac/ruby-gem-push-action@v1 + uses: fac/ruby-gem-push-action@v2 with: - release: false + key: github pre-release: true ``` @@ -103,7 +96,7 @@ The release job runs if the tests pass, we always package the gem to test that w ## Inputs -### package-glob +### gem-glob File glob to match the gem file to push. The default `pkg/*.gem` picks up gems built using `bundle exec rake build`. You may need to set this if your your gem builds another way. @@ -111,23 +104,18 @@ File glob to match the gem file to push. The default `pkg/*.gem` picks up gems b - name: Push Gem uses: fac/ruby-gem-push-action@v1 with: - package-glob: build/special.gem + gem-glob: build/special.gem ``` - -### release - -Whether to push new release versions of the gem. Defaults to true. - ### pre-release -Whether to push new pre-release versions of the gem. Defaults to true. +Whether to push new pre-release versions of the gem and ignore releases, instead of the normal, push prod releases but ignore pre-release. -### tag-release +### tag When true (the default), after pushing a new gem version tag the repo with the version number prefixed with `v`. e.g. after pushing version `0.1.0`, the -tag will be `v0.1.0`. This is the same behavior as `gem tag`, but internally -implemented to work with older gem versions. +tag will be `v0.1.0`. This is the same behavior as `gem tag`. (Internally +implemented to work with older gem versions and around bugs that caused tags for failed pushes, which then blocked re-pushing. The tag commit and push will be made as the author of the commit being tagged. @@ -139,14 +127,7 @@ If we pushed a gem to the repository, this will be set to the version pushed. ## Environment Variables -### GEM_HOST_API_KEY - -Read to get the API key string (prefixed token with Bearer), to access the package repo. Used by `gem push`. - -### GEM_HOST - -The host URL for pushing gems to. - +None. ## Authors * FreeAgent From 6230aeb91fa0c19cfa4baf5d73615a281bd2b89b Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Sun, 18 Apr 2021 12:49:47 +0100 Subject: [PATCH 18/46] Add super linter --- .github/workflows/linter.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/linter.yml diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..49c869f --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,26 @@ +name: Lint Code Base +# https://help.github.com/en/articles/workflow-syntax-for-github-actions + +on: + pull_request: + push: + branches: + - main + +jobs: + linter: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + fetch-depth: 0 # Full history to get a proper list of changed files within `super-linter` + + - name: Lint Code Base + uses: github/super-linter@v3 + env: + VALIDATE_ALL_CODEBASE: false + VALIDATE_BASH: true + VALIDATE_YAML: true + DEFAULT_BRANCH: main + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 5a8c475c50b42dd51ff5ab5ce3fb6a3bf3bb859a Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Mon, 26 Apr 2021 11:38:20 +0100 Subject: [PATCH 19/46] Add v2 CHANGELOG --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 773a683..1cd322b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,17 @@ TODO: v2 changes ## [Unreleased] + +## [2.0.0] - 2021-04-26 + +- Change: Don't pass the gem host around as an environment variable, extract from the gemspec. +- Change: Don't pass gem keys around in environment variables anymore. Use the installed creds by key name. +- Add: input `key` to set the key name in gem credentials to use. +- Change: Release/pre-release inputs collapsed into single pre-release input. Push is either release or pre-release version, can't do both (or none!) in the same call anymore. +- Add: Add linter for action code. +- Change: `tag-release` input renamed to just `tag`. +- Change: Use command line args instead of env variables for the internal command. + ## [1.3.0] - 2021-04-16 - Fix: clean shell log handling for `gem push` call From c1126044877f7fb8b44b5ffb5d47adfcb59890a7 Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Mon, 26 Apr 2021 13:07:30 +0100 Subject: [PATCH 20/46] Review --- README.md | 5 ++--- action.yml | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9c48e98..330c102 100644 --- a/README.md +++ b/README.md @@ -33,12 +33,11 @@ Build and push all new version of the gem: key: github ``` -Note, that the ruby-gem-push-action, will push to the host given in the gemspec. The token needs to match. Trying to push to a different host will fail. +Note that the ruby-gem-push-action will push to the host given in the gemspec. The token needs to match. Trying to push to a different host will fail. ### Separate release and pre-release workflow - -By the default, the action releases, (er!) release versions, that is, non pre-release versions, those are skipped over with a message. Setting the input `pre-release: true`, reverses that, releasing new pre-release versions and skipping over live releases. That way, you can have 2 calls to the action, using the workflow to decide the logic. +By default, the action only acts on non-pre-release versions, and prints a message if it thinks the gem has a pre-release version number. If you set the input option `pre-release: true`, then it will only act on pre-release versions, and will skip over regular versions. That way, you can have 2 calls to the action, using the workflow to decide the logic. Say you want to push release versions from your default branch (main) and pre-release versions from PR builds: diff --git a/action.yml b/action.yml index f42c058..1f8eb1b 100644 --- a/action.yml +++ b/action.yml @@ -4,7 +4,7 @@ author: FreeAgent description: Push gem packages to a rubygems compatible repository inputs: key: - description: "Name of credentials key to use from ~/.gem/credentials. Use github for gh packages." + description: "Name of credentials key to use from ~/.gem/credentials." default: "" gem-glob: description: File glob to match the .gem files to push @@ -29,5 +29,5 @@ runs: run: | PATH="${{ github.action_path }}:$PATH" args="" - '${{ inputs.tag }}' && args="$args -t" + [ '${{ inputs.tag }}' == true ] && args="$args -t" gem-push-action -k "${{inputs.key}}" $args ${{inputs.gem-glob}} From 61733538b2c15254c5524b8796d285c4bc575710 Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Mon, 26 Apr 2021 15:04:41 +0100 Subject: [PATCH 21/46] Update docs for new ruby-gem-setup-credentials-action --- CHANGELOG.md | 4 ++++ README.md | 13 +++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cd322b..345b2b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ TODO: v2 changes ## [Unreleased] +## [2.0.1] - 2021-04-26 + +- Update: README to show usage with renamed `ruby-gem-setup-credentials@v2` + ## [2.0.0] - 2021-04-26 - Change: Don't pass the gem host around as an environment variable, extract from the gemspec. diff --git a/README.md b/README.md index 330c102..2407788 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ## Description Action to push gems to a gem cutter compatible repository. Basically RubyGems or GitHub Packages. It expects the authentication to have already been setup, `~/.gem/credentials` contains a token for the repo and you know the name of the key. -See [fac/ruby-gem-setup-github-packages-action](https://github.com/fac/ruby-gem-setup-github-packages-action) for an action to set this up for you. It is actually pretty easy if pushing to the same repo. +See [fac/ruby-gem-credentials-action](https://github.com/fac/ruby-gem-credentials-action) for an action to set this up for you. It is actually pretty easy if pushing to the same repo. If the gem version already exists in the repo the action will no-op and still set a success status. This makes it easier to integrate into workflows, safe to re-run (intentionally or accidentally) and wont push duplicate/replacement packages. It will still raise an error visible in the summary, letting you know the version already exists. @@ -22,9 +22,10 @@ Build and push all new version of the gem: - uses: ruby/setup-ruby@v1 # .ruby-version with: bundler-cache: true # bundle install + - run: bundle exec rake build - - uses: fac/ruby-gem-setup-github-packages-action@v2 + - uses: fac/ruby-gem-setup-credentials-action@v2 with: token: ${{ secrets.github_token }} @@ -67,13 +68,13 @@ jobs: steps: - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 - - run: bundle exec rake build - - # Setup repo auth - - uses: fac/ruby-gem-setup-github-packages-action@v2 + - uses: fac/ruby-gem-setup-credentials-action@v2 with: token: ${{ secrets.github_token }} + - name: Build Gem + run: bundle exec rake build + # Release production gem version from default branch - name: Release Gem if: github.ref == 'refs/heads/main' From 4e7c0d2b24749ac440a72a1c24bf5f838e0b0b70 Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Fri, 30 Apr 2021 11:55:00 +0100 Subject: [PATCH 22/46] Version 2.1.0 - Fix bug with pre-release getting ignored. --- CHANGELOG.md | 4 ++++ action.yml | 1 + 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 345b2b6..634556d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ TODO: v2 changes ## [Unreleased] +## [2.1.0] - 2021-04-30 + +- Fix: Bug with pre-release input getting ignored + ## [2.0.1] - 2021-04-26 - Update: README to show usage with renamed `ruby-gem-setup-credentials@v2` diff --git a/action.yml b/action.yml index 1f8eb1b..4cf807f 100644 --- a/action.yml +++ b/action.yml @@ -29,5 +29,6 @@ runs: run: | PATH="${{ github.action_path }}:$PATH" args="" + [ '${{ inputs.pre-release }}' == true ] && args="$args -p" [ '${{ inputs.tag }}' == true ] && args="$args -t" gem-push-action -k "${{inputs.key}}" $args ${{inputs.gem-glob}} From 32b2d5a7be6b5284d25272e4d033b713fdcb203b Mon Sep 17 00:00:00 2001 From: Mark Pitchless Date: Fri, 30 Apr 2021 12:50:18 +0100 Subject: [PATCH 23/46] Version 2.2.0 Fix bug in pre-release:false --- CHANGELOG.md | 3 +++ gem-push-action | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 634556d..d6a241f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ TODO: v2 changes ## [Unreleased] +## [2.2.0] - 2021-04-30 + +- Fix: Bug with pre-release:false input getting ignored ## [2.1.0] - 2021-04-30 diff --git a/gem-push-action b/gem-push-action index b04b40c..e4bfd17 100755 --- a/gem-push-action +++ b/gem-push-action @@ -40,10 +40,16 @@ GEM_FILE="$1" push_host="$(parse-gemspec --push-host)" GEM_HOST="${GEM_HOST:-$push_host}" -if parse-gemspec --is-pre-release && [[ $PRE_RELEASE != true ]]; -then +if parse-gemspec --is-pre-release; then + if [[ $PRE_RELEASE != true ]]; then echo "Ignoring pre-release. To release, pass pre-release: true as an input" exit 0 + fi +else # normal release + if [[ $PRE_RELEASE == true ]]; then + echo "Ignoring release. To release, pass pre-release: false as an input" + exit 0 + fi fi # Capture as we can't tell why gem push failed from the exit code and it logs From 81f0d569ac1d7b075c4e48f4db451a470af39d8c Mon Sep 17 00:00:00 2001 From: Daniel Holz Date: Wed, 19 May 2021 10:47:13 +0100 Subject: [PATCH 24/46] Explicitly check the push host URL before attempting to push a gem `gem` will immediately stop with no error if it encounters an unexpected response when pushing a gem. To avoid this, I'm adding an explicit pre-flight check that replicates the request `gem` will make, but wuth no authentication, and testing for an 'Authentication required' response. If the gem host URL has the wrong scheme or excess slashes, the gem host usually responds with a redirect. https://github.com/rubygems/rubygems/issues/4458 fixes https://github.com/fac/dev-platform/issues/202 --- gem-push-action | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gem-push-action b/gem-push-action index e4bfd17..32a4039 100755 --- a/gem-push-action +++ b/gem-push-action @@ -40,6 +40,16 @@ GEM_FILE="$1" push_host="$(parse-gemspec --push-host)" GEM_HOST="${GEM_HOST:-$push_host}" +# test GEM_HOST, gem silently fails with no error if the GEM_HOST redirects +# see https://github.com/rubygems/rubygems/issues/4458 +test_response_code=$(curl --silent --output /dev/null --write-out "%{http_code}" --request POST "$GEM_HOST/api/v1/gems") +if [ $test_response_code != 401 ] # expecting an 'authentication required' response +then + echo "::error::Push host looks malformed! Got response of $test_response_code when requesting $GEM_HOST/api/vi/gems" >&2 + echo "::error::Check for HTTPS scheme & no trailing slashes on your allowed push host ($push_host)" >&2 + exit 1 +fi + if parse-gemspec --is-pre-release; then if [[ $PRE_RELEASE != true ]]; then echo "Ignoring pre-release. To release, pass pre-release: true as an input" From 07981992aa615e094d5259293b836f7de3161379 Mon Sep 17 00:00:00 2001 From: Daniel Holz Date: Wed, 19 May 2021 10:52:12 +0100 Subject: [PATCH 25/46] Bump changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6a241f..f0b248f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ TODO: v2 changes ## [Unreleased] + +## [2.3.0] - 2021-05-19 + +- Add: explicit preflight check on the push host, to work around gem failing successfully on malformed push hosts + ## [2.2.0] - 2021-04-30 - Fix: Bug with pre-release:false input getting ignored From 194c5fef158f7664e46b2a4f76d35293eecb48dc Mon Sep 17 00:00:00 2001 From: Daniel Holz Date: Wed, 19 May 2021 11:04:45 +0100 Subject: [PATCH 26/46] Appease the bash linter --- gem-push-action | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gem-push-action b/gem-push-action index 32a4039..fa12b1b 100755 --- a/gem-push-action +++ b/gem-push-action @@ -43,7 +43,7 @@ GEM_HOST="${GEM_HOST:-$push_host}" # test GEM_HOST, gem silently fails with no error if the GEM_HOST redirects # see https://github.com/rubygems/rubygems/issues/4458 test_response_code=$(curl --silent --output /dev/null --write-out "%{http_code}" --request POST "$GEM_HOST/api/v1/gems") -if [ $test_response_code != 401 ] # expecting an 'authentication required' response +if [[ $test_response_code != 401 ]] # expecting an 'authentication required' response then echo "::error::Push host looks malformed! Got response of $test_response_code when requesting $GEM_HOST/api/vi/gems" >&2 echo "::error::Check for HTTPS scheme & no trailing slashes on your allowed push host ($push_host)" >&2 From fd6caf8fc7e7d7d2de2a9caa9261449720c2cb7a Mon Sep 17 00:00:00 2001 From: Daniel Holz Date: Mon, 19 Jul 2021 16:27:17 +0100 Subject: [PATCH 27/46] Add actionlint (run via Reviewdog) For fac/dev-platform#314 --- .github/workflows/reviewdog.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/workflows/reviewdog.yml diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml new file mode 100644 index 0000000..a2d2316 --- /dev/null +++ b/.github/workflows/reviewdog.yml @@ -0,0 +1,13 @@ +name: reviewdog +on: [pull_request] +jobs: + actionlint: + name: runner / actionlint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: actionlint + uses: reviewdog/action-actionlint@v1.2.0 + with: + fail_on_error: true + reporter: github-pr-review From 336a829550b089468ece7707c99c25eb5a72ac4c Mon Sep 17 00:00:00 2001 From: Daniel Holz Date: Tue, 20 Jul 2021 16:16:42 +0100 Subject: [PATCH 28/46] Support ACTIONS_STEP_DEBUG for debug logging --- gem-push-action | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gem-push-action b/gem-push-action index fa12b1b..abf8913 100755 --- a/gem-push-action +++ b/gem-push-action @@ -1,6 +1,11 @@ #!/usr/bin/env bash set -e -o pipefail +if [ "$ACTIONS_STEP_DEBUG" = "true" ] +then + set -x +fi + KEY="" PRE_RELEASE=false TAG_RELEASE=false From 34fd7a2057118c19931b0b48cecc797f71606f70 Mon Sep 17 00:00:00 2001 From: Daniel Holz Date: Tue, 20 Jul 2021 16:24:51 +0100 Subject: [PATCH 29/46] Send `set -x` output as debug messages --- gem-push-action | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/gem-push-action b/gem-push-action index abf8913..5417708 100755 --- a/gem-push-action +++ b/gem-push-action @@ -1,10 +1,9 @@ #!/usr/bin/env bash set -e -o pipefail -if [ "$ACTIONS_STEP_DEBUG" = "true" ] -then - set -x -fi +exec 19> >( sed -e's/^/::debug::/g' ) +BASH_XTRACEFD=19 +set -x KEY="" PRE_RELEASE=false From 26b030bc474a2a60e25d67f51ea6c3aee179f2ba Mon Sep 17 00:00:00 2001 From: Daniel Holz Date: Tue, 20 Jul 2021 17:13:57 +0100 Subject: [PATCH 30/46] Update docs to mention how to debug --- CHANGELOG.md | 4 ++++ README.md | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0b248f..cf0ad65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ TODO: v2 changes ## [Unreleased] +## [2.4.0] - 2021-07-20 + +- Add: support for `ACTIONS_STEP_DEBUG` to see what the push script is doing + ## [2.3.0] - 2021-05-19 - Add: explicit preflight check on the push host, to work around gem failing successfully on malformed push hosts diff --git a/README.md b/README.md index 2407788..c98a0b1 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,10 @@ jobs: Here we run the test on its own job, so that it gets it's own status on the PR, that you can require separately from the release job in your branch protection. The release job runs if the tests pass, we always package the gem to test that works. For release we use a conditional along with the actions inputs to push release versions for the main branch only and push pre-releases for PR. +### Debugging + +This action supports [debug logging](https://docs.github.com/en/actions/managing-workflow-runs/enabling-debug-logging#enabling-step-debug-logging). Enable it by setting the `ACTIONS_STEP_DEBUG` secret to `true` on your repository. + ## Inputs ### gem-glob From d0d2c8b1a483736762e36346318daedecf1c02c9 Mon Sep 17 00:00:00 2001 From: Daniel Holz Date: Tue, 20 Jul 2021 17:51:16 +0100 Subject: [PATCH 31/46] Detect when allowed_push_host or GEM_HOST is not set --- CHANGELOG.md | 4 ++++ gem-push-action | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf0ad65..b5a7ead 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ TODO: v2 changes ## [Unreleased] +## [2.4.1] - 2021-07-20 + +- Fix: detect when allowed_push_host or GEM_HOST is not set + ## [2.4.0] - 2021-07-20 - Add: support for `ACTIONS_STEP_DEBUG` to see what the push script is doing diff --git a/gem-push-action b/gem-push-action index 5417708..69bbf4c 100755 --- a/gem-push-action +++ b/gem-push-action @@ -44,6 +44,12 @@ GEM_FILE="$1" push_host="$(parse-gemspec --push-host)" GEM_HOST="${GEM_HOST:-$push_host}" +if [ -z "$GEM_HOST" ] +then + echo '::error::Push host is missing! Set `spec.metadata["allowed_push_host"]` in your gemspec' + exit 1 +fi + # test GEM_HOST, gem silently fails with no error if the GEM_HOST redirects # see https://github.com/rubygems/rubygems/issues/4458 test_response_code=$(curl --silent --output /dev/null --write-out "%{http_code}" --request POST "$GEM_HOST/api/v1/gems") From 9f71947426da080cb35e9271b985e70fdd7648b5 Mon Sep 17 00:00:00 2001 From: Daniel Holz Date: Thu, 22 Jul 2021 10:19:43 +0100 Subject: [PATCH 32/46] Run shellcheck with Reviewdog So errors appear on the PR (so I don't waste time looking at passive-agressive ASCII opossums in the workflow run logs) --- .github/workflows/reviewdog.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index a2d2316..95e82dc 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -11,3 +11,13 @@ jobs: with: fail_on_error: true reporter: github-pr-review + shellcheck: + name: runner / shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: shellcheck + uses: reviewdog/action-shellcheck@v1 + with: + fail_on_error: true + reporter: github-pr-review From 54b02ae771f33e4459662f2e26a2824b23d550a2 Mon Sep 17 00:00:00 2001 From: Daniel Holz Date: Thu, 22 Jul 2021 10:28:53 +0100 Subject: [PATCH 33/46] Add file extension to the bash script So actionlint-shellcheck can find it --- action.yml | 2 +- gem-push-action => gem-push-action.sh | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename gem-push-action => gem-push-action.sh (100%) diff --git a/action.yml b/action.yml index 4cf807f..4dcb457 100644 --- a/action.yml +++ b/action.yml @@ -31,4 +31,4 @@ runs: args="" [ '${{ inputs.pre-release }}' == true ] && args="$args -p" [ '${{ inputs.tag }}' == true ] && args="$args -t" - gem-push-action -k "${{inputs.key}}" $args ${{inputs.gem-glob}} + gem-push-action.sh -k "${{inputs.key}}" $args ${{inputs.gem-glob}} diff --git a/gem-push-action b/gem-push-action.sh similarity index 100% rename from gem-push-action rename to gem-push-action.sh From b3c0c459ba67b7ca3601d01f30a4c06baba47527 Mon Sep 17 00:00:00 2001 From: Daniel Holz Date: Thu, 22 Jul 2021 11:29:57 +0100 Subject: [PATCH 34/46] Work around shellcheck's dislike of backticks https://github.com/koalaman/shellcheck/issues/2277 --- gem-push-action.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gem-push-action.sh b/gem-push-action.sh index 69bbf4c..5dc7458 100755 --- a/gem-push-action.sh +++ b/gem-push-action.sh @@ -46,7 +46,7 @@ GEM_HOST="${GEM_HOST:-$push_host}" if [ -z "$GEM_HOST" ] then - echo '::error::Push host is missing! Set `spec.metadata["allowed_push_host"]` in your gemspec' + echo "::error::Push host is missing! Set \`spec.metadata['allowed_push_host']\` in your gemspec" exit 1 fi From 2cae2dd3a2fa7a50cdf793ad3d85f763409ced1f Mon Sep 17 00:00:00 2001 From: Peter Singh Date: Wed, 22 Sep 2021 14:54:34 +0100 Subject: [PATCH 35/46] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c98a0b1..0e6fad8 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ## Description Action to push gems to a gem cutter compatible repository. Basically RubyGems or GitHub Packages. It expects the authentication to have already been setup, `~/.gem/credentials` contains a token for the repo and you know the name of the key. -See [fac/ruby-gem-credentials-action](https://github.com/fac/ruby-gem-credentials-action) for an action to set this up for you. It is actually pretty easy if pushing to the same repo. +See [fac/ruby-gem-credentials-action](https://github.com/fac/ruby-gem-setup-credentials-action) for an action to set this up for you. It is actually pretty easy if pushing to the same repo. If the gem version already exists in the repo the action will no-op and still set a success status. This makes it easier to integrate into workflows, safe to re-run (intentionally or accidentally) and wont push duplicate/replacement packages. It will still raise an error visible in the summary, letting you know the version already exists. From fb3610f73684f5faac99ebb63e62c96db43f2e82 Mon Sep 17 00:00:00 2001 From: Peter Singh Date: Thu, 28 Apr 2022 12:33:55 +0100 Subject: [PATCH 36/46] Update action.yml --- action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/action.yml b/action.yml index 4dcb457..10acfbb 100644 --- a/action.yml +++ b/action.yml @@ -1,6 +1,8 @@ # See: https://docs.github.com/en/actions/creating-actions name: Gem Push author: FreeAgent +icon: arrow-up-circle +color: red description: Push gem packages to a rubygems compatible repository inputs: key: From 61ff978094a4054f006bef6ec087734462692efc Mon Sep 17 00:00:00 2001 From: Peter Singh Date: Thu, 28 Apr 2022 12:36:00 +0100 Subject: [PATCH 37/46] Update action.yml --- action.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 10acfbb..42e13a0 100644 --- a/action.yml +++ b/action.yml @@ -1,8 +1,9 @@ # See: https://docs.github.com/en/actions/creating-actions name: Gem Push author: FreeAgent -icon: arrow-up-circle -color: red +branding: + icon: 'globe' + color: 'red' description: Push gem packages to a rubygems compatible repository inputs: key: From 1a5013c6be8e98db0ffdb0c1f95d23ad1b9016ba Mon Sep 17 00:00:00 2001 From: Peter Singh Date: Thu, 28 Apr 2022 14:13:43 +0100 Subject: [PATCH 38/46] Update README.md --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 0e6fad8..02be4c9 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,18 @@ If we pushed a gem to the repository, this will be set to the version pushed. ## Environment Variables None. + +## Troubleshooting + +If when tagging the action fails with `shallow update not allowed` try setting `fetch-depth` to 0, i.e. dont' do a shallow clone. + +```yml +- uses: actions/checkout@v2 + with: + fetch-depth: 0 +``` + + ## Authors * FreeAgent From 1fb85b2c972a09501305e4763c4ac7d0ffe0260a Mon Sep 17 00:00:00 2001 From: Duncan Smith Date: Mon, 17 Oct 2022 16:42:38 +0100 Subject: [PATCH 39/46] Switch to the new method of setting outputs --- gem-push-action.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gem-push-action.sh b/gem-push-action.sh index 5dc7458..740ce83 100755 --- a/gem-push-action.sh +++ b/gem-push-action.sh @@ -84,7 +84,7 @@ if ! gem push --key="$KEY" --host "$GEM_HOST" "$GEM_FILE" >push.out; then exit $gemerr fi -echo "::set-output name=pushed-version::$( parse-gemspec --version )" +echo "pushed-version=$(parse-gemspec --version)" >> "$GITHUB_OUTPUT" if [[ $TAG_RELEASE == true ]]; then tagname="v$( parse-gemspec --version )" From 6abab1932b69d701386f020da2fdb77b43674084 Mon Sep 17 00:00:00 2001 From: Duncan Smith Date: Mon, 17 Oct 2022 16:58:21 +0100 Subject: [PATCH 40/46] update superlinter --- .github/workflows/linter.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 49c869f..6359732 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -11,13 +11,13 @@ jobs: linter: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: ref: ${{ github.head_ref }} fetch-depth: 0 # Full history to get a proper list of changed files within `super-linter` - name: Lint Code Base - uses: github/super-linter@v3 + uses: github/super-linter@v4 env: VALIDATE_ALL_CODEBASE: false VALIDATE_BASH: true From e0e12e656d45f7c915096b1990d24e3c3aac17c2 Mon Sep 17 00:00:00 2001 From: Duncan Smith Date: Mon, 17 Oct 2022 17:10:49 +0100 Subject: [PATCH 41/46] bump actionlinter --- .github/workflows/reviewdog.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index 95e82dc..dc2d987 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -5,9 +5,11 @@ jobs: name: runner / actionlint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: actionlint - uses: reviewdog/action-actionlint@v1.2.0 + uses: reviewdog/action-actionlint@v1.33.0 with: fail_on_error: true reporter: github-pr-review @@ -15,7 +17,7 @@ jobs: name: runner / shellcheck runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: shellcheck uses: reviewdog/action-shellcheck@v1 with: From 02fee178125d22dc145332a58a36e829434ebb29 Mon Sep 17 00:00:00 2001 From: Duncan Smith Date: Tue, 18 Oct 2022 10:07:24 +0100 Subject: [PATCH 42/46] prepare for v2.5.0 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5a7ead..fe0a4c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ TODO: v2 changes ## [Unreleased] +## [2.5.0] - 2022-10-18 + +- Update: Switch to the new method of setting outputs (fac/ruby-gem-push-action/pull/16) +- Update: Updated Linters to latest versions + ## [2.4.1] - 2021-07-20 - Fix: detect when allowed_push_host or GEM_HOST is not set From d63feecfb396bdda2e844680ac74203940dc6f55 Mon Sep 17 00:00:00 2001 From: Dale Morgan Date: Tue, 21 Sep 2021 10:50:49 +0100 Subject: [PATCH 43/46] Adding working-directory support to the action --- README.md | 11 +++++++++++ action.yml | 5 +++++ parse-gemspec | 4 ++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 02be4c9..98018a3 100644 --- a/README.md +++ b/README.md @@ -100,9 +100,20 @@ This action supports [debug logging](https://docs.github.com/en/actions/managing ## Inputs +### working-directory +Sets the working directory before all other steps occur. This is useful for cases where files like `.ruby-version` and `Gemfile` aren't located in the root directory. For example in a monorepo where the Ruby project is located in its own subfolder. + +```yaml + name: Push Gem + uses: fac/ruby-gem-push-action@v1 + with: + working-directory: './ruby_project/' +``` + ### gem-glob File glob to match the gem file to push. The default `pkg/*.gem` picks up gems built using `bundle exec rake build`. You may need to set this if your your gem builds another way. +_Note_: `working-directory` is set before this step, therefore if both inputs are provided, this path will be relative to the `working-directory`. ```yaml - name: Push Gem diff --git a/action.yml b/action.yml index 42e13a0..d6116a3 100644 --- a/action.yml +++ b/action.yml @@ -18,6 +18,10 @@ inputs: tag: description: After pushing a new gem version, git tag with the version string default: true + working-directory: + description: "The working directory of the ruby project. Useful for cases where files like .ruby-version and Gemfile aren't located in the root directory." + required: false + default: "." outputs: pushed-version: description: "The version of the gem pushed to the repository" @@ -34,4 +38,5 @@ runs: args="" [ '${{ inputs.pre-release }}' == true ] && args="$args -p" [ '${{ inputs.tag }}' == true ] && args="$args -t" + [ ! -z ${{ inputs.working-directory }} ] && cd ${{ inputs.working-directory }} gem-push-action.sh -k "${{inputs.key}}" $args ${{inputs.gem-glob}} diff --git a/parse-gemspec b/parse-gemspec index 04e8183..29878c1 100755 --- a/parse-gemspec +++ b/parse-gemspec @@ -5,12 +5,12 @@ require 'optparse' gemspecs = Dir["*.gemspec"] if gemspecs.empty? - warn "No gemspec found" + warn "No gemspec found in #{Dir.pwd}" exit 10 end if gemspecs.count > 1 - warn "More than one gemspec found" + warn "More than one gemspec found in #{Dir.pwd}" exit 10 end From be4308eb3b8e750c685c5827b70400c8006ead96 Mon Sep 17 00:00:00 2001 From: Dale Morgan Date: Mon, 13 Mar 2023 16:33:38 +0000 Subject: [PATCH 44/46] Update README.md Bumping README to point to `v2` --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 98018a3..ae28c81 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ Sets the working directory before all other steps occur. This is useful for case ```yaml name: Push Gem - uses: fac/ruby-gem-push-action@v1 + uses: fac/ruby-gem-push-action@v2 with: working-directory: './ruby_project/' ``` @@ -117,7 +117,7 @@ _Note_: `working-directory` is set before this step, therefore if both inputs ar ```yaml - name: Push Gem - uses: fac/ruby-gem-push-action@v1 + uses: fac/ruby-gem-push-action@v2 with: gem-glob: build/special.gem ``` From dd683097c42aa867249874e38f33e4c6d30685f9 Mon Sep 17 00:00:00 2001 From: Dale Morgan Date: Thu, 22 Jun 2023 17:27:58 +0100 Subject: [PATCH 45/46] Use org-wide reusable workflow for actionlint # What Previously we added `actionlint` workflows to lots of repos: - https://github.com/fac/dev-platform/issues/314 They trigger on every push to a PR branch, so most of the time this is unnecessary, as workflows are rarely updated. Really we only need to trigger `actionlint` when workflows are changed. We're now looking to use org-wide reusable workflows that can be updated in one central place. # Note! The org-wide shared workflow is for private repos only. We're using `fac/hermod` as the public mirror for the private workflow since only a few repos are public and require this workflow. In future we might look to create a `shared-workflows-public` repo if necessary. Dev-P ticket - https://github.com/fac/dev-platform/issues/1002 --- .github/workflows/reviewdog.yml | 45 ++++++++++++++++---------------- .github/workflows/shellcheck.yml | 13 +++++++++ 2 files changed, 35 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/shellcheck.yml diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index dc2d987..2b71434 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -1,25 +1,24 @@ -name: reviewdog -on: [pull_request] +name: Lint workflow files + +on: + push: + paths: + - '.github/workflows/*.yml' + - '.github/workflows/*.yaml' + pull_request: + types: + - opened + - reopened + - synchronize + paths: + - '.github/workflows/*.yml' + - '.github/workflows/*.yaml' + +permissions: + pull-requests: write + contents: read + jobs: actionlint: - name: runner / actionlint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: actionlint - uses: reviewdog/action-actionlint@v1.33.0 - with: - fail_on_error: true - reporter: github-pr-review - shellcheck: - name: runner / shellcheck - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: shellcheck - uses: reviewdog/action-shellcheck@v1 - with: - fail_on_error: true - reporter: github-pr-review + uses: fac/hermod/.github/workflows/actionlint.yml@master + secrets: inherit diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml new file mode 100644 index 0000000..010baa0 --- /dev/null +++ b/.github/workflows/shellcheck.yml @@ -0,0 +1,13 @@ +name: Shellcheck +on: [pull_request] +jobs: + shellcheck: + name: runner / shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: shellcheck + uses: reviewdog/action-shellcheck@v1 + with: + fail_on_error: true + reporter: github-pr-review From 0713745a3470bd8b002086eb335defd930ff7d18 Mon Sep 17 00:00:00 2001 From: Duncan Smith Date: Tue, 23 Dec 2025 11:10:28 +0000 Subject: [PATCH 46/46] Pin GitHub Actions to specific SHAs --- .github/dependabot.yml | 11 +++++++++++ .github/workflows/check-pinned-actions.yml | 11 +++++++++++ .github/workflows/linter.yml | 4 ++-- .github/workflows/shellcheck.yml | 4 ++-- .pinact.yaml | 5 +++++ 5 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/check-pinned-actions.yml create mode 100644 .pinact.yaml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..c294609 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +--- +version: 2 +updates: +- package-ecosystem: github-actions + directory: "/" + schedule: + interval: daily + rebase-strategy: disabled + open-pull-requests-limit: 10 + cooldown: + default-days: 7 diff --git a/.github/workflows/check-pinned-actions.yml b/.github/workflows/check-pinned-actions.yml new file mode 100644 index 0000000..5a35d27 --- /dev/null +++ b/.github/workflows/check-pinned-actions.yml @@ -0,0 +1,11 @@ +name: Check actions have their versions pinned + +on: + push: + paths: + - '.github/workflows/*.yml' + - '.github/workflows/*.yaml' + +jobs: + pinact: + uses: fac/shared-workflows/.github/workflows/check_pinned_actions.yml@main diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 6359732..d50bda6 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -11,13 +11,13 @@ jobs: linter: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 with: ref: ${{ github.head_ref }} fetch-depth: 0 # Full history to get a proper list of changed files within `super-linter` - name: Lint Code Base - uses: github/super-linter@v4 + uses: github/super-linter@985ef206aaca4d560cb9ee2af2b42ba44adc1d55 # v4.10.0 env: VALIDATE_ALL_CODEBASE: false VALIDATE_BASH: true diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml index 010baa0..7ec66ad 100644 --- a/.github/workflows/shellcheck.yml +++ b/.github/workflows/shellcheck.yml @@ -5,9 +5,9 @@ jobs: name: runner / shellcheck runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 - name: shellcheck - uses: reviewdog/action-shellcheck@v1 + uses: reviewdog/action-shellcheck@4c07458293ac342d477251099501a718ae5ef86e # v1.32.0 with: fail_on_error: true reporter: github-pr-review diff --git a/.pinact.yaml b/.pinact.yaml new file mode 100644 index 0000000..b5b2a7f --- /dev/null +++ b/.pinact.yaml @@ -0,0 +1,5 @@ +--- +version: 3 +ignore_actions: +- name: fac/.* + ref: "^(main|master)$"