-
Notifications
You must be signed in to change notification settings - Fork 1
130 lines (111 loc) · 3.86 KB
/
release.yml
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: gem
on:
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:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Ruby
uses: ruby/setup-ruby@v1
- name: Build
run: |
bundle install
gem build *.gemspec
rm *.gem
- 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 | grep -Eo '\[[0-9]+, [0-9]+, [0-9]+\]' | tr -d '[]')
major=$(echo "$version" | cut -d, -f1 | tr -d ' ')
minor=$(echo "$version" | cut -d, -f2 | tr -d ' ')
patch=$(echo "$version" | cut -d, -f3 | 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="${new_major}, ${new_minor}, ${new_patch}"
sed -i -E "s/(Version = \[)[0-9]+, [0-9]+, [0-9]+/\1${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 "[email protected]"
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: Build
run: |
bundle install
gem build *.gemspec
- name: Publish to GitHub Packages
env:
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
OWNER: ${{ github.repository_owner }}
run: |
mkdir -p ~/.gem/
touch ~/.gem/credentials
chmod 0600 ~/.gem/credentials
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > ~/.gem/credentials
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
- name: Publish to RubyGems
env:
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
run: |
mkdir -p ~/.gem/
touch ~/.gem/credentials
chmod 0600 ~/.gem/credentials
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > ~/.gem/credentials
gem push *.gem