Skip to content

Commit

Permalink
Update workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
rcvalle committed Nov 14, 2024
1 parent 852d210 commit 71970c6
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 3 deletions.
85 changes: 83 additions & 2 deletions .github/workflows/gem.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
name: gem

on:
release:
types: [published]
push:
branches: main

workflow_dispatch:
inputs:
version_increment:
description: 'Version to increment'
required: true
default: 'patch'
options:
- major
- minor
- patch

jobs:
build:
name: Build and publish

permissions:
contents: write
id-token: write
packages: write
pages: write

runs-on: ubuntu-latest

steps:
Expand All @@ -21,6 +39,69 @@ jobs:
bundle install
gem build *.gemspec
- name: Update version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
version_increment="${{ github.event.inputs.version_increment }}"
version_increment="${version_increment:-patch}"
if [[ "$version_increment" == "patch" ]]; then
commit_message=$(git log -1 --pretty=%B)
if [[ "$commit_message" =~ Version-increment:\ (major|minor|patch) ]]; then
version_increment="${BASH_REMATCH[1]}"
fi
fi
version=$(grep -E "Version = \[([0-9]+), ([0-9]+), ([0-9]+)\]" *.gemspec)
major=$(echo "$version" | grep -Eo '\[[0-9]+' | tr -d '[')
minor=$(echo "$version" | grep -Eo ', [0-9]+,' | tr -d ', ')
patch=$(echo "$version" | grep -Eo ', [0-9]+\]' | tr -d ', ]')
case $version_increment in
major)
new_major=$((major + 1))
new_minor=0
new_patch=0
;;
minor)
new_major=$((major))
new_minor=$((minor + 1))
new_patch=0
;;
patch)
new_major=$((major))
new_minor=$((minor))
new_patch=$((patch + 1))
;;
esac
new_version="Version = [$new_major, $new_minor, $new_patch]"
sed -i "s/^Version = \[.*\]/${new_version}/" *.gemspec
echo "version=$major.$minor.$patch" >> $GITHUB_ENV
echo "new_version=$new_major.$new_minor.$new_patch" >> $GITHUB_ENV
git config --global user.email "rcvalle@users.noreply.github.com"
git config --global user.name "Ramon de C Valle"
git add *.gemspec
git commit -m "Update version to $new_major.$new_minor.$new_patch"
git push origin main
- name: Create new release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
changelog=$(mktemp)
if [[ "${{ env.version }}" != "0.0.0" ]]; then
git fetch --all -t
git log "v${{ env.version }}"..HEAD --pretty='format:* %s' > "$changelog"
else
git log --pretty='format:* %s' > "$changelog"
fi
gh release create "v${{ env.new_version }}" -F "$changelog" -t "v${{ env.new_version }}"
rm "$changelog"
- name: Publish to GitHub Packages
env:
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
Expand Down
4 changes: 3 additions & 1 deletion jekyll-theme-bootstrap4.gemspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
Version = [0, 0, 11]

Gem::Specification.new do |spec|
spec.authors = ['Ramon de C Valle']
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z`.split("\0").reject { |f| f.match(%r{(\A(?:\.|Gemfile|_drafts)|(?:\.gemspec)\Z)}) }
end
spec.name = 'jekyll-theme-bootstrap4'
spec.summary = 'A Bootstrap-based Jekyll theme.'
spec.version = '0.0.11'
spec.version = Version.join('.')

spec.description = ''
spec.email = 'rcvalle@users.noreply.github.com'
Expand Down

0 comments on commit 71970c6

Please sign in to comment.