diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..45bdedd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM ruby:2.6.0 + +ENV LC_ALL C.UTF-8 +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US.UTF-8 + +ADD entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..675184c --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# GitHub Action - Publish Gem to Rubygems + +This is a GitHub Action written to streamline the Ruby gem publication process. The action sets the Gem Credentials from `GITHUB_TOKEN` and `RUBYGEMS_API_KEY`secrets, and then runs `rake release` in your project root. You can override this command by setting `RELEASE_COMMAND` environment variable to the script that creates and publishes (this is usually only the case when a repository hosts multiple gems together). + +# Secrets Needed + +`GITHUB_TOKEN` - Bundler needs this to create tags on your repo for the release +`RUBYGEMS_API_KEY` - The Rubygems API Key for an Owner of the Gem you wish to publish. You can find your API Key by looking in `~/.gem/credentials` or using the [Rubygems API](https://guides.rubygems.org/rubygems-org-api/#misc-methods) + +# Env Options + +`RELEASE_COMMAND` - By default, this will invoke `rake release` to build and publish the gem to Rubygems. Set this environment variable if you have a custom release command to be invoked + +# Example + +```hcl +workflow "Publish Gem" { + on = "release" + resolves = ["Release Gem"] +} + +action "Install Dependencies" { + uses = "docker://ruby:2.6.0" + args = "bundle install" +} + +action "Release Gem" { + uses = "cadwallion/publish-rubygems-action@master" + secrets = ["GITHUB_TOKEN", "RUBYGEMS_API_KEY"] + env = { + "RELEASE_COMMAND" = "rake dotenv:release" + } + needs = ["Install Dependencies"] +} +``` diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..f53a4db --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +echo "Setting up gem credentials..." +set +x +mkdir -p ~/.gem +cat << EOF > ~/.gem/credentials +--- +:github: Bearer ${GITHUB_TOKEN} +:rubygems_api_key: ${RUBYGEMS_API_KEY} +EOF +set -x + +echo "Running gem release task..." +release_command="${RELEASE_COMMAND:-rake release}" +exec $release_command