Skip to content

Commit 114717a

Browse files
author
Transcript Dock
committed
Declare required owner when authenticating initial RubyGems publication
1 parent fc8147e commit 114717a

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

‎.github/workflows/release.yml‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,24 @@ jobs:
3737
ruby-version: '3.2'
3838
bundler-cache: false
3939
- run: mkdir -p artifacts && gem build transcriptdock.gemspec --output artifacts/transcriptdock-0.1.0.gem
40-
- uses: rubygems/configure-rubygems-credentials@17e51a8c9fcf6d5f709e04cc612fd105f9273170
40+
- name: Authenticate the pending RubyGems publisher
41+
env:
42+
RUBYGEMS_OWNER_ID: '256122'
43+
run: |
44+
python3 - <<'PYTHON'
45+
import json, os, urllib.request
46+
url = os.environ['ACTIONS_ID_TOKEN_REQUEST_URL'] + '&audience=rubygems.org'
47+
request = urllib.request.Request(url, headers={'Authorization': 'Bearer ' + os.environ['ACTIONS_ID_TOKEN_REQUEST_TOKEN']})
48+
with urllib.request.urlopen(request, timeout=30) as response:
49+
jwt = json.load(response)['value']
50+
body = json.dumps({'jwt': jwt, 'owner': os.environ['RUBYGEMS_OWNER_ID']}).encode()
51+
request = urllib.request.Request('https://rubygems.org/api/v1/oidc/trusted_publisher/exchange_token', data=body, headers={'Content-Type': 'application/json', 'Accept': 'application/json'})
52+
with urllib.request.urlopen(request, timeout=30) as response:
53+
key = json.load(response)['rubygems_api_key']
54+
if not isinstance(key, str) or not key or any(c.isspace() for c in key):
55+
raise RuntimeError('RubyGems returned an invalid credential')
56+
print('::add-mask::' + key)
57+
with open(os.environ['GITHUB_ENV'], 'a') as output:
58+
output.write('GEM_HOST_API_KEY=' + key + '\n')
59+
PYTHON
4160
- run: gem push artifacts/transcriptdock-0.1.0.gem

0 commit comments

Comments
 (0)