Skip to content

Commit

Permalink
Merge pull request #13 from actionshub/switch-to-token
Browse files Browse the repository at this point in the history
feat: Use token input variable
  • Loading branch information
damacus authored Nov 21, 2023
2 parents c5ca1ec + 5c152f5 commit c490c83
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This Action has been heavily influenced by [Jstastny's Publish-Gem-to-Github Act

## Usage

See [RubyGems API Key scopes][key] on how to obtain an api key
See [RubyGems API Key scopes][key] on how to obtain an API key

```yaml
jobs:
Expand All @@ -18,7 +18,7 @@ jobs:
- name: Build and publish to RubyGems
uses: actionshub/publish-gem-to-rubygems@main
with:
api_key: ${{ secrets.RUBY_GEMS_API_KEY }}
token: ${{ secrets.RUBY_GEMS_API_KEY }}
```
[key]: https://guides.rubygems.org/api-key-scopes/
18 changes: 9 additions & 9 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
name: 'publish-gem-to-rubygems'
author: 'Dan Webb'
description: 'Run publish Gems to Rubygems'
name: "publish-gem-to-rubygems"
author: "Dan Webb"
description: "Run publish Gems to Rubygems"
runs:
using: 'docker'
image: docker://ghcr.io/actionshub/publish-gem-to-rubygems:v1.0.3
using: "docker"
image: docker://ghcr.io/actionshub/publish-gem-to-rubygems:v2.0.0
inputs:
api_key:
description: "A RubyGems API Token"
token:
description: "RubyGems API Key"
branding:
icon: 'edit-3'
color: 'red'
icon: "edit-3"
color: "red"
37 changes: 25 additions & 12 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
#!/bin/bash

RUBYGEMS_API_KEY=${1}
cd "${GITHUB_WORKSPACE}" || exit 1
git config --global --add safe.directory "${GITHUB_WORKSPACE}"

[ -z "${RUBYGEMS_API_KEY}" ] && { echo "Missing input.rubygems_api_key!"; exit 2; }
TOKEN="${1}"
[ -z "${TOKEN}" ] && { echo "Missing input.token!"; exit 2; }

echo "Setting up access to RubyGems"
mkdir -p ~/.gem
cat << EOF > ~/.gem/credentials
---
:rubygems_api_key: ${RUBYGEMS_API_KEY}
EOF
function setup_credentials_file() {
echo "Setting up access to RubyGems"
mkdir -p ~/.gem
touch ~/.gem/credentials
chmod 600 ~/.gem/credentials
}

echo "Building the gem"
gem build
echo "Pushing the built gem to RubyGems.org"
find . -name '*.gem' -maxdepth 1 -exec gem push {} \;
function auth_rubygems() {
echo "Logging in to RubyGems"
echo ":rubygems_api_key: ${1}" > ~/.gem/credentials
}

function build() {
echo "Building gem"
find . -name '*.gemspec' -maxdepth 1 -exec gem build {} \;
echo "Pushing gem to rubygems.org"
find . -name '*.gem' -maxdepth 1 -exec gem push --key "${1}" {} \;
}

setup_credentials_file
auth_rubygems "${TOKEN}"
build_and_push "rubygems"

0 comments on commit c490c83

Please sign in to comment.