Repository navigation
60 lines (60 loc) · 2.52 KB
/
Copy pathrelease.yml
File metadata and controls
60 lines (60 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
name: Check and release
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
inputs:
publish:
description: Publish the checked package
type: boolean
default: false
permissions:
contents: read
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
- uses: ruby/setup-ruby@b3aaceaef7e0ee231b499e7b5f49c03fc1d32199
with:
ruby-version: '3.2'
bundler-cache: false
- run: python3 .ci/check.py
- run: mkdir -p artifacts && gem build transcriptdock.gemspec --output artifacts/transcriptdock.gem
publish:
if: github.event_name == 'workflow_dispatch' && inputs.publish && github.ref == 'refs/heads/main'
needs: check
runs-on: ubuntu-latest
environment: rubygems
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
- uses: ruby/setup-ruby@b3aaceaef7e0ee231b499e7b5f49c03fc1d32199
with:
ruby-version: '3.2'
bundler-cache: false
- run: mkdir -p artifacts && gem build transcriptdock.gemspec --output artifacts/transcriptdock.gem
- name: Authenticate the pending RubyGems publisher
env:
RUBYGEMS_OWNER_ID: '256122'
run: |
python3 - <<'PYTHON'
import json, os, urllib.request
url = os.environ['ACTIONS_ID_TOKEN_REQUEST_URL'] + '&audience=rubygems.org'
request = urllib.request.Request(url, headers={'Authorization': 'Bearer ' + os.environ['ACTIONS_ID_TOKEN_REQUEST_TOKEN']})
with urllib.request.urlopen(request, timeout=30) as response:
jwt = json.load(response)['value']
body = json.dumps({'jwt': jwt, 'owner': os.environ['RUBYGEMS_OWNER_ID']}).encode()
request = urllib.request.Request('https://rubygems.org/api/v1/oidc/trusted_publisher/exchange_token', data=body, headers={'Content-Type': 'application/json', 'Accept': 'application/json'})
with urllib.request.urlopen(request, timeout=30) as response:
key = json.load(response)['rubygems_api_key']
if not isinstance(key, str) or not key or any(c.isspace() for c in key):
raise RuntimeError('RubyGems returned an invalid credential')
print('::add-mask::' + key)
with open(os.environ['GITHUB_ENV'], 'a') as output:
output.write('GEM_HOST_API_KEY=' + key + '\n')
PYTHON
- run: gem push artifacts/transcriptdock.gem