Skip to content

Commit c742e5c

Browse files
authored
Merge pull request #15 from niwo/copilot/add-github-actions-for-deployment
Add GitHub Actions CI + RubyGems release pipeline with pre-build version gate
2 parents 3bd7a46 + 5bcd662 commit c742e5c

File tree

4 files changed

+104
-1
lines changed

4 files changed

+104
-1
lines changed

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
ruby-version: ['3.2', '3.3']
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Ruby
23+
uses: ruby/setup-ruby@v1
24+
with:
25+
ruby-version: ${{ matrix.ruby-version }}
26+
bundler-cache: true
27+
28+
- name: Run tests
29+
run: bundle exec rake test
30+
31+
- name: Build gem
32+
run: bundle exec rake build

.github/workflows/release.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
verify:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
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+
bundler-cache: true
24+
25+
- name: Run tests
26+
run: bundle exec rake test
27+
28+
- name: Ensure version is bumped
29+
run: |
30+
CURRENT_VERSION="$(ruby -Ilib -e "require 'cloudstack_client/version'; puts CloudstackClient::VERSION")"
31+
LATEST_JSON="$(curl -fsSL https://rubygems.org/api/v1/versions/cloudstack_client/latest.json || true)"
32+
if [ -n "$LATEST_JSON" ]; then
33+
LATEST_VERSION="$(printf '%s' "$LATEST_JSON" | ruby -rjson -e "puts JSON.parse(STDIN.read)['version']")"
34+
ruby -e "require 'rubygems/version'; current = Gem::Version.new('$CURRENT_VERSION'); latest = Gem::Version.new('$LATEST_VERSION'); abort(\"Version must be bumped before building (current=#{current}, latest=#{latest})\") unless current > latest"
35+
fi
36+
37+
- name: Build gem
38+
run: bundle exec rake build
39+
40+
publish:
41+
runs-on: ubuntu-latest
42+
needs: verify
43+
environment: rubygems
44+
45+
steps:
46+
- name: Checkout repository
47+
uses: actions/checkout@v4
48+
49+
- name: Set up Ruby
50+
uses: ruby/setup-ruby@v1
51+
with:
52+
ruby-version: '3.2'
53+
bundler-cache: true
54+
55+
- name: Publish gem to RubyGems
56+
uses: rubygems/release-gem@v1
57+
with:
58+
api-key: ${{ secrets.RUBYGEMS_AUTH_TOKEN }}

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
cloudstack_client (1.5.11)
4+
cloudstack_client (1.5.12)
55

66
GEM
77
remote: https://rubygems.org/

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,19 @@ $ cloudstack_client list_apis > data/4.15.json
164164
$ gzip data/4.15.json
165165
```
166166

167+
### GitHub Actions
168+
169+
This repository includes GitHub Actions workflows for:
170+
171+
- Running tests and gem build on every push and pull request (`CI`)
172+
- Publishing the gem to RubyGems when a GitHub Release is published (`Release`)
173+
174+
To enable publishing, add this repository secret:
175+
176+
- `RUBYGEMS_AUTH_TOKEN`: your RubyGems API key with push permissions
177+
178+
The release workflow checks that `CloudstackClient::VERSION` is greater than the latest version on RubyGems before building, then uses the `rubygems` environment to publish.
179+
167180
## References
168181

169182
- [Apache CloudStack API documentation](http://cloudstack.apache.org/api/apidocs-4.15/)

0 commit comments

Comments
 (0)