Repository navigation
84 lines (70 loc) · 2.14 KB
/
Copy pathrelease.yml
File metadata and controls
84 lines (70 loc) · 2.14 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
name: Publish to RubyGems
on:
push:
tags:
- "v*"
branches:
- main
workflow_dispatch:
inputs:
bump:
description: "Version bump type"
required: true
type: choice
options:
- patch
- minor
- major
jobs:
bump:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
- name: Bump version
id: bump
run: |
current=$(ruby -r ./lib/ipdata/version -e "puts IPData::VERSION")
IFS='.' read -r major minor patch <<< "$current"
case "${{ inputs.bump }}" in
major) major=$((major + 1)); minor=0; patch=0 ;;
minor) minor=$((minor + 1)); patch=0 ;;
patch) patch=$((patch + 1)) ;;
esac
new_version="${major}.${minor}.${patch}"
echo "version=${new_version}" >> "$GITHUB_OUTPUT"
sed -i "s/VERSION = \"${current}\"/VERSION = \"${new_version}\"/" lib/ipdata/version.rb
- name: Commit and tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add lib/ipdata/version.rb
git commit -m "Bump version to v${{ steps.bump.outputs.version }}"
git tag "v${{ steps.bump.outputs.version }}"
git push origin main --tags
release:
if: always() && (github.event_name == 'push' || needs.bump.result == 'success')
needs: [bump]
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_dispatch' && 'main' || github.ref }}
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true
- name: Run tests
run: bundle exec rake test
- name: Push to RubyGems
uses: rubygems/release-gem@v1