Repository navigation
86 lines (82 loc) · 2.84 KB
/
Copy pathplugin-push.yml
File metadata and controls
86 lines (82 loc) · 2.84 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: Push plugin gem to RubyGems
# A plugin's release tag (duel-redis-v0.1.0, say, which `rake release` in
# plugins/redis makes) pushes that plugin's gem. Duel's own tags (v0.1.0)
# are push.yml's.
on:
push:
tags:
- "duel-*-v*"
permissions:
contents: read
jobs:
# Which plugin, and which version, the tag is for.
plan:
if: github.repository == 'sferik/duel-ruby'
runs-on: ubuntu-latest
outputs:
gem: ${{ steps.plan.outputs.gem }}
version: ${{ steps.plan.outputs.version }}
directory: ${{ steps.plan.outputs.directory }}
steps:
- uses: actions/checkout@v7
- name: Find the plugin
id: plan
run: |
gem="${GITHUB_REF_NAME%-v*}"
version="${GITHUB_REF_NAME##*-v}"
directory="plugins/${gem#duel-}"
if [ ! -f "$directory/$gem.gemspec" ]; then
echo "::error::No plugin $gem ($directory/$gem.gemspec) for the tag $GITHUB_REF_NAME"
exit 1
fi
{
echo "gem=$gem"
echo "version=$version"
echo "directory=$directory"
} >> "$GITHUB_OUTPUT"
push:
needs: plan
runs-on: ubuntu-latest
environment:
name: rubygems.org
url: https://rubygems.org/gems/${{ needs.plan.outputs.gem }}
permissions:
contents: write
id-token: write
defaults:
run:
working-directory: ${{ needs.plan.outputs.directory }}
env:
GEM: ${{ needs.plan.outputs.gem }}-${{ needs.plan.outputs.version }}.gem
steps:
- uses: actions/checkout@v7
# Ruby 3.4, as push.yml: Sigstore's signing fails on Ruby 4.0.
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.4'
# Trusted publishing: RubyGems.org trusts this workflow, no API key.
- uses: rubygems/configure-rubygems-credentials@v2.1.0
- name: Update RubyGems
run: gem update --system
# The tag must be the version the gem builds as (duel-redis-v0.1.0:
# duel-redis 0.1.0).
- name: Build the gem
run: |
gem build "${{ needs.plan.outputs.gem }}.gemspec"
test -f "$GEM"
- name: Sign the gem with Sigstore
run: gem exec sigstore-cli sign "$GEM" --bundle "$GEM.sigstore.json"
- name: Push the gem
run: |
gem push "$GEM" --attestation "$GEM.sigstore.json" || {
echo "gem push failed: checking whether it's published already"
gem exec rubygems-await "$GEM" && echo "Already published, continuing" || exit 1
}
- name: Wait for the release
run: gem exec rubygems-await "$GEM"
- name: Create the GitHub release
run: |
gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1 || \
gh release create "$GITHUB_REF_NAME" --verify-tag --generate-notes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}