-
Notifications
You must be signed in to change notification settings - Fork 25
55 lines (52 loc) · 1.96 KB
/
publish-rubygem.yml
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
name: Publish a Rubygem
on:
workflow_call:
inputs:
gem_name:
required: false
type: string
default: ${{ github.event.repository.name }}
secrets:
GEM_HOST_API_KEY:
required: true
jobs:
publish:
name: Publish gem
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
show-progress: false
- uses: ruby/setup-ruby@v1
with:
rubygems: latest
bundler-cache: true
- name: "Determine HEAD of default branch"
id: fetch_default_branch_head
run: echo "sha=$(git ls-remote origin HEAD | cut -f 1)" >> "$GITHUB_OUTPUT"
- if: github.sha == steps.fetch_default_branch_head.outputs.sha
name: "Check if gem needs publishing"
env:
GEM_NAME: ${{ inputs.gem_name }}
GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }}
run: |
local_version=$(ruby -r rubygems -e "puts Gem::Specification::load('$GEM_NAME.gemspec').version")
remote_version=$(gem list --exact --remote "$GEM_NAME")
if [[ "$remote_version" != "$GEM_NAME (${local_version})" ]]; then
gem build "${GEM_NAME}.gemspec"
gem push "${GEM_NAME}-${local_version}.gem"
else
echo "::notice title=Gem version already published::Skipping gem publish because version (${local_version}) is already published"
fi
if ! git ls-remote --tags --exit-code origin "v${local_version}"; then
git tag "v${local_version}"
git push --tags
else
echo "::notice title=Tag already exists::Skipping git tagging because tag (v${local_version}) already exists"
fi
- if: github.sha != steps.fetch_default_branch_head.outputs.sha
name: "Skip publish: commit is not HEAD of default branch"
run: |
echo "Skipping publish because commit ($GITHUB_SHA) isn't the HEAD of the default branch ($DEFAULT_BRANCH_HEAD_SHA)" >> "$GITHUB_JOB_SUMMARY"