Skip to content

Commit 68389e8

Browse files
committed
feat: publish action
1 parent d9a8dbc commit 68389e8

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

.github/workflows/publish.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Publish Gem
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
publish:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Ruby
20+
uses: ruby/setup-ruby@v1
21+
with:
22+
ruby-version: '3.2'
23+
24+
- name: Determine versions and decide if publish is needed
25+
id: versions
26+
shell: bash
27+
run: |
28+
set -euo pipefail
29+
30+
# Read gem name from gemspec
31+
gem_name=$(ruby -e "require 'rubygems'; spec = Gem::Specification.load('sdk-ruby.gemspec'); puts spec.name")
32+
33+
# Read local version from the version file
34+
local_version=$(ruby -e "require_relative 'lib/lingodotdev/version'; puts LingoDotDev::VERSION")
35+
36+
# Fetch latest published version from RubyGems (empty if not published yet)
37+
remote_json=$(curl -sS "https://rubygems.org/api/v1/gems/$gem_name.json" || true)
38+
remote_version=$(ruby -rjson -e 'puts JSON.parse(STDIN.read)["version"] rescue ""' <<< "$remote_json")
39+
40+
echo "gem_name=$gem_name" >> "$GITHUB_OUTPUT"
41+
echo "local_version=$local_version" >> "$GITHUB_OUTPUT"
42+
echo "remote_version=$remote_version" >> "$GITHUB_OUTPUT"
43+
44+
if [[ "$local_version" == "$remote_version" ]]; then
45+
echo "should_publish=false" >> "$GITHUB_OUTPUT"
46+
echo "Version $local_version already on RubyGems. Skipping publish."
47+
else
48+
echo "should_publish=true" >> "$GITHUB_OUTPUT"
49+
echo "Will publish $gem_name $local_version to RubyGems."
50+
fi
51+
52+
- name: Build gem
53+
if: steps.versions.outputs.should_publish == 'true'
54+
run: |
55+
gem build sdk-ruby.gemspec
56+
57+
- name: Publish to RubyGems
58+
if: steps.versions.outputs.should_publish == 'true'
59+
env:
60+
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
61+
run: |
62+
gem push "${{ steps.versions.outputs.gem_name }}-${{ steps.versions.outputs.local_version }}.gem"
63+

0 commit comments

Comments
 (0)