Skip to content

Commit 71970c6

Browse files
committed
Update workflows
1 parent 852d210 commit 71970c6

File tree

2 files changed

+86
-3
lines changed

2 files changed

+86
-3
lines changed

.github/workflows/gem.yml

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
name: gem
22

33
on:
4-
release:
5-
types: [published]
4+
push:
5+
branches: main
6+
7+
workflow_dispatch:
8+
inputs:
9+
version_increment:
10+
description: 'Version to increment'
11+
required: true
12+
default: 'patch'
13+
options:
14+
- major
15+
- minor
16+
- patch
617

718
jobs:
819
build:
920
name: Build and publish
21+
22+
permissions:
23+
contents: write
24+
id-token: write
25+
packages: write
26+
pages: write
27+
1028
runs-on: ubuntu-latest
1129

1230
steps:
@@ -21,6 +39,69 @@ jobs:
2139
bundle install
2240
gem build *.gemspec
2341
42+
- name: Update version
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
run: |
46+
version_increment="${{ github.event.inputs.version_increment }}"
47+
version_increment="${version_increment:-patch}"
48+
49+
if [[ "$version_increment" == "patch" ]]; then
50+
commit_message=$(git log -1 --pretty=%B)
51+
if [[ "$commit_message" =~ Version-increment:\ (major|minor|patch) ]]; then
52+
version_increment="${BASH_REMATCH[1]}"
53+
fi
54+
fi
55+
56+
version=$(grep -E "Version = \[([0-9]+), ([0-9]+), ([0-9]+)\]" *.gemspec)
57+
major=$(echo "$version" | grep -Eo '\[[0-9]+' | tr -d '[')
58+
minor=$(echo "$version" | grep -Eo ', [0-9]+,' | tr -d ', ')
59+
patch=$(echo "$version" | grep -Eo ', [0-9]+\]' | tr -d ', ]')
60+
61+
case $version_increment in
62+
major)
63+
new_major=$((major + 1))
64+
new_minor=0
65+
new_patch=0
66+
;;
67+
minor)
68+
new_major=$((major))
69+
new_minor=$((minor + 1))
70+
new_patch=0
71+
;;
72+
patch)
73+
new_major=$((major))
74+
new_minor=$((minor))
75+
new_patch=$((patch + 1))
76+
;;
77+
esac
78+
79+
new_version="Version = [$new_major, $new_minor, $new_patch]"
80+
sed -i "s/^Version = \[.*\]/${new_version}/" *.gemspec
81+
82+
echo "version=$major.$minor.$patch" >> $GITHUB_ENV
83+
echo "new_version=$new_major.$new_minor.$new_patch" >> $GITHUB_ENV
84+
85+
git config --global user.email "rcvalle@users.noreply.github.com"
86+
git config --global user.name "Ramon de C Valle"
87+
git add *.gemspec
88+
git commit -m "Update version to $new_major.$new_minor.$new_patch"
89+
git push origin main
90+
91+
- name: Create new release
92+
env:
93+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94+
run: |
95+
changelog=$(mktemp)
96+
if [[ "${{ env.version }}" != "0.0.0" ]]; then
97+
git fetch --all -t
98+
git log "v${{ env.version }}"..HEAD --pretty='format:* %s' > "$changelog"
99+
else
100+
git log --pretty='format:* %s' > "$changelog"
101+
fi
102+
gh release create "v${{ env.new_version }}" -F "$changelog" -t "v${{ env.new_version }}"
103+
rm "$changelog"
104+
24105
- name: Publish to GitHub Packages
25106
env:
26107
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"

jekyll-theme-bootstrap4.gemspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
Version = [0, 0, 11]
2+
13
Gem::Specification.new do |spec|
24
spec.authors = ['Ramon de C Valle']
35
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
46
`git ls-files -z`.split("\0").reject { |f| f.match(%r{(\A(?:\.|Gemfile|_drafts)|(?:\.gemspec)\Z)}) }
57
end
68
spec.name = 'jekyll-theme-bootstrap4'
79
spec.summary = 'A Bootstrap-based Jekyll theme.'
8-
spec.version = '0.0.11'
10+
spec.version = Version.join('.')
911

1012
spec.description = ''
1113
spec.email = 'rcvalle@users.noreply.github.com'

0 commit comments

Comments
 (0)