-
Notifications
You must be signed in to change notification settings - Fork 38
83 lines (67 loc) · 2.05 KB
/
publish.yaml
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: Publish
on:
push:
branches:
- main
workflow_dispatch:
concurrency: rubygems
jobs:
pre:
name: Pre-flight checks
runs-on: ubuntu-latest
outputs:
go: ${{ steps.gem_version.outputs.new_version }}
steps:
- uses: actions/checkout@v4
with:
show-progress: false
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3'
- name: Check if new version to release
id: gem_version
run: |
gem_version=$(ruby -r rubygems -e "puts Gem::Specification::load('govuk_tech_docs.gemspec').version")
echo "gem_version=$gem_version" >> "$GITHUB_OUTPUT"
if git fetch origin "refs/tags/v$gem_version" >/dev/null 2>&1
then
echo "Tag 'v$gem_version' already exists"
echo "new_version=false" >> "$GITHUB_OUTPUT"
else
echo "new_version=true" >> "$GITHUB_OUTPUT"
fi
deploy:
name: Publish Ruby Gem
environment: rubygems
permissions:
contents: write # needed to be able to tag the release
runs-on: ubuntu-latest
needs: pre
if: needs.pre.outputs.go == 'true'
steps:
- uses: actions/checkout@v4
with:
show-progress: false
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3'
bundler-cache: true
- name: Publish
env:
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
run: |
mkdir -p ~/.gem
cat << EOF > ~/.gem/credentials
---
:rubygems_api_key: ${RUBYGEMS_API_KEY}
EOF
chmod 0600 ~/.gem/credentials
# tag will be associated with github-actions bot user, see
# https://github.community/t/github-actions-bot-email-address/17204
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
bundle exec rake release